Skip to content

Commit 8254569

Browse files
authored
Merge pull request kubernetes#121861 from jsturtevant/update-waiting-logic-hpa
Fix issue with client rate limiter when polling
2 parents a00ea0d + c99b5a2 commit 8254569

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

test/e2e/framework/autoscaling/autoscaling_utils.go

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import (
5050
utilpointer "k8s.io/utils/pointer"
5151

5252
"github.com/onsi/ginkgo/v2"
53+
"github.com/onsi/gomega"
5354

5455
imageutils "k8s.io/kubernetes/test/utils/image"
5556
)
@@ -506,29 +507,18 @@ func (rc *ResourceConsumer) WaitForReplicas(ctx context.Context, desiredReplicas
506507
// EnsureDesiredReplicasInRange ensure the replicas is in a desired range
507508
func (rc *ResourceConsumer) EnsureDesiredReplicasInRange(ctx context.Context, minDesiredReplicas, maxDesiredReplicas int, duration time.Duration, hpaName string) {
508509
interval := 10 * time.Second
509-
err := wait.PollUntilContextTimeout(ctx, interval, duration, true, func(ctx context.Context) (bool, error) {
510-
replicas := rc.GetReplicas(ctx)
511-
framework.Logf("expecting there to be in [%d, %d] replicas (are: %d)", minDesiredReplicas, maxDesiredReplicas, replicas)
512-
as, err := rc.GetHpa(ctx, hpaName)
513-
if err != nil {
514-
framework.Logf("Error getting HPA: %s", err)
515-
} else {
516-
framework.Logf("HPA status: %+v", as.Status)
517-
}
518-
if replicas < minDesiredReplicas {
519-
return false, fmt.Errorf("number of replicas below target")
520-
} else if replicas > maxDesiredReplicas {
521-
return false, fmt.Errorf("number of replicas above target")
522-
} else {
523-
return false, nil // Expected number of replicas found. Continue polling until timeout.
524-
}
525-
})
526-
// The call above always returns an error, but if it is timeout, it's OK (condition satisfied all the time).
527-
if wait.Interrupted(err) {
528-
framework.Logf("Number of replicas was stable over %v", duration)
529-
return
510+
desiredReplicasErr := framework.Gomega().Consistently(ctx, func(ctx context.Context) int {
511+
return rc.GetReplicas(ctx)
512+
}).WithTimeout(duration).WithPolling(interval).Should(gomega.And(gomega.BeNumerically(">=", minDesiredReplicas), gomega.BeNumerically("<=", maxDesiredReplicas)))
513+
514+
// dump HPA for debugging
515+
as, err := rc.GetHpa(ctx, hpaName)
516+
if err != nil {
517+
framework.Logf("Error getting HPA: %s", err)
518+
} else {
519+
framework.Logf("HPA status: %+v", as.Status)
530520
}
531-
framework.ExpectNoErrorWithOffset(1, err)
521+
framework.ExpectNoError(desiredReplicasErr)
532522
}
533523

534524
// Pause stops background goroutines responsible for consuming resources.

0 commit comments

Comments
 (0)