mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-10-14 01:47:43 +00:00
fix pod creation with "new:" syntax followup + allow hostname
Fixes:4c75fe3f70("fix pod creation with "new:" syntax") Commit4c75fe3f70passes all net options to the pod but forgot to unset the options for the container creation. This leads to erros when using flags like `--ip` since we tried setting the ip on the pod and container which obviously fails. I didn't notice the bug because we don't throw an error when specifing port bindings on a container which joins the pods network namespace. (#7373) Also allow the use of `--hostname` and pass that option to the pod and unset it for the container. The container has to use the pods hostname anyway. This would error otherwise. Added tests to prevent regression. Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
This commit is contained in:
parent
f12f2456af
commit
7fc3c25410
3 changed files with 43 additions and 2 deletions
|
|
@ -292,7 +292,12 @@ func createPodIfNecessary(s *specgen.SpecGenerator, netOpts *entities.NetOptions
|
|||
Infra: true,
|
||||
Net: netOpts,
|
||||
CreateCommand: os.Args,
|
||||
Hostname: s.ContainerBasicConfig.Hostname,
|
||||
}
|
||||
// Unset config values we passed to the pod to prevent them being used twice for the container and pod.
|
||||
s.ContainerBasicConfig.Hostname = ""
|
||||
s.ContainerNetworkConfig = specgen.ContainerNetworkConfig{}
|
||||
|
||||
s.Pod = podName
|
||||
return registry.ContainerEngine().PodCreate(context.Background(), createOptions)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -437,8 +437,8 @@ var _ = Describe("Podman run networking", func() {
|
|||
It("podman run in custom CNI network with --static-ip", func() {
|
||||
SkipIfRootless()
|
||||
netName := "podmantestnetwork"
|
||||
ipAddr := "10.20.30.128"
|
||||
create := podmanTest.Podman([]string{"network", "create", "--subnet", "10.20.30.0/24", netName})
|
||||
ipAddr := "10.25.30.128"
|
||||
create := podmanTest.Podman([]string{"network", "create", "--subnet", "10.25.30.0/24", netName})
|
||||
create.WaitWithDefaultTimeout()
|
||||
Expect(create.ExitCode()).To(BeZero())
|
||||
|
||||
|
|
@ -446,5 +446,33 @@ var _ = Describe("Podman run networking", func() {
|
|||
run.WaitWithDefaultTimeout()
|
||||
Expect(run.ExitCode()).To(BeZero())
|
||||
Expect(run.OutputToString()).To(ContainSubstring(ipAddr))
|
||||
|
||||
netrm := podmanTest.Podman([]string{"network", "rm", netName})
|
||||
netrm.WaitWithDefaultTimeout()
|
||||
Expect(netrm.ExitCode()).To(BeZero())
|
||||
})
|
||||
|
||||
It("podman run with new:pod and static-ip", func() {
|
||||
SkipIfRemote()
|
||||
SkipIfRootless()
|
||||
netName := "podmantestnetwork2"
|
||||
ipAddr := "10.25.40.128"
|
||||
podname := "testpod"
|
||||
create := podmanTest.Podman([]string{"network", "create", "--subnet", "10.25.40.0/24", netName})
|
||||
create.WaitWithDefaultTimeout()
|
||||
Expect(create.ExitCode()).To(BeZero())
|
||||
|
||||
run := podmanTest.Podman([]string{"run", "-t", "-i", "--rm", "--pod", "new:" + podname, "--net", netName, "--ip", ipAddr, ALPINE, "ip", "addr"})
|
||||
run.WaitWithDefaultTimeout()
|
||||
Expect(run.ExitCode()).To(BeZero())
|
||||
Expect(run.OutputToString()).To(ContainSubstring(ipAddr))
|
||||
|
||||
podrm := podmanTest.Podman([]string{"pod", "rm", "-f", podname})
|
||||
podrm.WaitWithDefaultTimeout()
|
||||
Expect(podrm.ExitCode()).To(BeZero())
|
||||
|
||||
netrm := podmanTest.Podman([]string{"network", "rm", netName})
|
||||
netrm.WaitWithDefaultTimeout()
|
||||
Expect(netrm.ExitCode()).To(BeZero())
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -835,6 +835,14 @@ USER mail`
|
|||
Expect(match).To(BeTrue())
|
||||
})
|
||||
|
||||
It("podman run --pod new with hostname", func() {
|
||||
hostname := "abc"
|
||||
session := podmanTest.Podman([]string{"run", "--pod", "new:foobar", "--hostname", hostname, ALPINE, "cat", "/etc/hostname"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(session.OutputToString()).To(ContainSubstring(hostname))
|
||||
})
|
||||
|
||||
It("podman run --rm should work", func() {
|
||||
session := podmanTest.Podman([]string{"run", "--rm", ALPINE, "ls"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue