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

Use SplitN(2) when copying env variables #11920

Merged
merged 1 commit into from
Oct 11, 2021
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
2 changes: 1 addition & 1 deletion pkg/specgen/generate/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

Expand Down
42 changes: 42 additions & 0 deletions test/e2e/play_kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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))
})
})

})