Skip to content

Commit bd00f83

Browse files
committed
Add step to existing pod termination Node E2E tests to check the container’s exit code
Signed-off-by: Tsubasa Nagasawa <[email protected]>
1 parent cc67c4c commit bd00f83

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

test/e2e_node/container_lifecycle_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,28 @@ func prefixedName(namePrefix string, name string) string {
5050
return fmt.Sprintf("%s-%s", namePrefix, name)
5151
}
5252

53+
type podTerminationContainerStatus struct {
54+
exitCode int32
55+
reason string
56+
}
57+
58+
func expectPodTerminationContainerStatuses(statuses []v1.ContainerStatus, to map[string]podTerminationContainerStatus) {
59+
ginkgo.GinkgoHelper()
60+
61+
if len(statuses) != len(to) {
62+
ginkgo.Fail(fmt.Sprintf("mismatched lengths in pod termination container statuses. got %d, expected %d", len(statuses), len(to)))
63+
}
64+
for _, status := range statuses {
65+
expected, ok := to[status.Name]
66+
if !ok {
67+
ginkgo.Fail(fmt.Sprintf("container %q not found in expected pod termination container statuses", status.Name))
68+
}
69+
gomega.Expect(status.State.Terminated).NotTo(gomega.BeNil())
70+
gomega.Expect(status.State.Terminated.ExitCode).To(gomega.Equal(expected.exitCode))
71+
gomega.Expect(status.State.Terminated.Reason).To(gomega.Equal(expected.reason))
72+
}
73+
}
74+
5375
var _ = SIGDescribe(framework.WithNodeConformance(), "Containers Lifecycle", func() {
5476
f := framework.NewDefaultFramework("containers-lifecycle-test")
5577
addAfterEachForCleaningUpPods(f)
@@ -3115,6 +3137,12 @@ var _ = SIGDescribe(nodefeature.SidecarContainers, "Containers Lifecycle", func(
31153137
pod, err = client.Get(context.TODO(), pod.Name, metav1.GetOptions{})
31163138
framework.ExpectNoError(err)
31173139

3140+
expectPodTerminationContainerStatuses(pod.Status.InitContainerStatuses, map[string]podTerminationContainerStatus{
3141+
restartableInit1: {exitCode: int32(0), reason: "Completed"},
3142+
restartableInit2: {exitCode: int32(0), reason: "Completed"},
3143+
restartableInit3: {exitCode: int32(0), reason: "Completed"},
3144+
})
3145+
31183146
results := parseOutput(context.TODO(), f, pod)
31193147

31203148
ginkgo.By("Analyzing results")
@@ -3221,6 +3249,13 @@ var _ = SIGDescribe(nodefeature.SidecarContainers, "Containers Lifecycle", func(
32213249
pod, err = client.Get(context.TODO(), pod.Name, metav1.GetOptions{})
32223250
framework.ExpectNoError(err)
32233251

3252+
// all restartable init containers are sigkilled with exit code 137
3253+
expectPodTerminationContainerStatuses(pod.Status.InitContainerStatuses, map[string]podTerminationContainerStatus{
3254+
restartableInit1: {exitCode: int32(137), reason: "Error"},
3255+
restartableInit2: {exitCode: int32(137), reason: "Error"},
3256+
restartableInit3: {exitCode: int32(137), reason: "Error"},
3257+
})
3258+
32243259
results := parseOutput(context.TODO(), f, pod)
32253260

32263261
ginkgo.By("Analyzing results")
@@ -3352,6 +3387,12 @@ var _ = SIGDescribe(nodefeature.SidecarContainers, "Containers Lifecycle", func(
33523387
pod, err = client.Get(context.TODO(), pod.Name, metav1.GetOptions{})
33533388
framework.ExpectNoError(err)
33543389

3390+
expectPodTerminationContainerStatuses(pod.Status.InitContainerStatuses, map[string]podTerminationContainerStatus{
3391+
restartableInit1: {exitCode: int32(0), reason: "Completed"},
3392+
restartableInit2: {exitCode: int32(0), reason: "Completed"},
3393+
restartableInit3: {exitCode: int32(0), reason: "Completed"},
3394+
})
3395+
33553396
results := parseOutput(context.TODO(), f, pod)
33563397

33573398
ginkgo.By("Analyzing results")

0 commit comments

Comments
 (0)