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

netavark: macvlan networks keep custom nameservers #19207

Merged
merged 1 commit into from
Jul 12, 2023
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
6 changes: 3 additions & 3 deletions libpod/container_internal_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
17 changes: 17 additions & 0 deletions test/e2e/run_networking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: move this line below the following exit-code check. If creation fails, remove will as well and cause some noise in the output.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this pattern is used almost everywhere I rather not change that now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes many small nits :^)

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
`))
})
})