From 02b6b6520ad1452267aa0b0017dc5a600580309a Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Sun, 18 Dec 2022 13:35:18 +0100 Subject: [PATCH 1/2] e2e kubectl: increase wait timeout After adding error checking in df5d84ae811b, the "[sig-cli] Kubectl client Simple pod should return command exit codes [Slow] running a failing command without --restart=Never, but with --rm" test was found to time out. Doubling the timeout might help. Alternatively, the entire WaitForPodToDisappear could get removed, which would make this scenario similar to the others which also don't wait. --- test/e2e/kubectl/kubectl.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/kubectl/kubectl.go b/test/e2e/kubectl/kubectl.go index 3006df523c2..631cca961cf 100644 --- a/test/e2e/kubectl/kubectl.go +++ b/test/e2e/kubectl/kubectl.go @@ -579,7 +579,7 @@ var _ = SIGDescribe("Kubectl client", func() { if !strings.Contains(ee.String(), "timed out") { framework.Failf("Missing expected 'timed out' error, got: %#v", ee) } - framework.ExpectNoError(e2epod.WaitForPodToDisappear(ctx, f.ClientSet, ns, "failure-3", labels.Everything(), 2*time.Second, wait.ForeverTestTimeout)) + framework.ExpectNoError(e2epod.WaitForPodToDisappear(ctx, f.ClientSet, ns, "failure-3", labels.Everything(), 2*time.Second, 2*v1.DefaultTerminationGracePeriodSeconds*time.Second)) }) ginkgo.It("[Slow] running a failing command with --leave-stdin-open", func(ctx context.Context) { From 2296fc4b1f82cf6c36484127b2e1a28da701d123 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Sun, 18 Dec 2022 14:01:56 +0100 Subject: [PATCH 2/2] e2e apps: fix "context canceled" error Using the ctx of the ginkgo.BeforeEach in callbacks that are invoked after the BeforeEach is done causes "context canceled" errors. Previously, this code used context.TODO(). The best solution is to create a new context and cancel it during test cleanup, then that context can be used for the API calls and as stop channel. --- test/e2e/apps/daemon_restart.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/test/e2e/apps/daemon_restart.go b/test/e2e/apps/daemon_restart.go index c9845b143d1..ab8d9e34f7d 100644 --- a/test/e2e/apps/daemon_restart.go +++ b/test/e2e/apps/daemon_restart.go @@ -216,7 +216,6 @@ var _ = SIGDescribe("DaemonRestart [Disruptive]", func() { var config testutils.RCConfig var controller cache.Controller var newPods cache.Store - var stopCh chan struct{} var tracker *podTracker ginkgo.BeforeEach(func(ctx context.Context) { @@ -237,18 +236,21 @@ var _ = SIGDescribe("DaemonRestart [Disruptive]", func() { framework.ExpectNoError(e2erc.RunRC(ctx, config)) replacePods(*config.CreatedPods, existingPods) - stopCh = make(chan struct{}) + // The following code continues to run after the BeforeEach and thus + // must not use ctx. + backgroundCtx, cancel := context.WithCancel(context.Background()) + ginkgo.DeferCleanup(cancel) tracker = newPodTracker() newPods, controller = cache.NewInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { options.LabelSelector = labelSelector.String() - obj, err := f.ClientSet.CoreV1().Pods(ns).List(ctx, options) + obj, err := f.ClientSet.CoreV1().Pods(ns).List(backgroundCtx, options) return runtime.Object(obj), err }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { options.LabelSelector = labelSelector.String() - return f.ClientSet.CoreV1().Pods(ns).Watch(ctx, options) + return f.ClientSet.CoreV1().Pods(ns).Watch(backgroundCtx, options) }, }, &v1.Pod{}, @@ -265,11 +267,7 @@ var _ = SIGDescribe("DaemonRestart [Disruptive]", func() { }, }, ) - go controller.Run(stopCh) - }) - - ginkgo.AfterEach(func() { - close(stopCh) + go controller.Run(backgroundCtx.Done()) }) ginkgo.It("Controller Manager should not create/delete replicas across restart", func(ctx context.Context) {