summaryrefslogtreecommitdiff
path: root/libpod/container_internal_linux.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-08-28 13:19:15 -0500
committerbaude <bbaude@redhat.com>2019-09-03 10:10:05 -0500
commit8818e358bf4d934b494bb38c545c7e72a4fb26e6 (patch)
tree2c7297018e387e072d08ad51bc7949004a3eadf8 /libpod/container_internal_linux.go
parent03344fff1cd41c8a1cc8cec2ac3877b25505fb0c (diff)
downloadpodman-8818e358bf4d934b494bb38c545c7e72a4fb26e6.tar.gz
podman-8818e358bf4d934b494bb38c545c7e72a4fb26e6.tar.bz2
podman-8818e358bf4d934b494bb38c545c7e72a4fb26e6.zip
handle dns response from cni
when cni returns a list of dns servers, we should add them under the right conditions. the defined conditions are as follows: - if the user provides dns, it and only it are added. - if not above and you get a cni name server, it is added and a forwarding dns instance is created for what was in resolv.conf. - if not either above, the entries from the host's resolv.conf are used. Signed-off-by: baude <bbaude@redhat.com> Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'libpod/container_internal_linux.go')
-rw-r--r--libpod/container_internal_linux.go30
1 files changed, 24 insertions, 6 deletions
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go
index 5aa4ee9a9..cb19b5484 100644
--- a/libpod/container_internal_linux.go
+++ b/libpod/container_internal_linux.go
@@ -1039,6 +1039,11 @@ func (c *Container) makeBindMounts() error {
// generateResolvConf generates a containers resolv.conf
func (c *Container) generateResolvConf() (string, error) {
+ var (
+ nameservers []string
+ cniNameServers []string
+ )
+
resolvConf := "/etc/resolv.conf"
for _, namespace := range c.config.Spec.Linux.Namespaces {
if namespace.Type == spec.NetworkNamespace {
@@ -1074,18 +1079,31 @@ func (c *Container) generateResolvConf() (string, error) {
return "", errors.Wrapf(err, "error parsing host resolv.conf")
}
- // Make a new resolv.conf
- nameservers := resolvconf.GetNameservers(resolv.Content)
- // slirp4netns has a built in DNS server.
- if c.config.NetMode.IsSlirp4netns() {
- nameservers = append([]string{"10.0.2.3"}, nameservers...)
+ // Check if CNI gave back and DNS servers for us to add in
+ cniResponse := c.state.NetworkStatus
+ for _, i := range cniResponse {
+ if i.DNS.Nameservers != nil {
+ cniNameServers = append(cniNameServers, i.DNS.Nameservers...)
+ logrus.Debugf("adding nameserver(s) from cni response of '%q'", i.DNS.Nameservers)
+ }
}
+
+ // If the user provided dns, it trumps all; then dns masq; then resolv.conf
if len(c.config.DNSServer) > 0 {
// We store DNS servers as net.IP, so need to convert to string
- nameservers = []string{}
for _, server := range c.config.DNSServer {
nameservers = append(nameservers, server.String())
}
+ } else if len(cniNameServers) > 0 {
+ nameservers = append(nameservers, cniNameServers...)
+ } else {
+ // Make a new resolv.conf
+ nameservers = resolvconf.GetNameservers(resolv.Content)
+ // slirp4netns has a built in DNS server.
+ if c.config.NetMode.IsSlirp4netns() {
+ nameservers = append([]string{"10.0.2.3"}, nameservers...)
+ }
+
}
search := resolvconf.GetSearchDomains(resolv.Content)