Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: initContainer restart policy overridden by pod #18481

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/specgen/generate/container_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pkg/specgen/specgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/play_kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down