From 7e880d1babb0c77d45644572b00efbf5e1ac3a1f Mon Sep 17 00:00:00 2001 From: Swati Sehgal Date: Mon, 24 Oct 2022 16:21:28 +0100 Subject: [PATCH] node: e2e: ensure log rotation pod is deleted after test Some node e2e tests check for expected number of pods running on the node to verify the correct state of that node after running test scenarios. An example of such a check is in the device plugin end to end test here: [1]. If the node is not left in a clean state after an e2e test finishes running, it can lead to flaky tests because the node might have unexpected pods running on the node. In order to avoid that, we make sure that the test pods are cleaned up after the test runs. [1]: https://github.com/kubernetes/kubernetes/blob/master/test/e2e_node/device_plugin_test.go#L189-L190 Signed-off-by: Swati Sehgal --- test/e2e_node/container_log_rotation_test.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/test/e2e_node/container_log_rotation_test.go b/test/e2e_node/container_log_rotation_test.go index 56796fd469b..6a6a2708446 100644 --- a/test/e2e_node/container_log_rotation_test.go +++ b/test/e2e_node/container_log_rotation_test.go @@ -50,7 +50,8 @@ var _ = SIGDescribe("ContainerLogRotation [Slow] [Serial] [Disruptive]", func() initialConfig.ContainerLogMaxSize = testContainerLogMaxSize }) - ginkgo.It("should be rotated and limited to a fixed amount of files", func(ctx context.Context) { + var logRotationPod *v1.Pod + ginkgo.BeforeEach(func() { ginkgo.By("create log container") pod := &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ @@ -72,10 +73,20 @@ var _ = SIGDescribe("ContainerLogRotation [Slow] [Serial] [Disruptive]", func() }, }, } - pod = e2epod.NewPodClient(f).CreateSync(pod) + logRotationPod = e2epod.NewPodClient(f).CreateSync(pod) + }) + + ginkgo.AfterEach(func() { + ginkgo.By("Deleting the log-rotation pod") + framework.Logf("Deleting pod: %s", logRotationPod.Name) + e2epod.NewPodClient(f).DeleteSync(logRotationPod.Name, metav1.DeleteOptions{}, time.Minute) + }) + + ginkgo.It("should be rotated and limited to a fixed amount of files", func(ctx context.Context) { + ginkgo.By("get container log path") - framework.ExpectEqual(len(pod.Status.ContainerStatuses), 1) - id := kubecontainer.ParseContainerID(pod.Status.ContainerStatuses[0].ContainerID).ID + framework.ExpectEqual(len(logRotationPod.Status.ContainerStatuses), 1) + id := kubecontainer.ParseContainerID(logRotationPod.Status.ContainerStatuses[0].ContainerID).ID r, _, err := getCRIClient() framework.ExpectNoError(err) resp, err := r.ContainerStatus(context.Background(), id, false)