mirror of
https://github.com/containers/podman.git
synced 2025-05-21 00:56:36 +08:00
Don't add env if optional and not found
If the pod yaml has env from secret and condifg map but they are optional and the secret cannot be found, don't add the env key as well as the env value will not be found. Matches behavior with k8s. Signed-off-by: Urvashi Mohnani <umohnani@redhat.com>
This commit is contained in:
@ -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)
|
||||
|
@ -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() {
|
||||
@ -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() {
|
||||
@ -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() {
|
||||
@ -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() {
|
||||
@ -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() {
|
||||
|
Reference in New Issue
Block a user