@@ -50,6 +50,7 @@ import (
50
50
utilpointer "k8s.io/utils/pointer"
51
51
52
52
"github.com/onsi/ginkgo/v2"
53
+ "github.com/onsi/gomega"
53
54
54
55
imageutils "k8s.io/kubernetes/test/utils/image"
55
56
)
@@ -506,29 +507,18 @@ func (rc *ResourceConsumer) WaitForReplicas(ctx context.Context, desiredReplicas
506
507
// EnsureDesiredReplicasInRange ensure the replicas is in a desired range
507
508
func (rc * ResourceConsumer ) EnsureDesiredReplicasInRange (ctx context.Context , minDesiredReplicas , maxDesiredReplicas int , duration time.Duration , hpaName string ) {
508
509
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 )
530
520
}
531
- framework .ExpectNoErrorWithOffset ( 1 , err )
521
+ framework .ExpectNoError ( desiredReplicasErr )
532
522
}
533
523
534
524
// Pause stops background goroutines responsible for consuming resources.
0 commit comments