From 4b1b9a198a6deeeece2e9f1fc107e39b1beda6e8 Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Mon, 13 Nov 2023 20:00:33 +0000 Subject: [PATCH 1/3] Fix issue with client rate limiter when polling Signed-off-by: James Sturtevant --- test/e2e/framework/autoscaling/autoscaling_utils.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/test/e2e/framework/autoscaling/autoscaling_utils.go b/test/e2e/framework/autoscaling/autoscaling_utils.go index 30b06e88e29..bd64006963a 100644 --- a/test/e2e/framework/autoscaling/autoscaling_utils.go +++ b/test/e2e/framework/autoscaling/autoscaling_utils.go @@ -50,6 +50,7 @@ import ( utilpointer "k8s.io/utils/pointer" "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" imageutils "k8s.io/kubernetes/test/utils/image" ) @@ -506,7 +507,7 @@ func (rc *ResourceConsumer) WaitForReplicas(ctx context.Context, desiredReplicas // EnsureDesiredReplicasInRange ensure the replicas is in a desired range func (rc *ResourceConsumer) EnsureDesiredReplicasInRange(ctx context.Context, minDesiredReplicas, maxDesiredReplicas int, duration time.Duration, hpaName string) { interval := 10 * time.Second - err := wait.PollUntilContextTimeout(ctx, interval, duration, true, func(ctx context.Context) (bool, error) { + gomega.Consistently(ctx, framework.HandleRetry(func(ctx context.Context) (bool, error) { replicas := rc.GetReplicas(ctx) framework.Logf("expecting there to be in [%d, %d] replicas (are: %d)", minDesiredReplicas, maxDesiredReplicas, replicas) as, err := rc.GetHpa(ctx, hpaName) @@ -520,15 +521,9 @@ func (rc *ResourceConsumer) EnsureDesiredReplicasInRange(ctx context.Context, mi } 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. + return true, 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) + })).WithTimeout(duration).WithPolling(interval).Should(gomega.BeTrue()) } // Pause stops background goroutines responsible for consuming resources. From 49e8c196c34c8d121618a00bcad97066d602fae6 Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Tue, 14 Nov 2023 19:35:04 +0000 Subject: [PATCH 2/3] use framework gomega Signed-off-by: James Sturtevant --- .../autoscaling/autoscaling_utils.go | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/test/e2e/framework/autoscaling/autoscaling_utils.go b/test/e2e/framework/autoscaling/autoscaling_utils.go index bd64006963a..d7953a6d7ee 100644 --- a/test/e2e/framework/autoscaling/autoscaling_utils.go +++ b/test/e2e/framework/autoscaling/autoscaling_utils.go @@ -507,23 +507,16 @@ func (rc *ResourceConsumer) WaitForReplicas(ctx context.Context, desiredReplicas // EnsureDesiredReplicasInRange ensure the replicas is in a desired range func (rc *ResourceConsumer) EnsureDesiredReplicasInRange(ctx context.Context, minDesiredReplicas, maxDesiredReplicas int, duration time.Duration, hpaName string) { interval := 10 * time.Second - gomega.Consistently(ctx, framework.HandleRetry(func(ctx context.Context) (bool, error) { - replicas := rc.GetReplicas(ctx) - framework.Logf("expecting there to be in [%d, %d] replicas (are: %d)", minDesiredReplicas, maxDesiredReplicas, replicas) - as, err := rc.GetHpa(ctx, hpaName) - if err != nil { - framework.Logf("Error getting HPA: %s", err) - } else { - framework.Logf("HPA status: %+v", as.Status) - } - if replicas < minDesiredReplicas { - return false, fmt.Errorf("number of replicas below target") - } else if replicas > maxDesiredReplicas { - return false, fmt.Errorf("number of replicas above target") - } else { - return true, nil // Expected number of replicas found. Continue polling until timeout. - } - })).WithTimeout(duration).WithPolling(interval).Should(gomega.BeTrue()) + framework.Gomega().Consistently(ctx, func(ctx context.Context) int { + return rc.GetReplicas(ctx) + }).WithTimeout(duration).WithPolling(interval).Should(gomega.And(gomega.BeNumerically(">=", minDesiredReplicas), gomega.BeNumerically("<=", maxDesiredReplicas))) + + as, err := rc.GetHpa(ctx, hpaName) + if err != nil { + framework.Logf("Error getting HPA: %s", err) + } else { + framework.Logf("HPA status: %+v", as.Status) + } } // Pause stops background goroutines responsible for consuming resources. From c99b5a208deecad40bf1f2d13ebdbada28124d22 Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Tue, 14 Nov 2023 21:29:56 +0000 Subject: [PATCH 3/3] Check error from gomega Signed-off-by: James Sturtevant --- test/e2e/framework/autoscaling/autoscaling_utils.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/e2e/framework/autoscaling/autoscaling_utils.go b/test/e2e/framework/autoscaling/autoscaling_utils.go index d7953a6d7ee..68f884b8272 100644 --- a/test/e2e/framework/autoscaling/autoscaling_utils.go +++ b/test/e2e/framework/autoscaling/autoscaling_utils.go @@ -507,16 +507,18 @@ func (rc *ResourceConsumer) WaitForReplicas(ctx context.Context, desiredReplicas // EnsureDesiredReplicasInRange ensure the replicas is in a desired range func (rc *ResourceConsumer) EnsureDesiredReplicasInRange(ctx context.Context, minDesiredReplicas, maxDesiredReplicas int, duration time.Duration, hpaName string) { interval := 10 * time.Second - framework.Gomega().Consistently(ctx, func(ctx context.Context) int { + desiredReplicasErr := framework.Gomega().Consistently(ctx, func(ctx context.Context) int { return rc.GetReplicas(ctx) }).WithTimeout(duration).WithPolling(interval).Should(gomega.And(gomega.BeNumerically(">=", minDesiredReplicas), gomega.BeNumerically("<=", maxDesiredReplicas))) + // dump HPA for debugging as, err := rc.GetHpa(ctx, hpaName) if err != nil { framework.Logf("Error getting HPA: %s", err) } else { framework.Logf("HPA status: %+v", as.Status) } + framework.ExpectNoError(desiredReplicasErr) } // Pause stops background goroutines responsible for consuming resources.