Skip to content

Commit

Permalink
Report errors from rewriting /etc/hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
bboreham committed Oct 4, 2017
1 parent c16653a commit 79d65bc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 1 addition & 2 deletions proxy/hosts.go
Expand Up @@ -20,8 +20,7 @@ func (proxy *Proxy) RewriteEtcHosts(hostsPath, fqdn string, ips []*net.IPNet, ex
contents := buf.String()
cmdLine := fmt.Sprintf("echo '%s' > %s && rm -f %s && echo '%s' > %s", contents, mntHosts, mntHosts, contents, mntHosts)
mounts := []string{hostsPathDir + ":" + mnt}
proxy.runTransientContainer([]string{"sh"}, []string{"-c", cmdLine}, mounts)
return nil
return proxy.runTransientContainer([]string{"sh"}, []string{"-c", cmdLine}, mounts)
}

// we assume (for compatibility with the weave script) that fqdn has a dot
Expand Down
6 changes: 5 additions & 1 deletion proxy/proxy.go
Expand Up @@ -510,7 +510,10 @@ func (proxy *Proxy) attach(containerID string) error {
if container.HostConfig != nil {
extraHosts = container.HostConfig.ExtraHosts
}
proxy.RewriteEtcHosts(container.HostsPath, fqdn, ips, extraHosts)
if err := proxy.RewriteEtcHosts(container.HostsPath, fqdn, ips, extraHosts); err != nil {
Log.Errorf("Error from rewriting container's /etc/hosts: %s", err)
// carry on since the original /etc/hosts is good enough in most cases
}
}

pid := container.State.Pid
Expand Down Expand Up @@ -684,6 +687,7 @@ func (proxy *Proxy) runTransientContainer(entrypoint, cmd, binds []string) (err
env = append(env, fmt.Sprintf("%s=%s", "WEAVE_DEBUG", val))
}

Log.Debugf("Running image %q; entrypoint=%q; cmd=%q; binds=%q", proxy.Image, entrypoint, fmt.Sprintf("%.72s", cmd), binds)
var container *docker.Container
container, err = proxy.client.CreateContainer(docker.CreateContainerOptions{
Config: &docker.Config{
Expand Down

0 comments on commit 79d65bc

Please sign in to comment.