Skip to content

Commit bbf4d44

Browse files
authored
Merge pull request #8735 from adrianmoisey/tweak-test
Refactor recommender e2e test
2 parents f7f44c3 + 1a26a9e commit bbf4d44

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

vertical-pod-autoscaler/e2e/v1/recommender.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"k8s.io/apimachinery/pkg/api/resource"
3030
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3131
"k8s.io/apimachinery/pkg/fields"
32+
"k8s.io/apimachinery/pkg/util/wait"
3233
utilfeature "k8s.io/apiserver/pkg/util/feature"
3334
"k8s.io/autoscaler/vertical-pod-autoscaler/e2e/utils"
3435
vpa_types "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1"
@@ -151,22 +152,23 @@ var _ = utils.RecommenderE2eDescribe("Checkpoints", func() {
151152
_, err := vpaClientSet.AutoscalingV1().VerticalPodAutoscalerCheckpoints(ns).Create(context.TODO(), &checkpoint, metav1.CreateOptions{})
152153
gomega.Expect(err).NotTo(gomega.HaveOccurred())
153154

154-
klog.InfoS("Sleeping for up to 15 minutes...")
155+
klog.InfoS("Polling for up to 15 minutes...")
155156

156-
maxRetries := 90
157-
retryDelay := 10 * time.Second
158-
for i := 0; i < maxRetries; i++ {
159-
list, err := vpaClientSet.AutoscalingV1().VerticalPodAutoscalerCheckpoints(ns).List(context.TODO(), metav1.ListOptions{})
160-
if err == nil && len(list.Items) == 0 {
161-
break
157+
var list *vpa_types.VerticalPodAutoscalerCheckpointList
158+
err = wait.PollUntilContextTimeout(context.TODO(), 10*time.Second, 15*time.Minute, false, func(ctx context.Context) (done bool, err error) {
159+
list, err = vpaClientSet.AutoscalingV1().VerticalPodAutoscalerCheckpoints(ns).List(ctx, metav1.ListOptions{})
160+
if err != nil {
161+
klog.ErrorS(err, "Error listing VPA checkpoints")
162+
return false, err
162163
}
163-
klog.InfoS("Still waiting...")
164-
time.Sleep(retryDelay)
165-
}
164+
if len(list.Items) > 0 {
165+
return false, nil
166+
}
167+
klog.InfoS("No VPA checkpoints found")
168+
return true, nil
166169

167-
list, err := vpaClientSet.AutoscalingV1().VerticalPodAutoscalerCheckpoints(ns).List(context.TODO(), metav1.ListOptions{})
170+
})
168171
gomega.Expect(err).NotTo(gomega.HaveOccurred())
169-
gomega.Expect(list.Items).To(gomega.BeEmpty())
170172
})
171173
})
172174

0 commit comments

Comments
 (0)