Skip to content

Commit

Permalink
sidecar-20372 - Inspecting the start order of restartable init container
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Deng <ywdeng@tw.ibm.com>
  • Loading branch information
vincentywdeng committed Dec 13, 2023
1 parent f827d95 commit ec63837
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions test/e2e/play_kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,18 +585,24 @@ spec:
{{ if .RestartPolicy }}
restartPolicy: {{ .RestartPolicy }}
{{ if .StartupProbe }}
startupProbe:
exec:
startupProbe:
exec:
command:
{{ range .StartupProbe.Cmd }}
- {{.}}
{{ end }}
{{ if .StartupProbe.TimeoutSeconds }}
timeoutSeconds: {{ .StartupProbe.TimeoutSeconds }}
timeoutSeconds: {{ .StartupProbe.TimeoutSeconds }}
{{ end }}
{{ end }}
{{ end }}
{{ if .VolumeMount }}
volumeMounts:
- name: {{.VolumeName}}
mountPath: {{ .VolumeMountPath }}
readonly: {{.VolumeReadOnly}}
{{ end }}
{{ end }}
{{ end }}
{{ if .SecurityContext }}
Expand Down Expand Up @@ -2588,9 +2594,15 @@ var _ = Describe("Podman kube play", func() {
Expect(inspect.OutputToString()).To(ContainSubstring("running"))
})

It("test with always restart init container startup probe continue Pod creation after init container started", func() {
startupProbe := getHealthCheckProbe(WithHealthCheckCommand([]string{"sleep", "'1'"}), WithHeathCheckTimeout(3))
pod := getPod(withPodInitCtr(getCtr(withImage(CITEST_IMAGE), withCmd([]string{"top"}), withRestartableInitCtr(), withName("sidecar-container"), withStartupProbe(startupProbe))), withCtr(getCtr(withImage(CITEST_IMAGE), withCmd([]string{"top"}))))
// For a Pod with [initContainer1, restartableInitContainer, initContainer2, regularContainer], the containers shouldbe started in sequence. And regular container started after
// start probe of restartableInitContainer finished
It("init container started in sequence", func() {
startupProbe := getHealthCheckProbe(WithHealthCheckCommand([]string{"sh", "-c", "echo 'sidecar'>>/test/startUpSequence"}), WithHeathCheckTimeout(3))
initContainer1 := withPodInitCtr(getCtr(withImage(CITEST_IMAGE), withCmd([]string{"sh", "-c", "echo 'init-test1'>>/test/startUpSequence"}), withInitCtr(), withName("init-test1"), withVolumeMount("/test", "", false)))
restartableInitConatiner := withPodInitCtr(getCtr(withImage(CITEST_IMAGE), withCmd([]string{"top"}), withRestartableInitCtr(), withName("sidecar-container"), withStartupProbe(startupProbe), withVolumeMount("/test", "", false)))
initContainer2 := withPodInitCtr(getCtr(withImage(CITEST_IMAGE), withCmd([]string{"sh", "-c", "echo 'init-test2'>>/test/startUpSequence"}), withInitCtr(), withName("init-test2"), withVolumeMount("/test", "", false)))

pod := getPod(initContainer1, restartableInitConatiner, initContainer2, withCtr(getCtr(withImage(CITEST_IMAGE), withCmd([]string{"top"}), withVolumeMount("/test", "", false))), withVolume(getEmptyDirVolume()))
err := generateKubeYaml("pod", pod, kubeYaml)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -2609,10 +2621,27 @@ var _ = Describe("Podman kube play", func() {
Expect(inspect.OutputToString()).To(ContainSubstring("running"))

// Regular container should be in running state
inspect = podmanTest.Podman([]string{"inspect", "--format", "{{.State.Status}}", "testPod-" + defaultCtrName})
inspect = podmanTest.Podman([]string{"inspect", "--format", "{{.State.Status}}", getCtrNameInPod(pod)})
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(ExitCleanly())
Expect(inspect.OutputToString()).To(ContainSubstring("running"))

// Init container started in correct sequence
inspect = podmanTest.Podman([]string{"exec", getCtrNameInPod(pod), "cat", "/test/startUpSequence"})
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(ExitCleanly())
Expect(inspect.OutputToString()).To(Equal("init-test1 sidecar init-test2"))

// Regular container started after restartable init container
inspect = podmanTest.Podman([]string{"inspect", "--format", "{{.State.StartedAt}}", "testPod-" + "sidecar-container"})
inspect.WaitWithDefaultTimeout()
startOfRestartableInitContainer, err := time.Parse("2006-01-02 15:04:05.999999999 -0700 MST", inspect.OutputToString())
Expect(err).ToNot(HaveOccurred())
inspect = podmanTest.Podman([]string{"inspect", "--format", "{{.State.StartedAt}}", getCtrNameInPod(pod)})
inspect.WaitWithDefaultTimeout()
startOfRegularContainer, err := time.Parse("2006-01-02 15:04:05.999999999 -0700 MST", inspect.OutputToString())
Expect(err).ToNot(HaveOccurred())
Expect(startOfRestartableInitContainer).To(BeTemporally("<", startOfRegularContainer))
})

// If you supply only args for a Container, the default Entrypoint defined in the Docker image is run with the args that you supplied.
Expand Down

0 comments on commit ec63837

Please sign in to comment.