Skip to content

Commit 1e19f96

Browse files
committed
Remove HPA change
1 parent f9db288 commit 1e19f96

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

internal/controller/provisioner/objects.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -691,9 +691,6 @@ func (p *NginxProvisioner) buildNginxDeployment(
691691
replicas = deploymentCfg.Replicas
692692
}
693693

694-
// When HPA is enabled, we should not set the replicas field to allow HPA exclusive control.
695-
// Setting replicas causes a race condition where NGF and HPA fight over the replica count.
696-
// See: https://github.com/nginx/nginx-gateway-fabric/issues/4007
697694
if isAutoscalingEnabled(&deploymentCfg) {
698695
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
699696
defer cancel()
@@ -703,14 +700,9 @@ func (p *NginxProvisioner) buildNginxDeployment(
703700
Namespace: objectMeta.Namespace,
704701
Name: objectMeta.Name,
705702
}, hpa)
706-
if err == nil {
707-
// HPA exists - do not set replicas field, let HPA manage it
708-
replicas = nil
709-
} else if replicas == nil && deploymentCfg.Autoscaling.MinReplicas != nil {
710-
// HPA doesn't exist yet - set initial replicas
711-
// This handles the initial deployment before HPA takes over
712-
// Use minReplicas as the initial value
713-
replicas = deploymentCfg.Autoscaling.MinReplicas
703+
if err == nil && hpa.Status.DesiredReplicas > 0 {
704+
// overwrite with HPA's desiredReplicas
705+
replicas = helpers.GetPointer(hpa.Status.DesiredReplicas)
714706
}
715707
}
716708

internal/controller/provisioner/objects_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ func TestBuildNginxResourceObjects_DeploymentReplicasFromHPA(t *testing.T) {
462462
}
463463
}
464464
g.Expect(deployment).ToNot(BeNil())
465-
g.Expect(deployment.Spec.Replicas).To(BeNil(),
466-
"Deployment replicas should be nil when HPA exists to allow HPA exclusive control")
465+
g.Expect(deployment.Spec.Replicas).ToNot(BeNil())
466+
g.Expect(*deployment.Spec.Replicas).To(Equal(int32(7)))
467467
}
468468

469469
func TestBuildNginxResourceObjects_Plus(t *testing.T) {

0 commit comments

Comments
 (0)