gke-autoneg-controller: capacityScaler can't be set to zero for global load balancer
Issue:
- When capacityScaler is set to
0Google sets it to 100% instead - When capacityScaler is set to between
0and100everything works as expected
How to recreate
Set up Kubernetes service in two regions:
- region1:
apiVersion: v1
kind: Service
metadata:
annotations:
cloud.google.com/neg: '{"exposed_ports": {"80":{"name": "region1-sampleapp"}}}'
controller.autoneg.dev/neg: '{"backend_services":{"80":[{"name":"sampleapp-backend-global","max_rate_per_endpoint":10,"initial_capacity":10}]}}'
name: sampleapp-external
namespace: sampleapp
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 8080
selector:
app.kubernetes.io/instance: sample
- region2:
apiVersion: v1
kind: Service
metadata:
annotations:
cloud.google.com/neg: '{"exposed_ports": {"80":{"name": "region2-sampleapp"}}}'
controller.autoneg.dev/neg: '{"backend_services":{"80":[{"name":"sampleapp-backend-global","max_rate_per_endpoint":10,"initial_capacity":0}]}}'
name: sampleapp-external
namespace: sampleapp
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 8080
selector:
app.kubernetes.io/instance: sample
- log:
2023-11-15T13:59:04-06:00 INFO Applying intended status {"controller": "service", "controllerGroup": "", "controllerKind": "Service", "Service": {"name":"sampleapp-external","namespace":"sampleapp"}, "namespace": "sampleapp", "name": "sampleapp-external", "reconcileID": "c087632a-7860", "service": {"name":"sampleapp-external","namespace":"sampleapp"}, "status": {"backend_services":{"80":{"sampleapp-backend-global":{"name":"sampleapp-backend-global","max_rate_per_endpoint":10,"initial_capacity":0}}},"network_endpoint_groups":{"80":"gcp-central1-hermes1-lab-sampleapp-sampleapp-external"},"zones":["region2-b","region2-c","region2-f"]}}
2023-11-15T13:59:25-06:00 DEBUG events Synced NEGs for "sampleapp/sampleapp-external" as backends to backend service "sampleapp-backend-global" (port 80) {"type": "Normal", "object": {"kind":"Service","namespace":"sampleapp","name":"sampleapp-external","uid":"e80e34435-123213","apiVersion":"v1","resourceVersion":"123453"}, "reason": "Sync"}
- result:
gcloud compute backend-services list --flatten="backends[]" --format "csv(name,backends.group,backends.balancingMode,backends.capacityScaler)" | grep sampleapp
sampleapp-backend-global,https://www.googleapis.com/compute/v1/projects/projectname/zones/region1-b/networkEndpointGroups/region1-sampleapp,RATE,0.1
sampleapp-backend-global,https://www.googleapis.com/compute/v1/projects/projectname/zones/region1-c/networkEndpointGroups/region1-sampleapp,RATE,0.1
sampleapp-backend-global,https://www.googleapis.com/compute/v1/projects/projectname/zones/region1-d/networkEndpointGroups/region1-sampleapp,RATE,0.1
sampleapp-backend-global,https://www.googleapis.com/compute/v1/projects/projectname/zones/region2-b/networkEndpointGroups/region2-sampleapp,RATE,1
sampleapp-backend-global,https://www.googleapis.com/compute/v1/projects/projectname/zones/region2-c/networkEndpointGroups/region2-sampleapp,RATE,1
sampleapp-backend-global,https://www.googleapis.com/compute/v1/projects/projectname/zones/region2-f/networkEndpointGroups/region2-sampleapp,RATE,1
Additional information
- I can set capacityScaler to zero in google console with no issue
- I ran code through debugger and I can see
0incapacityScalerbefore it makes a call, so for some reason GCE decides it is not set and takes default instead - I tried to add
NullFields = []string{"CapacityScaler"}andForceSendFields = []string{"CapacityScaler"}to backend update API call, but it did not help
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 23
Since Google SDKs use pure
int32instead of pointers, they cannot really express 0. Zero is unset for them. One needs to put the specific fieldForceSendFieldsto send an actual zero. (some other SDKs use helper functions to make ptr values, but it is almost just as annoying)There’s an issue currently with initial capacity and stuff - since the issue has not been picked up, I hope to find some time to look at it.