@@ -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