Skip to content

Chores: Migrate deprecated wait.Poll* to context-aware equivalents. #13766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions internal/ingress/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
20 changes: 10 additions & 10 deletions test/e2e/framework/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -207,6 +205,8 @@ func WaitForEndpoints(kubeClientSet kubernetes.Interface, timeout time.Duration,

return false, nil
})

return err
}

func countReadyEndpoints(e *core.Endpoints) int {
Expand Down Expand Up @@ -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",
})
Expand All @@ -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)
}

Expand Down
3 changes: 1 addition & 2 deletions test/e2e/status/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/tcpudp/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down