From 9d0470f125482a55a1b4d5d8ef38529cb505b485 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Wed, 12 Jul 2023 14:04:03 +0200 Subject: [PATCH] netavark: macvlan networks keep custom nameservers The change to use the custom dns server in aardvark-dns caused a regression here because macvlan networks never returned the nameservers in netavark and it also does not make sense to do so. Instead check here if we got any network nameservers, if not we then use the ones from the config if set otherwise fallback to host servers. Fixes #19169 Signed-off-by: Paul Holzinger --- libpod/container_internal_common.go | 6 +++--- test/e2e/run_networking_test.go | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/libpod/container_internal_common.go b/libpod/container_internal_common.go index 87794eeba7..13fe44e734 100644 --- a/libpod/container_internal_common.go +++ b/libpod/container_internal_common.go @@ -2077,12 +2077,12 @@ func (c *Container) addResolvConf() error { // If NetworkBackend is `netavark` do not populate `/etc/resolv.conf` // with custom dns server since after https://github.com/containers/netavark/pull/452 - // netavark will always set required `nameservers` in statsBlock and libpod + // netavark will always set required `nameservers` in StatusBlock and libpod // will correctly populate `networkNameServers`. Also see https://github.com/containers/podman/issues/16172 // Exception: Populate `/etc/resolv.conf` if container is not connected to any network - // ( i.e len(netStatus)==0 ) since in such case netavark is not invoked at all. - if networkBackend != string(types.Netavark) || len(netStatus) == 0 { + // with dns enabled then we do not get any nameservers back. + if networkBackend != string(types.Netavark) || len(networkNameServers) == 0 { nameservers = append(nameservers, c.runtime.config.Containers.DNSServers...) for _, ip := range c.config.DNSServer { nameservers = append(nameservers, ip.String()) diff --git a/test/e2e/run_networking_test.go b/test/e2e/run_networking_test.go index 19809203b5..fc185ca8b2 100644 --- a/test/e2e/run_networking_test.go +++ b/test/e2e/run_networking_test.go @@ -1186,4 +1186,21 @@ EXPOSE 2004-2005/tcp`, ALPINE) Expect(session).Should(Exit(0)) Expect(session.OutputToStringArray()).To(HaveLen(4), "output should only show link local address") }) + + It("podman run with macvlan network", func() { + net := "mv-" + stringid.GenerateRandomID() + session := podmanTest.Podman([]string{"network", "create", "-d", "macvlan", "--subnet", "10.10.0.0/24", net}) + session.WaitWithDefaultTimeout() + defer podmanTest.removeNetwork(net) + Expect(session).Should(Exit(0)) + + // use options and search to make sure we get the same resolv.conf everywhere + run := podmanTest.Podman([]string{"run", "--network", net, "--dns", "127.0.0.128", + "--dns-option", "ndots:1", "--dns-search", ".", ALPINE, "cat", "/etc/resolv.conf"}) + run.WaitWithDefaultTimeout() + Expect(run).Should(Exit(0)) + Expect(string(run.Out.Contents())).To(Equal(`nameserver 127.0.0.128 +options ndots:1 +`)) + }) })