diff --git a/test/e2e_node/pod_conditions_test.go b/test/e2e_node/pod_conditions_test.go index d4039fc4073..02410c074cf 100644 --- a/test/e2e_node/pod_conditions_test.go +++ b/test/e2e_node/pod_conditions_test.go @@ -57,6 +57,7 @@ var _ = SIGDescribe("Pod conditions managed by Kubelet", func() { ginkgo.It("a pod with init containers should report all conditions set in expected order after the pod is up", runPodReadyConditionsTest(f, true, true)) ginkgo.It("a pod failing to mount volumes and without init containers should report scheduled and initialized conditions set", runPodFailingConditionsTest(f, false, true)) ginkgo.It("a pod failing to mount volumes and with init containers should report just the scheduled condition set", runPodFailingConditionsTest(f, true, true)) + cleanupPods(f) }) ginkgo.Context("without PodReadyToStartContainersCondition condition", func() { @@ -64,6 +65,7 @@ var _ = SIGDescribe("Pod conditions managed by Kubelet", func() { ginkgo.It("a pod with init containers should report all conditions set in expected order after the pod is up", runPodReadyConditionsTest(f, true, false)) ginkgo.It("a pod failing to mount volumes and without init containers should report scheduled and initialized conditions set", runPodFailingConditionsTest(f, false, false)) ginkgo.It("a pod failing to mount volumes and with init containers should report just the scheduled condition set", runPodFailingConditionsTest(f, true, false)) + cleanupPods(f) }) }) diff --git a/test/e2e_node/util.go b/test/e2e_node/util.go index 3137edc726c..02315bff3db 100644 --- a/test/e2e_node/util.go +++ b/test/e2e_node/util.go @@ -170,6 +170,21 @@ func getCurrentKubeletConfig(ctx context.Context) (*kubeletconfig.KubeletConfigu return e2enodekubelet.GetCurrentKubeletConfig(ctx, framework.TestContext.NodeName, "", false, framework.TestContext.StandaloneMode) } +func cleanupPods(f *framework.Framework) { + ginkgo.AfterEach(func(ctx context.Context) { + ginkgo.By("Deleting any Pods created by the test in namespace: " + f.Namespace.Name) + l, err := e2epod.NewPodClient(f).List(ctx, metav1.ListOptions{}) + framework.ExpectNoError(err) + for _, p := range l.Items { + if p.Namespace != f.Namespace.Name { + continue + } + framework.Logf("Deleting pod: %s", p.Name) + e2epod.NewPodClient(f).DeleteSync(ctx, p.Name, metav1.DeleteOptions{}, 2*time.Minute) + } + }) +} + // Must be called within a Context. Allows the function to modify the KubeletConfiguration during the BeforeEach of the context. // The change is reverted in the AfterEach of the context. // Returns true on success.