diff options
author | Paul Holzinger <pholzing@redhat.com> | 2021-09-16 12:37:06 +0200 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2021-09-22 16:13:37 -0400 |
commit | be15a01c5e636d105d638c958a69420a21ac7ff4 (patch) | |
tree | 1845348873e62825d57484b2a85dbaec4a699582 | |
parent | d27fcbdc21a4c5fc201997068f871cf1e91561a1 (diff) | |
download | podman-be15a01c5e636d105d638c958a69420a21ac7ff4.tar.gz podman-be15a01c5e636d105d638c958a69420a21ac7ff4.tar.bz2 podman-be15a01c5e636d105d638c958a69420a21ac7ff4.zip |
Only add 127.0.0.1 entry to /etc/hosts with --net=none
The check for net=none was wrong. It just assumed when we do not create
the netns but have one set that we use the none mode. This however also
applies to a container which joins the pod netns.
To correctly check for the none mode use `config.NetMode.IsNone()`.
Fixes #11596
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
-rw-r--r-- | libpod/container_internal_linux.go | 13 | ||||
-rw-r--r-- | test/e2e/run_networking_test.go | 12 |
2 files changed, 19 insertions, 6 deletions
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go index 4194a0d93..89287efc9 100644 --- a/libpod/container_internal_linux.go +++ b/libpod/container_internal_linux.go @@ -2001,15 +2001,16 @@ func (c *Container) getHosts() string { // Do we have a network namespace? netNone := false - for _, ns := range c.config.Spec.Linux.Namespaces { - if ns.Type == spec.NetworkNamespace { - if ns.Path == "" && !c.config.CreateNetNS { - netNone = true + if c.config.NetNsCtr == "" && !c.config.CreateNetNS { + for _, ns := range c.config.Spec.Linux.Namespaces { + if ns.Type == spec.NetworkNamespace { + if ns.Path == "" { + netNone = true + } + break } - break } } - // If we are net=none (have a network namespace, but not connected to // anything) add the container's name and hostname to localhost. if netNone { diff --git a/test/e2e/run_networking_test.go b/test/e2e/run_networking_test.go index 8eabeba97..c7ffdaf4c 100644 --- a/test/e2e/run_networking_test.go +++ b/test/e2e/run_networking_test.go @@ -709,6 +709,18 @@ var _ = Describe("Podman run networking", func() { Expect(strings.Contains(run.OutputToString(), hostname)).To(BeTrue()) }) + It("podman run with pod does not add extra 127 entry to /etc/hosts", func() { + pod := "testpod" + hostname := "test-hostname" + run := podmanTest.Podman([]string{"pod", "create", "--hostname", hostname, "--name", pod}) + run.WaitWithDefaultTimeout() + Expect(run).Should(Exit(0)) + run = podmanTest.Podman([]string{"run", "--pod", pod, ALPINE, "cat", "/etc/hosts"}) + run.WaitWithDefaultTimeout() + Expect(run).Should(Exit(0)) + Expect(run.OutputToString()).ToNot(ContainSubstring("127.0.0.1 %s", hostname)) + }) + ping_test := func(netns string) { hostname := "testctr" run := podmanTest.Podman([]string{"run", netns, "--hostname", hostname, ALPINE, "ping", "-c", "1", hostname}) |