Skip to content

Commit

Permalink
Merge pull request #12757 from umohnani8/cm
Browse files Browse the repository at this point in the history
Don't add env if optional and not found
  • Loading branch information
openshift-merge-robot authored Jan 10, 2022
2 parents a957e8c + 4dc5a5b commit 8af574f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion pkg/specgen/generate/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,10 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener
return nil, err
}

envs[env.Name] = value
// Only set the env if the value is not ""
if value != "" {
envs[env.Name] = value
}
}
for _, envFrom := range opts.Container.EnvFrom {
cmEnvs, err := envVarsFrom(envFrom, opts)
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/play_kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,7 @@ var _ = Describe("Podman play kube", func() {
inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(pod), "--format", "'{{ range .Config.Env }}[{{ . }}]{{end}}'"})
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(Exit(0))
Expect(inspect.OutputToString()).To(ContainSubstring(`[FOO=]`))
Expect(inspect.OutputToString()).To(Not(ContainSubstring(`[FOO=]`)))
})

It("podman play kube test optional env value from missing configmap", func() {
Expand All @@ -1674,7 +1674,7 @@ var _ = Describe("Podman play kube", func() {
inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(pod), "--format", "'{{ range .Config.Env }}[{{ . }}]{{end}}'"})
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(Exit(0))
Expect(inspect.OutputToString()).To(ContainSubstring(`[FOO=]`))
Expect(inspect.OutputToString()).To(Not(ContainSubstring(`[FOO=]`)))
})

It("podman play kube test get all key-value pairs from configmap as envs", func() {
Expand Down Expand Up @@ -1768,7 +1768,7 @@ var _ = Describe("Podman play kube", func() {
inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(pod), "--format", "'{{ range .Config.Env }}[{{ . }}]{{end}}'"})
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(Exit(0))
Expect(inspect.OutputToString()).To(ContainSubstring(`[FOO=]`))
Expect(inspect.OutputToString()).To(Not(ContainSubstring(`[FOO=]`)))
})

It("podman play kube test optional env value from secret with missing key", func() {
Expand All @@ -1784,7 +1784,7 @@ var _ = Describe("Podman play kube", func() {
inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(pod), "--format", "'{{ range .Config.Env }}[{{ . }}]{{end}}'"})
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(Exit(0))
Expect(inspect.OutputToString()).To(ContainSubstring(`[FOO=]`))
Expect(inspect.OutputToString()).To(Not(ContainSubstring(`[FOO=]`)))
})

It("podman play kube test get all key-value pairs from secret as envs", func() {
Expand Down Expand Up @@ -3212,7 +3212,7 @@ ENV OPENJ9_JAVA_OPTIONS=%q
inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(pod), "--format", "'{{ range .Config.Env }}[{{ . }}]{{end}}'"})
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(Exit(0))
Expect(inspect.OutputToString()).To(ContainSubstring(`[FOO=]`))
Expect(inspect.OutputToString()).To(Not(ContainSubstring(`[FOO=]`)))
})

It("podman play kube uses all key-value pairs as envs", func() {
Expand Down

0 comments on commit 8af574f

Please sign in to comment.