From 57eb99dbb8756ad9b0fa86b2fd79b902028f255b Mon Sep 17 00:00:00 2001 From: Tim Allclair Date: Thu, 19 Mar 2026 03:19:07 +0000 Subject: [PATCH] test: fix flaky static pod tests by asserting on termination message and container ID instead of StartTime The expectation that StartTime changes on kubelet restart for static pods is no longer reliable due to faked init container status logic. This change updates the tests to assert on the specific behavior introduced by that logic. --- test/e2e_node/static_pod_test.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/test/e2e_node/static_pod_test.go b/test/e2e_node/static_pod_test.go index 7a6e62438ba..b1f2443c4ae 100644 --- a/test/e2e_node/static_pod_test.go +++ b/test/e2e_node/static_pod_test.go @@ -75,7 +75,6 @@ var _ = SIGDescribe("StaticPod", framework.WithSerial(), func() { }) var initCtrID string - var startTime *metav1.Time mirrorPodName := fmt.Sprintf("%s-%s", staticPod.Name, framework.TestContext.NodeName) ginkgo.By("wait for the mirror pod to be updated") gomega.Eventually(ctx, func(g gomega.Gomega) { @@ -85,9 +84,10 @@ var _ = SIGDescribe("StaticPod", framework.WithSerial(), func() { cstatus := pod.Status.InitContainerStatuses[0] // Wait until the init container is terminated. g.Expect(cstatus.State.Terminated).NotTo(gomega.BeNil()) + g.Expect(cstatus.State.Terminated.Reason).To(gomega.Equal("Completed")) + g.Expect(cstatus.State.Terminated.ExitCode).To(gomega.BeZero()) g.Expect(cstatus.State.Terminated.ContainerID).NotTo(gomega.BeEmpty()) initCtrID = cstatus.ContainerID - startTime = pod.Status.StartTime }, 2*time.Minute, 5*time.Second).Should(gomega.Succeed()) ginkgo.By("remove init container") @@ -103,7 +103,6 @@ var _ = SIGDescribe("StaticPod", framework.WithSerial(), func() { ginkgo.By("wait for the mirror pod to be updated") gomega.Eventually(ctx, func(g gomega.Gomega) { pod, err := f.ClientSet.CoreV1().Pods(staticPod.Namespace).Get(ctx, mirrorPodName, metav1.GetOptions{}) - g.Expect(pod.Status.StartTime.Equal(startTime)).To(gomega.BeFalseBecause("startTime should not be equal")) g.Expect(err).Should(gomega.Succeed()) g.Expect(pod.Status.InitContainerStatuses).To(gomega.HaveLen(1)) cstatus := pod.Status.InitContainerStatuses[0] @@ -111,6 +110,7 @@ var _ = SIGDescribe("StaticPod", framework.WithSerial(), func() { g.Expect(cstatus.State.Terminated).NotTo(gomega.BeNil()) g.Expect(cstatus.State.Terminated.Reason).To(gomega.Equal("Completed")) g.Expect(cstatus.State.Terminated.ExitCode).To(gomega.BeZero()) + g.Expect(cstatus.State.Terminated.Message).To(gomega.ContainSubstring("Unable to get init container status")) }, 2*time.Minute, 5*time.Second).Should(gomega.Succeed()) }) }) @@ -151,7 +151,6 @@ var _ = SIGDescribe("StaticPod", framework.WithSerial(), func() { }) var sidecarCtrID string - var startTime *metav1.Time mirrorPodName := fmt.Sprintf("%s-%s", staticPod.Name, framework.TestContext.NodeName) ginkgo.By("wait for the mirror pod to be updated") gomega.Eventually(ctx, func(g gomega.Gomega) { @@ -162,7 +161,6 @@ var _ = SIGDescribe("StaticPod", framework.WithSerial(), func() { // Wait until the sidecar container starts running. g.Expect(cstatus.State.Running).NotTo(gomega.BeNil()) sidecarCtrID = cstatus.ContainerID - startTime = pod.Status.StartTime }, 2*time.Minute, 5*time.Second).Should(gomega.Succeed()) // Stop kubelet first not to restart the sidecar container. @@ -181,12 +179,12 @@ var _ = SIGDescribe("StaticPod", framework.WithSerial(), func() { ginkgo.By("wait for the mirror pod to be updated") gomega.Eventually(ctx, func(g gomega.Gomega) { pod, err := f.ClientSet.CoreV1().Pods(staticPod.Namespace).Get(ctx, mirrorPodName, metav1.GetOptions{}) - g.Expect(pod.Status.StartTime.Equal(startTime)).To(gomega.BeFalseBecause("startTime should not be equal")) g.Expect(err).Should(gomega.Succeed()) g.Expect(pod.Status.InitContainerStatuses).To(gomega.HaveLen(1)) cstatus := pod.Status.InitContainerStatuses[0] // Sidecar container should be restarted and running. g.Expect(cstatus.State.Running).NotTo(gomega.BeNil()) + g.Expect(cstatus.ContainerID).NotTo(gomega.Equal(sidecarCtrID)) }, 2*time.Minute, 5*time.Second).Should(gomega.Succeed()) }) })