diff options
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/container_api.go | 36 | ||||
-rw-r--r-- | libpod/container_internal_linux.go | 30 | ||||
-rw-r--r-- | libpod/util.go | 6 |
3 files changed, 47 insertions, 25 deletions
diff --git a/libpod/container_api.go b/libpod/container_api.go index 9e59104cc..9bf97c5d4 100644 --- a/libpod/container_api.go +++ b/libpod/container_api.go @@ -14,7 +14,6 @@ import ( "github.com/opentracing/opentracing-go" "github.com/pkg/errors" "github.com/sirupsen/logrus" - "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/tools/remotecommand" ) @@ -524,24 +523,25 @@ func (c *Container) WaitWithInterval(waitTimeout time.Duration) (int32, error) { if !c.valid { return -1, define.ErrCtrRemoved } - err := wait.PollImmediateInfinite(waitTimeout, - func() (bool, error) { - logrus.Debugf("Checking container %s status...", c.ID()) - stopped, err := c.isStopped() - if err != nil { - return false, err - } - if !stopped { - return false, nil - } - return true, nil - }, - ) - if err != nil { - return 0, err + + exitFile := c.exitFilePath() + chWait := make(chan error, 1) + + defer close(chWait) + + for { + // ignore errors here, it is only used to avoid waiting + // too long. + _, _ = WaitForFile(exitFile, chWait, waitTimeout) + + stopped, err := c.isStopped() + if err != nil { + return -1, err + } + if stopped { + return c.state.ExitCode, nil + } } - exitCode := c.state.ExitCode - return exitCode, nil } // Cleanup unmounts all mount points in container and cleans up container storage 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) diff --git a/libpod/util.go b/libpod/util.go index b60575264..164800af4 100644 --- a/libpod/util.go +++ b/libpod/util.go @@ -69,7 +69,11 @@ func WaitForFile(path string, chWait chan error, timeout time.Duration) (bool, e defer watcher.Close() } - timeoutChan := time.After(timeout) + var timeoutChan <-chan time.Time + + if timeout != 0 { + timeoutChan = time.After(timeout) + } for { select { |