fix(generate): fix up podman generate kube missing env field bug

the logic is: if the process env vars key exists in podman default or in image defined, and the value is equal, skip the env var key.
the typo make it compare to itself -_-
so, here comes the simple fixup.

Signed-off-by: 荒野無燈 <ttys3.rust@gmail.com>
This commit is contained in:
荒野無燈
2021-12-18 08:37:24 +08:00
parent 59766ebe76
commit af6bcd0867
2 changed files with 25 additions and 1 deletions

View File

@ -747,7 +747,7 @@ func libpodEnvVarsToKubeEnvVars(envs []string, imageEnvs []string) ([]v1.EnvVar,
defaultEnv := env.DefaultEnvVariables() defaultEnv := env.DefaultEnvVariables()
envVars := make([]v1.EnvVar, 0, len(envs)) envVars := make([]v1.EnvVar, 0, len(envs))
imageMap := make(map[string]string, len(imageEnvs)) imageMap := make(map[string]string, len(imageEnvs))
for _, ie := range envs { for _, ie := range imageEnvs {
split := strings.SplitN(ie, "=", 2) split := strings.SplitN(ie, "=", 2)
imageMap[split[0]] = split[1] imageMap[split[0]] = split[1]
} }

View File

@ -1100,4 +1100,28 @@ USER test1`
Expect(pod.GetAnnotations()).To(HaveKeyWithValue("io.containers.autoupdate.authfile/"+ctr, "/some/authfile.json")) Expect(pod.GetAnnotations()).To(HaveKeyWithValue("io.containers.autoupdate.authfile/"+ctr, "/some/authfile.json"))
} }
}) })
It("podman generate kube can export env variables correctly", func() {
// Fixes https://github.com/containers/podman/issues/12647
// PR https://github.com/containers/podman/pull/12648
ctrName := "gen-kube-env-ctr"
podName := "gen-kube-env"
session1 := podmanTest.Podman([]string{"run", "-d", "--pod", "new:" + podName, "--name", ctrName,
"-e", "FOO=bar",
"-e", "HELLO=WORLD",
"alpine", "top"})
session1.WaitWithDefaultTimeout()
Expect(session1).Should(Exit(0))
kube := podmanTest.Podman([]string{"generate", "kube", podName})
kube.WaitWithDefaultTimeout()
Expect(kube).Should(Exit(0))
pod := new(v1.Pod)
err := yaml.Unmarshal(kube.Out.Contents(), pod)
Expect(err).To(BeNil())
Expect(pod.Spec.Containers[0].Env).To(HaveLen(2))
})
}) })