Merge pull request #121861 from jsturtevant/update-waiting-logic-hpa
Fix issue with client rate limiter when polling
This commit is contained in:
		@@ -50,6 +50,7 @@ import (
 | 
				
			|||||||
	utilpointer "k8s.io/utils/pointer"
 | 
						utilpointer "k8s.io/utils/pointer"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/onsi/ginkgo/v2"
 | 
						"github.com/onsi/ginkgo/v2"
 | 
				
			||||||
 | 
						"github.com/onsi/gomega"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	imageutils "k8s.io/kubernetes/test/utils/image"
 | 
						imageutils "k8s.io/kubernetes/test/utils/image"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -506,29 +507,18 @@ func (rc *ResourceConsumer) WaitForReplicas(ctx context.Context, desiredReplicas
 | 
				
			|||||||
// EnsureDesiredReplicasInRange ensure the replicas is in a desired range
 | 
					// EnsureDesiredReplicasInRange ensure the replicas is in a desired range
 | 
				
			||||||
func (rc *ResourceConsumer) EnsureDesiredReplicasInRange(ctx context.Context, minDesiredReplicas, maxDesiredReplicas int, duration time.Duration, hpaName string) {
 | 
					func (rc *ResourceConsumer) EnsureDesiredReplicasInRange(ctx context.Context, minDesiredReplicas, maxDesiredReplicas int, duration time.Duration, hpaName string) {
 | 
				
			||||||
	interval := 10 * time.Second
 | 
						interval := 10 * time.Second
 | 
				
			||||||
	err := wait.PollUntilContextTimeout(ctx, interval, duration, true, func(ctx context.Context) (bool, error) {
 | 
						desiredReplicasErr := framework.Gomega().Consistently(ctx, func(ctx context.Context) int {
 | 
				
			||||||
		replicas := rc.GetReplicas(ctx)
 | 
							return rc.GetReplicas(ctx)
 | 
				
			||||||
		framework.Logf("expecting there to be in [%d, %d] replicas (are: %d)", minDesiredReplicas, maxDesiredReplicas, replicas)
 | 
						}).WithTimeout(duration).WithPolling(interval).Should(gomega.And(gomega.BeNumerically(">=", minDesiredReplicas), gomega.BeNumerically("<=", maxDesiredReplicas)))
 | 
				
			||||||
		as, err := rc.GetHpa(ctx, hpaName)
 | 
					
 | 
				
			||||||
		if err != nil {
 | 
						// dump HPA for debugging
 | 
				
			||||||
			framework.Logf("Error getting HPA: %s", err)
 | 
						as, err := rc.GetHpa(ctx, hpaName)
 | 
				
			||||||
		} else {
 | 
						if err != nil {
 | 
				
			||||||
			framework.Logf("HPA status: %+v", as.Status)
 | 
							framework.Logf("Error getting HPA: %s", err)
 | 
				
			||||||
		}
 | 
						} else {
 | 
				
			||||||
		if replicas < minDesiredReplicas {
 | 
							framework.Logf("HPA status: %+v", as.Status)
 | 
				
			||||||
			return false, fmt.Errorf("number of replicas below target")
 | 
					 | 
				
			||||||
		} else if replicas > maxDesiredReplicas {
 | 
					 | 
				
			||||||
			return false, fmt.Errorf("number of replicas above target")
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			return false, nil // Expected number of replicas found. Continue polling until timeout.
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
	// The call above always returns an error, but if it is timeout, it's OK (condition satisfied all the time).
 | 
					 | 
				
			||||||
	if wait.Interrupted(err) {
 | 
					 | 
				
			||||||
		framework.Logf("Number of replicas was stable over %v", duration)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	framework.ExpectNoErrorWithOffset(1, err)
 | 
						framework.ExpectNoError(desiredReplicasErr)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Pause stops background goroutines responsible for consuming resources.
 | 
					// Pause stops background goroutines responsible for consuming resources.
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user