summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-02-21 08:55:27 -0500
committerGitHub <noreply@github.com>2020-02-21 08:55:27 -0500
commit4f5b40598f53915f138208e493279dfcfe70ab06 (patch)
treeedb25bddf6a06ffc31c2769c5143b8084e4fdbad
parent1c476d769610774864275711f49e429e27d84a73 (diff)
parent921f29c902ea6755f58a88637f447ddcf278f6ba (diff)
downloadpodman-4f5b40598f53915f138208e493279dfcfe70ab06.tar.gz
podman-4f5b40598f53915f138208e493279dfcfe70ab06.tar.bz2
podman-4f5b40598f53915f138208e493279dfcfe70ab06.zip
Merge pull request #5271 from baude/dnsnameuserns
populate resolv.conf with dnsname responses when in usernamespace
-rw-r--r--libpod/container_internal.go33
1 files changed, 32 insertions, 1 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go
index 216bbe669..11f9721dc 100644
--- a/libpod/container_internal.go
+++ b/libpod/container_internal.go
@@ -914,6 +914,7 @@ func (c *Container) checkDependenciesRunning() ([]string, error) {
}
func (c *Container) completeNetworkSetup() error {
+ var outResolvConf []string
netDisabled, err := c.NetworkDisabled()
if err != nil {
return err
@@ -927,7 +928,37 @@ func (c *Container) completeNetworkSetup() error {
if c.config.NetMode == "slirp4netns" {
return c.runtime.setupRootlessNetNS(c)
}
- return c.runtime.setupNetNS(c)
+ if err := c.runtime.setupNetNS(c); err != nil {
+ return err
+ }
+ state := c.state
+ // collect any dns servers that cni tells us to use (dnsname)
+ for _, cni := range state.NetworkStatus {
+ if cni.DNS.Nameservers != nil {
+ for _, server := range cni.DNS.Nameservers {
+ outResolvConf = append(outResolvConf, fmt.Sprintf("nameserver %s", server))
+ }
+ }
+ }
+ // check if we have a bindmount for resolv.conf
+ resolvBindMount := state.BindMounts["/etc/resolv.conf"]
+ if len(outResolvConf) < 1 || resolvBindMount == "" || len(c.config.NetNsCtr) > 0 {
+ return nil
+ }
+ // read the existing resolv.conf
+ b, err := ioutil.ReadFile(resolvBindMount)
+ if err != nil {
+ return err
+ }
+ for _, line := range strings.Split(string(b), "\n") {
+ // only keep things that dont start with nameserver from the old
+ // resolv.conf file
+ if !strings.HasPrefix(line, "nameserver") {
+ outResolvConf = append([]string{line}, outResolvConf...)
+ }
+ }
+ // write and return
+ return ioutil.WriteFile(resolvBindMount, []byte(strings.Join(outResolvConf, "\n")), 0644)
}
// Initialize a container, creating it in the runtime