Merge pull request #468 from sameo/topic/hosts

container: Bind mount hosts file for host networking containers
This commit is contained in:
Antonio Murdaca 2017-04-22 09:57:32 +02:00 committed by GitHub
commit 152f7d077d

View file

@ -175,6 +175,15 @@ func setupContainerUser(specgen *generate.Generator, rootfs string, sc *pb.Linux
return nil
}
func hostNetwork(containerConfig *pb.ContainerConfig) bool {
securityContext := containerConfig.GetLinux().GetSecurityContext()
if securityContext == nil || securityContext.GetNamespaceOptions() == nil {
return false
}
return securityContext.GetNamespaceOptions().HostNetwork
}
// ensureSaneLogPath is a hack to fix https://issues.k8s.io/44043 which causes
// logPath to be a broken symlink to some magical Docker path. Ideally we
// wouldn't have to deal with this, but until that issue is fixed we have to
@ -455,6 +464,11 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
specgen.AddBindMount(sb.resolvPath, "/etc/resolv.conf", []string{"ro"})
}
// Bind mount /etc/hosts for host networking containers
if hostNetwork(containerConfig) {
specgen.AddBindMount("/etc/hosts", "/etc/hosts", []string{"ro"})
}
if sb.hostname != "" {
specgen.SetHostname(sb.hostname)
}