Skip to content

Commit 1affd73

Browse files
committed
Code Review for status.desiredReplicas
1 parent ca0383c commit 1affd73

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

charts/nginx-gateway-fabric/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ The following table lists the configurable parameters of the NGINX Gateway Fabri
278278
| `nginx.kind` | The kind of NGINX deployment. | string | `"deployment"` |
279279
| `nginx.plus` | Is NGINX Plus image being used. | bool | `false` |
280280
| `nginx.pod` | The pod configuration for the NGINX data plane pod. This is applied globally to all Gateways managed by this instance of NGINX Gateway Fabric. | object | `{}` |
281-
| `nginx.replicas` | The number of replicas of the NGINX Deployment. | int | `1` |
281+
| `nginx.replicas` | The number of replicas of the NGINX Deployment. This value is ignored if autoscaling.enabled is true. | int | `1` |
282282
| `nginx.service` | The service configuration for the NGINX data plane. This is applied globally to all Gateways managed by this instance of NGINX Gateway Fabric. | object | `{"externalTrafficPolicy":"Local","loadBalancerClass":"","loadBalancerIP":"","loadBalancerSourceRanges":[],"nodePorts":[],"type":"LoadBalancer"}` |
283283
| `nginx.service.externalTrafficPolicy` | The externalTrafficPolicy of the service. The value Local preserves the client source IP. | string | `"Local"` |
284284
| `nginx.service.loadBalancerClass` | LoadBalancerClass is the class of the load balancer implementation this Service belongs to. Requires nginx.service.type set to LoadBalancer. | string | `""` |
@@ -319,7 +319,7 @@ The following table lists the configurable parameters of the NGINX Gateway Fabri
319319
| `nginxGateway.readinessProbe.enable` | Enable the /readyz endpoint on the control plane. | bool | `true` |
320320
| `nginxGateway.readinessProbe.initialDelaySeconds` | The number of seconds after the Pod has started before the readiness probes are initiated. | int | `3` |
321321
| `nginxGateway.readinessProbe.port` | Port in which the readiness endpoint is exposed. | int | `8081` |
322-
| `nginxGateway.replicas` | The number of replicas of the NGINX Gateway Fabric Deployment. | int | `1` |
322+
| `nginxGateway.replicas` | The number of replicas of the NGINX Gateway Fabric Deployment. This value is ignored if autoscaling.enabled is true. | int | `1` |
323323
| `nginxGateway.resources` | The resource requests and/or limits of the nginx-gateway container. | object | `{}` |
324324
| `nginxGateway.service` | The service configuration for the NGINX Gateway Fabric control plane. | object | `{"annotations":{},"labels":{}}` |
325325
| `nginxGateway.service.annotations` | The annotations of the NGINX Gateway Fabric control plane service. | object | `{}` |

charts/nginx-gateway-fabric/values.schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@
478478
},
479479
"replicas": {
480480
"default": 1,
481-
"description": "The number of replicas of the NGINX Deployment.",
481+
"description": "The number of replicas of the NGINX Deployment. This value is ignored if autoscaling.enabled is true.",
482482
"required": [],
483483
"title": "replicas",
484484
"type": "integer"
@@ -897,7 +897,7 @@
897897
},
898898
"replicas": {
899899
"default": 1,
900-
"description": "The number of replicas of the NGINX Gateway Fabric Deployment.",
900+
"description": "The number of replicas of the NGINX Gateway Fabric Deployment. This value is ignored if autoscaling.enabled is true.",
901901
"required": [],
902902
"title": "replicas",
903903
"type": "integer"

charts/nginx-gateway-fabric/values.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ nginxGateway:
8080
# Secrets must exist in the same namespace as the helm release.
8181
imagePullSecrets: []
8282

83-
# -- The number of replicas of the NGINX Gateway Fabric Deployment.
83+
# -- The number of replicas of the NGINX Gateway Fabric Deployment. This value is ignored if autoscaling.enabled is true.
8484
replicas: 1
8585

8686
# The configuration for leader election.
@@ -226,7 +226,7 @@ nginx:
226226
# -- The kind of NGINX deployment.
227227
kind: deployment
228228

229-
# -- The number of replicas of the NGINX Deployment.
229+
# -- The number of replicas of the NGINX Deployment. This value is ignored if autoscaling.enabled is true.
230230
replicas: 1
231231

232232
autoscaling:

internal/controller/provisioner/objects.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,24 @@ func (p *NginxProvisioner) buildNginxDeployment(
615615
}
616616

617617
if deploymentCfg.Replicas != nil {
618-
deployment.Spec.Replicas = deploymentCfg.Replicas
618+
replicas := deploymentCfg.Replicas
619+
620+
if isAutoscalingEnabled(&deploymentCfg) {
621+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
622+
defer cancel()
623+
624+
hpa := &autoscalingv2.HorizontalPodAutoscaler{}
625+
err := p.k8sClient.Get(ctx, types.NamespacedName{
626+
Namespace: objectMeta.Namespace,
627+
Name: objectMeta.Name,
628+
}, hpa)
629+
if err == nil && hpa.Status.DesiredReplicas > 0 {
630+
// overwrite with HPA's desiredReplicas
631+
replicas = helpers.GetPointer(hpa.Status.DesiredReplicas)
632+
}
633+
}
634+
635+
deployment.Spec.Replicas = replicas
619636
}
620637

621638
return deployment, nil

0 commit comments

Comments
 (0)