diff --git a/internal/ingress/status/status.go b/internal/ingress/status/status.go index ef01cdd248..150573dced 100644 --- a/internal/ingress/status/status.go +++ b/internal/ingress/status/status.go @@ -95,11 +95,16 @@ func (s *statusSync) Run(stopCh chan struct{}) { // when this instance is the leader we need to enqueue // an item to trigger the update of the Ingress status. - //nolint:staticcheck // TODO: will replace it since wait.PollUntil is deprecated - err := wait.PollUntil(time.Duration(UpdateInterval)*time.Second, func() (bool, error) { + ctx, cancel := context.WithCancel(context.Background()) + go func() { + <-stopCh + cancel() + }() + + err := wait.PollUntilContextCancel(ctx, time.Duration(UpdateInterval)*time.Second, true, func(context.Context) (bool, error) { s.syncQueue.EnqueueTask(task.GetDummyObject("sync status")) return false, nil - }, stopCh) + }) if err != nil { klog.ErrorS(err, "error running poll") } diff --git a/test/e2e/framework/k8s.go b/test/e2e/framework/k8s.go index 7c067421d9..4d413e4b47 100644 --- a/test/e2e/framework/k8s.go +++ b/test/e2e/framework/k8s.go @@ -144,8 +144,7 @@ func (f *Framework) EnsureDeployment(deployment *appsv1.Deployment) *appsv1.Depl // waitForPodsReady waits for a given amount of time until a group of Pods is running in the given namespace. func waitForPodsReady(kubeClientSet kubernetes.Interface, timeout time.Duration, expectedReplicas int, namespace string, opts *metav1.ListOptions) error { - //nolint:staticcheck // TODO: will replace it since wait.PollImmediate is deprecated - return wait.PollImmediate(1*time.Second, timeout, func() (bool, error) { + return wait.PollUntilContextTimeout(context.Background(), 1*time.Second, timeout, true, func(_ context.Context) (bool, error) { pl, err := kubeClientSet.CoreV1().Pods(namespace).List(context.TODO(), *opts) if err != nil { return false, nil @@ -172,8 +171,7 @@ func waitForPodsReady(kubeClientSet kubernetes.Interface, timeout time.Duration, // waitForPodsDeleted waits for a given amount of time until a group of Pods are deleted in the given namespace. func waitForPodsDeleted(kubeClientSet kubernetes.Interface, timeout time.Duration, namespace string, opts *metav1.ListOptions) error { - //nolint:staticcheck // TODO: will replace it since wait.Poll is deprecated - return wait.Poll(Poll, timeout, func() (bool, error) { + return wait.PollUntilContextTimeout(context.Background(), Poll, timeout, true, func(_ context.Context) (bool, error) { pl, err := kubeClientSet.CoreV1().Pods(namespace).List(context.TODO(), *opts) if err != nil { return false, nil @@ -192,8 +190,8 @@ func WaitForEndpoints(kubeClientSet kubernetes.Interface, timeout time.Duration, if expectedEndpoints == 0 { return nil } - //nolint:staticcheck // TODO: will replace it since wait.PollImmediate is deprecated - return wait.PollImmediate(Poll, timeout, func() (bool, error) { + + err := wait.PollUntilContextTimeout(context.Background(), Poll, timeout, true, func(_ context.Context) (bool, error) { endpoint, err := kubeClientSet.CoreV1().Endpoints(ns).Get(context.TODO(), name, metav1.GetOptions{}) if k8sErrors.IsNotFound(err) { return false, nil @@ -207,6 +205,8 @@ func WaitForEndpoints(kubeClientSet kubernetes.Interface, timeout time.Duration, return false, nil }) + + return err } func countReadyEndpoints(e *core.Endpoints) int { @@ -254,8 +254,9 @@ func isPodReady(p *core.Pod) bool { // getIngressNGINXPod returns the ingress controller running pod func getIngressNGINXPod(ns string, kubeClientSet kubernetes.Interface) (*core.Pod, error) { var pod *core.Pod - //nolint:staticcheck // TODO: will replace it since wait.Poll is deprecated - err := wait.Poll(1*time.Second, DefaultTimeout, func() (bool, error) { + ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout) + defer cancel() + err := wait.PollUntilContextTimeout(ctx, 1*time.Second, DefaultTimeout, true, func(_ context.Context) (bool, error) { l, err := kubeClientSet.CoreV1().Pods(ns).List(context.TODO(), metav1.ListOptions{ LabelSelector: "app.kubernetes.io/name=ingress-nginx", }) @@ -281,8 +282,7 @@ func getIngressNGINXPod(ns string, kubeClientSet kubernetes.Interface) (*core.Po return false, nil }) if err != nil { - //nolint:staticcheck // TODO: will replace it since wait.ErrWaitTimeout is deprecated - if err == wait.ErrWaitTimeout { + if ctx.Err() == context.DeadlineExceeded { return nil, fmt.Errorf("timeout waiting at least one ingress-nginx pod running in namespace %v", ns) } diff --git a/test/e2e/status/update.go b/test/e2e/status/update.go index c3c48f8d2a..47ddb1832a 100644 --- a/test/e2e/status/update.go +++ b/test/e2e/status/update.go @@ -108,8 +108,7 @@ var _ = framework.IngressNginxDescribe("[Status] status update", func() { } }() - //nolint:staticcheck // TODO: will replace it since wait.Poll is deprecated - err = wait.Poll(5*time.Second, 4*time.Minute, func() (done bool, err error) { + err = wait.PollUntilContextTimeout(context.Background(), 5*time.Second, 4*time.Minute, true, func(_ context.Context) (done bool, err error) { ing, err = f.KubeClientSet.NetworkingV1().Ingresses(f.Namespace).Get(context.TODO(), host, metav1.GetOptions{}) if err != nil { return false, nil diff --git a/test/e2e/tcpudp/tcp.go b/test/e2e/tcpudp/tcp.go index 856184d18b..fc84523a87 100644 --- a/test/e2e/tcpudp/tcp.go +++ b/test/e2e/tcpudp/tcp.go @@ -157,8 +157,7 @@ var _ = framework.IngressNginxDescribe("[TCP] tcp-services", func() { return false, nil }) - //nolint:staticcheck // TODO: will replace it since wait.ErrWaitTimeout is deprecated - if err == wait.ErrWaitTimeout { + if err != nil && errRetry != nil { err = errRetry }