mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-24 19:38:02 +00:00
update docker's resolv.conf file with options ndots:5
This commit is contained in:
@@ -60,6 +60,10 @@ const (
|
||||
|
||||
kubernetesPodLabel = "io.kubernetes.pod.data"
|
||||
kubernetesContainerLabel = "io.kubernetes.container.name"
|
||||
// ndots specifies the minimum number of dots that a domain name must contain for the resolver to consider it as FQDN (fully-qualified)
|
||||
// we want to able to consider SRV lookup names like _dns._udp.kube-dns.default.svc to be considered relative.
|
||||
// hence, setting ndots to be 5.
|
||||
ndotsDNSOption = "options ndots:5\n"
|
||||
)
|
||||
|
||||
// DockerManager implements the Runtime interface.
|
||||
@@ -1221,6 +1225,13 @@ func (dm *DockerManager) runContainerInPod(pod *api.Pod, container *api.Containe
|
||||
}
|
||||
if container.Name == PodInfraContainerName {
|
||||
util.ApplyOomScoreAdj(containerInfo.State.Pid, podOomScoreAdj)
|
||||
// currently, Docker does not have a flag by which the ndots option can be passed.
|
||||
// (A seperate issue has been filed with Docker to add a ndots flag)
|
||||
// The addNDotsOption call appends the ndots option to the resolv.conf file generated by docker.
|
||||
// This resolv.conf file is shared by all containers of the same pod, and needs to be modified only once per pod.
|
||||
// we modify it when the pause container is created since it is the first container created in the pod since it holds
|
||||
// the networking namespace.
|
||||
err = addNDotsOption(containerInfo.ResolvConfPath)
|
||||
} else {
|
||||
// Children processes of docker daemon will inheritant the OOM score from docker
|
||||
// daemon process. We explicitly apply OOM score 0 by default to the user
|
||||
@@ -1231,6 +1242,36 @@ func (dm *DockerManager) runContainerInPod(pod *api.Pod, container *api.Containe
|
||||
return kubeletTypes.DockerID(id), err
|
||||
}
|
||||
|
||||
func addNDotsOption(resolvFilePath string) error {
|
||||
if len(resolvFilePath) == 0 {
|
||||
glog.Errorf("DNS ResolvConfPath is empty.")
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, err := os.Stat(resolvFilePath); os.IsNotExist(err) {
|
||||
return fmt.Errorf("DNS ResolvConfPath specified but does not exist. It could not be updated: %s", resolvFilePath)
|
||||
}
|
||||
|
||||
glog.V(4).Infof("DNS ResolvConfPath exists: %s. Will attempt to add ndots option: %s", resolvFilePath, ndotsDNSOption)
|
||||
|
||||
if err := appendToFile(resolvFilePath, ndotsDNSOption); err != nil {
|
||||
glog.Errorf("resolv.conf could not be updated. err:%v", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func appendToFile(filePath, stringToAppend string) error {
|
||||
f, err := os.OpenFile(filePath, os.O_APPEND|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
_, err = f.WriteString(stringToAppend)
|
||||
return err
|
||||
}
|
||||
|
||||
// createPodInfraContainer starts the pod infra container for a pod. Returns the docker container ID of the newly created container.
|
||||
func (dm *DockerManager) createPodInfraContainer(pod *api.Pod) (kubeletTypes.DockerID, error) {
|
||||
start := time.Now()
|
||||
|
Reference in New Issue
Block a user