Skip to content

Commit b70f25e

Browse files
Chores: Migrate deprecated wait.Poll* to context-aware equivalents. (#13781)
Co-authored-by: Michael <[email protected]>
1 parent 9554781 commit b70f25e

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

internal/ingress/status/status.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,16 @@ func (s *statusSync) Run(stopCh chan struct{}) {
9595

9696
// when this instance is the leader we need to enqueue
9797
// an item to trigger the update of the Ingress status.
98-
//nolint:staticcheck // TODO: will replace it since wait.PollUntil is deprecated
99-
err := wait.PollUntil(time.Duration(UpdateInterval)*time.Second, func() (bool, error) {
98+
ctx, cancel := context.WithCancel(context.Background())
99+
go func() {
100+
<-stopCh
101+
cancel()
102+
}()
103+
104+
err := wait.PollUntilContextCancel(ctx, time.Duration(UpdateInterval)*time.Second, true, func(context.Context) (bool, error) {
100105
s.syncQueue.EnqueueTask(task.GetDummyObject("sync status"))
101106
return false, nil
102-
}, stopCh)
107+
})
103108
if err != nil {
104109
klog.ErrorS(err, "error running poll")
105110
}

test/e2e/framework/k8s.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ func (f *Framework) EnsureDeployment(deployment *appsv1.Deployment) *appsv1.Depl
144144

145145
// waitForPodsReady waits for a given amount of time until a group of Pods is running in the given namespace.
146146
func waitForPodsReady(kubeClientSet kubernetes.Interface, timeout time.Duration, expectedReplicas int, namespace string, opts *metav1.ListOptions) error {
147-
//nolint:staticcheck // TODO: will replace it since wait.PollImmediate is deprecated
148-
return wait.PollImmediate(1*time.Second, timeout, func() (bool, error) {
147+
return wait.PollUntilContextTimeout(context.Background(), 1*time.Second, timeout, true, func(_ context.Context) (bool, error) {
149148
pl, err := kubeClientSet.CoreV1().Pods(namespace).List(context.TODO(), *opts)
150149
if err != nil {
151150
return false, nil
@@ -172,8 +171,7 @@ func waitForPodsReady(kubeClientSet kubernetes.Interface, timeout time.Duration,
172171

173172
// waitForPodsDeleted waits for a given amount of time until a group of Pods are deleted in the given namespace.
174173
func waitForPodsDeleted(kubeClientSet kubernetes.Interface, timeout time.Duration, namespace string, opts *metav1.ListOptions) error {
175-
//nolint:staticcheck // TODO: will replace it since wait.Poll is deprecated
176-
return wait.Poll(Poll, timeout, func() (bool, error) {
174+
return wait.PollUntilContextTimeout(context.Background(), Poll, timeout, true, func(_ context.Context) (bool, error) {
177175
pl, err := kubeClientSet.CoreV1().Pods(namespace).List(context.TODO(), *opts)
178176
if err != nil {
179177
return false, nil
@@ -192,8 +190,8 @@ func WaitForEndpoints(kubeClientSet kubernetes.Interface, timeout time.Duration,
192190
if expectedEndpoints == 0 {
193191
return nil
194192
}
195-
//nolint:staticcheck // TODO: will replace it since wait.PollImmediate is deprecated
196-
return wait.PollImmediate(Poll, timeout, func() (bool, error) {
193+
194+
err := wait.PollUntilContextTimeout(context.Background(), Poll, timeout, true, func(_ context.Context) (bool, error) {
197195
endpoint, err := kubeClientSet.CoreV1().Endpoints(ns).Get(context.TODO(), name, metav1.GetOptions{})
198196
if k8sErrors.IsNotFound(err) {
199197
return false, nil
@@ -207,6 +205,8 @@ func WaitForEndpoints(kubeClientSet kubernetes.Interface, timeout time.Duration,
207205

208206
return false, nil
209207
})
208+
209+
return err
210210
}
211211

212212
func countReadyEndpoints(e *core.Endpoints) int {
@@ -254,8 +254,9 @@ func isPodReady(p *core.Pod) bool {
254254
// getIngressNGINXPod returns the ingress controller running pod
255255
func getIngressNGINXPod(ns string, kubeClientSet kubernetes.Interface) (*core.Pod, error) {
256256
var pod *core.Pod
257-
//nolint:staticcheck // TODO: will replace it since wait.Poll is deprecated
258-
err := wait.Poll(1*time.Second, DefaultTimeout, func() (bool, error) {
257+
ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout)
258+
defer cancel()
259+
err := wait.PollUntilContextTimeout(ctx, 1*time.Second, DefaultTimeout, true, func(_ context.Context) (bool, error) {
259260
l, err := kubeClientSet.CoreV1().Pods(ns).List(context.TODO(), metav1.ListOptions{
260261
LabelSelector: "app.kubernetes.io/name=ingress-nginx",
261262
})
@@ -281,8 +282,7 @@ func getIngressNGINXPod(ns string, kubeClientSet kubernetes.Interface) (*core.Po
281282
return false, nil
282283
})
283284
if err != nil {
284-
//nolint:staticcheck // TODO: will replace it since wait.ErrWaitTimeout is deprecated
285-
if err == wait.ErrWaitTimeout {
285+
if ctx.Err() == context.DeadlineExceeded {
286286
return nil, fmt.Errorf("timeout waiting at least one ingress-nginx pod running in namespace %v", ns)
287287
}
288288

test/e2e/status/update.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ var _ = framework.IngressNginxDescribe("[Status] status update", func() {
108108
}
109109
}()
110110

111-
//nolint:staticcheck // TODO: will replace it since wait.Poll is deprecated
112-
err = wait.Poll(5*time.Second, 4*time.Minute, func() (done bool, err error) {
111+
err = wait.PollUntilContextTimeout(context.Background(), 5*time.Second, 4*time.Minute, true, func(_ context.Context) (done bool, err error) {
113112
ing, err = f.KubeClientSet.NetworkingV1().Ingresses(f.Namespace).Get(context.TODO(), host, metav1.GetOptions{})
114113
if err != nil {
115114
return false, nil

test/e2e/tcpudp/tcp.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ var _ = framework.IngressNginxDescribe("[TCP] tcp-services", func() {
157157

158158
return false, nil
159159
})
160-
//nolint:staticcheck // TODO: will replace it since wait.ErrWaitTimeout is deprecated
161-
if err == wait.ErrWaitTimeout {
160+
if err != nil && errRetry != nil {
162161
err = errRetry
163162
}
164163

0 commit comments

Comments
 (0)