aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-10-11 20:29:05 +0200
committerGitHub <noreply@github.com>2021-10-11 20:29:05 +0200
commit2fcec59445267e8c8e06005539701a172d3db8a5 (patch)
tree193efc5f2e57ccedb0bf07d2423960cea2dfed95
parent00ebf3cf1885fc95c3c36021e717db1f1e7d63be (diff)
parent6b2939884cd774fa70304a2a198e9c572242eda9 (diff)
downloadpodman-2fcec59445267e8c8e06005539701a172d3db8a5.tar.gz
podman-2fcec59445267e8c8e06005539701a172d3db8a5.tar.bz2
podman-2fcec59445267e8c8e06005539701a172d3db8a5.zip
Merge pull request #11920 from jwhonce/issues/11891
Use SplitN(2) when copying env variables
-rw-r--r--pkg/specgen/generate/kube/kube.go2
-rw-r--r--test/e2e/play_kube_test.go42
2 files changed, 43 insertions, 1 deletions
diff --git a/pkg/specgen/generate/kube/kube.go b/pkg/specgen/generate/kube/kube.go
index e93462008..6eebc6376 100644
--- a/pkg/specgen/generate/kube/kube.go
+++ b/pkg/specgen/generate/kube/kube.go
@@ -257,7 +257,7 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener
// Environment Variables
envs := map[string]string{}
for _, env := range imageData.Config.Env {
- keyval := strings.Split(env, "=")
+ keyval := strings.SplitN(env, "=", 2)
envs[keyval[0]] = keyval[1]
}
diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go
index 079bb53b5..8aeba9d75 100644
--- a/test/e2e/play_kube_test.go
+++ b/test/e2e/play_kube_test.go
@@ -18,6 +18,7 @@ import (
"github.com/containers/storage/pkg/stringid"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
+ "github.com/onsi/gomega/format"
. "github.com/onsi/gomega/gexec"
"github.com/opencontainers/selinux/go-selinux"
)
@@ -2852,4 +2853,45 @@ invalid kube kind
Expect(ls).Should(Exit(0))
Expect(len(ls.OutputToStringArray())).To(Equal(1))
})
+
+ Describe("verify environment variables", func() {
+ var maxLength int
+ BeforeEach(func() {
+ maxLength = format.MaxLength
+ format.MaxLength = 0
+ })
+ AfterEach(func() {
+ format.MaxLength = maxLength
+ })
+
+ It("values containing equal sign", func() {
+ javaToolOptions := `-XX:+IgnoreUnrecognizedVMOptions -XX:+IdleTuningGcOnIdle -Xshareclasses:name=openj9_system_scc,cacheDir=/opt/java/.scc,readonly,nonFatal`
+ openj9JavaOptions := `-XX:+IgnoreUnrecognizedVMOptions -XX:+IdleTuningGcOnIdle -Xshareclasses:name=openj9_system_scc,cacheDir=/opt/java/.scc,readonly,nonFatal -Dosgi.checkConfiguration=false`
+
+ containerfile := fmt.Sprintf(`FROM %s
+ENV JAVA_TOOL_OPTIONS=%q
+ENV OPENJ9_JAVA_OPTIONS=%q
+`,
+ ALPINE, javaToolOptions, openj9JavaOptions)
+
+ image := "podman-kube-test:env"
+ podmanTest.BuildImage(containerfile, image, "false")
+ ctnr := getCtr(withImage(image))
+ pod := getPod(withCtr(ctnr))
+ Expect(generateKubeYaml("pod", pod, kubeYaml)).Should(Succeed())
+
+ play := podmanTest.Podman([]string{"play", "kube", "--start", kubeYaml})
+ play.WaitWithDefaultTimeout()
+ Expect(play).Should(Exit(0))
+
+ inspect := podmanTest.Podman([]string{"container", "inspect", "--format=json", getCtrNameInPod(pod)})
+ inspect.WaitWithDefaultTimeout()
+ Expect(inspect).Should(Exit(0))
+
+ contents := string(inspect.Out.Contents())
+ Expect(contents).To(ContainSubstring(javaToolOptions))
+ Expect(contents).To(ContainSubstring(openj9JavaOptions))
+ })
+ })
+
})