Skip to content

Commit

Permalink
pass environment variables to container clone
Browse files Browse the repository at this point in the history
the env vars are held in the spec rather than the config, so they need to be mapped manually. They are also of a different format so special handling needed to be added. All env from the parent container will now be passed to the clone.

resolves #15242

Signed-off-by: Charlie Doern <[email protected]>
  • Loading branch information
cdoern committed Aug 22, 2022
1 parent aefd0ae commit 53369aa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
18 changes: 15 additions & 3 deletions pkg/specgen/generate/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,21 @@ func ConfigToSpec(rt *libpod.Runtime, specg *specgen.SpecGenerator, contaierID s
conf.Systemd = tmpSystemd
conf.Mounts = tmpMounts

if conf.Spec != nil && conf.Spec.Linux != nil && conf.Spec.Linux.Resources != nil {
if specg.ResourceLimits == nil {
specg.ResourceLimits = conf.Spec.Linux.Resources
if conf.Spec != nil {
if conf.Spec.Linux != nil && conf.Spec.Linux.Resources != nil {
if specg.ResourceLimits == nil {
specg.ResourceLimits = conf.Spec.Linux.Resources
}
}
if conf.Spec.Process != nil && conf.Spec.Process.Env != nil {
env := make(map[string]string)
for _, entry := range conf.Spec.Process.Env {
split := strings.Split(entry, "=")
if len(split) == 2 {
env[split[0]] = split[1]
}
}
specg.Env = env
}
}

Expand Down
16 changes: 16 additions & 0 deletions test/e2e/container_clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,20 @@ var _ = Describe("Podman container clone", func() {
Expect(ok).To(BeTrue())

})

It("podman container clone env test", func() {
session := podmanTest.Podman([]string{"run", "--name", "env_ctr", "-e", "ENV_TEST=123", ALPINE, "printenv", "ENV_TEST"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))

session = podmanTest.Podman([]string{"container", "clone", "env_ctr"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))

session = podmanTest.Podman([]string{"start", "-a", "env_ctr-clone"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expect(session.OutputToString()).Should(ContainSubstring("123"))

})
})

0 comments on commit 53369aa

Please sign in to comment.