File tree Expand file tree Collapse file tree 2 files changed +5
-13
lines changed 
internal/controller/provisioner Expand file tree Collapse file tree 2 files changed +5
-13
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
469469func  TestBuildNginxResourceObjects_Plus (t  * testing.T ) {
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments