From 6caefcc4bc6208f6f9c106eec4a076fb4e99da36 Mon Sep 17 00:00:00 2001 From: Aditya R Date: Mon, 17 Oct 2022 14:39:10 +0530 Subject: [PATCH] podman: relay custom DNS servers to network stack Aardvark-dns and netavark now accepts custom DNS servers for containers via new config field `dns_servers`. New field allows containers to use custom resolvers instead of host's default resolvers. Following commit instruments libpod to pass these custom DNS servers set via `--dns` or central config to the network stack. Depends-on: * Common: https://github.com/containers/common/pull/1189 * Netavark: https://github.com/containers/netavark/pull/452 * Aardvark-dns: https://github.com/containers/aardvark-dns/pull/240 [NO NEW TESTS ADDED] [NO TESTS ADDED] Signed-off-by: Aditya R --- libpod/networking_common.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libpod/networking_common.go b/libpod/networking_common.go index fa444e26ab..4c57079921 100644 --- a/libpod/networking_common.go +++ b/libpod/networking_common.go @@ -39,9 +39,15 @@ func (c *Container) convertPortMappings() []types.PortMapping { } func (c *Container) getNetworkOptions(networkOpts map[string]types.PerNetworkOptions) types.NetworkOptions { + nameservers := make([]string, 0, len(c.runtime.config.Containers.DNSServers)+len(c.config.DNSServer)) + nameservers = append(nameservers, c.runtime.config.Containers.DNSServers...) + for _, ip := range c.config.DNSServer { + nameservers = append(nameservers, ip.String()) + } opts := types.NetworkOptions{ ContainerID: c.config.ID, ContainerName: getCNIPodName(c), + DNSServers: nameservers, } opts.PortMappings = c.convertPortMappings()