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

Run generate.CompleteSpec() for initContainers as well #18385

Merged
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
12 changes: 11 additions & 1 deletion pkg/domain/infra/abi/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,16 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY
if err != nil {
return nil, nil, err
}

// ensure the environment is setup for initContainers as well: https://github.com/containers/podman/issues/18384
warn, err := generate.CompleteSpec(ctx, ic.Libpod, specGen)
if err != nil {
return nil, nil, err
}
for _, w := range warn {
logrus.Warn(w)
}

specGen.SdNotifyMode = define.SdNotifyModeIgnore
rtSpec, spec, opts, err := generate.MakeContainer(ctx, ic.Libpod, specGen, false, nil)
if err != nil {
Expand Down Expand Up @@ -792,7 +802,7 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY
return nil, nil, err
}
for _, w := range warn {
fmt.Fprintf(os.Stderr, "%s\n", w)
logrus.Warn(w)
}

specGen.RawImageName = container.Image
Expand Down
8 changes: 7 additions & 1 deletion test/e2e/play_kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2210,7 +2210,7 @@ var _ = Describe("Podman play kube", func() {
// With annotation set to always
It("podman play kube test with init containers and annotation set", func() {
// With the init container type annotation set to always
pod := getPod(withAnnotation("io.podman.annotations.init.container.type", "always"), withPodInitCtr(getCtr(withImage(ALPINE), withCmd([]string{"echo", "hello"}), withInitCtr(), withName("init-test"))), withCtr(getCtr(withImage(ALPINE), withCmd([]string{"top"}))))
pod := getPod(withAnnotation("io.podman.annotations.init.container.type", "always"), withPodInitCtr(getCtr(withImage(ALPINE), withCmd([]string{"printenv", "container"}), withInitCtr(), withName("init-test"))), withCtr(getCtr(withImage(ALPINE), withCmd([]string{"top"}))))
err := generateKubeYaml("pod", pod, kubeYaml)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -2233,6 +2233,12 @@ var _ = Describe("Podman play kube", func() {
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(Exit(0))
Expect(inspect.OutputToString()).To(ContainSubstring("running"))

// Init containers need environment too! #18384
logs := podmanTest.Podman([]string{"logs", "testPod-init-test"})
logs.WaitWithDefaultTimeout()
Expect(logs).Should(Exit(0))
Expect(logs.OutputToString()).To(Equal("podman"))
})

// If you have an init container in the pod yaml, podman should create and run the init container with play kube
Expand Down