From 53220717eb252f7f6b3336166810b8dab9565119 Mon Sep 17 00:00:00 2001 From: Tony Duan Date: Fri, 5 May 2023 15:14:36 +0800 Subject: [PATCH 1/2] fix: initContainer restart policy overridden by pod Restart policy of initContainers should not be overriden by pod and the restart policy should always be "no". See #16343 Signed-off-by: Tony Duan --- pkg/specgen/generate/container_create.go | 2 +- pkg/specgen/specgen.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/specgen/generate/container_create.go b/pkg/specgen/generate/container_create.go index 266c4c5883..3b0b6c5f6c 100644 --- a/pkg/specgen/generate/container_create.go +++ b/pkg/specgen/generate/container_create.go @@ -560,7 +560,7 @@ func createContainerOptions(rt *libpod.Runtime, s *specgen.SpecGenerator, pod *l retries uint ) // If the container is running in a pod, use the pod's restart policy for all the containers - if pod != nil { + if pod != nil && !s.IsInitContainer() { podConfig := pod.ConfigNoCopy() if podConfig.RestartRetries != nil { retries = *podConfig.RestartRetries diff --git a/pkg/specgen/specgen.go b/pkg/specgen/specgen.go index ff91489dbf..52ddf3d396 100644 --- a/pkg/specgen/specgen.go +++ b/pkg/specgen/specgen.go @@ -586,6 +586,10 @@ func (s *SpecGenerator) GetImage() (*libimage.Image, string) { return s.image, s.resolvedImageName } +func (s *SpecGenerator) IsInitContainer() bool { + return len(s.InitContainerType) != 0 +} + type Secret struct { Source string Target string From 74a5b92b3a51f8bcf8e989cfd34f1991799358e0 Mon Sep 17 00:00:00 2001 From: Tony Duan Date: Fri, 5 May 2023 16:36:16 +0000 Subject: [PATCH 2/2] test: check restart policy of init containers make the sure restart policy is "no" for init containers created by `podman kube play` Signed-off-by: Tony Duan --- test/e2e/play_kube_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go index 2d82899ee9..9bf51ee3d6 100644 --- a/test/e2e/play_kube_test.go +++ b/test/e2e/play_kube_test.go @@ -2234,6 +2234,12 @@ var _ = Describe("Podman play kube", func() { Expect(inspect).Should(Exit(0)) Expect(inspect.OutputToString()).To(ContainSubstring("running")) + // Init containers should not be restarted + inspect = podmanTest.Podman([]string{"inspect", "--format", "{{ .HostConfig.RestartPolicy.Name }}", "testPod-" + defaultCtrName}) + inspect.WaitWithDefaultTimeout() + Expect(inspect).Should(Exit(0)) + Expect(inspect.OutputToString()).To(ContainSubstring(define.RestartPolicyNo)) + // Init containers need environment too! #18384 logs := podmanTest.Podman([]string{"logs", "testPod-init-test"}) logs.WaitWithDefaultTimeout()