mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 07:27:21 +00:00
@@ -1357,6 +1357,38 @@ func containerAndPodFromLabels(inspect *docker.Container) (pod *api.Pod, contain
|
||||
return
|
||||
}
|
||||
|
||||
func (dm *DockerManager) applyOOMScoreAdj(container *api.Container, containerInfo *docker.Container) error {
|
||||
cgroupName, err := dm.procFs.GetFullContainerName(containerInfo.State.Pid)
|
||||
if err != nil {
|
||||
if err == os.ErrNotExist {
|
||||
// Container exited. We cannot do anything about it. Ignore this error.
|
||||
glog.V(2).Infof("Failed to apply OOM score adj on container %q with ID %q. Init process does not exist.", containerInfo.Name, containerInfo.ID)
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
// Set OOM score of the container based on the priority of the container.
|
||||
// Processes in lower-priority pods should be killed first if the system runs out of memory.
|
||||
// The main pod infrastructure container is considered high priority, since if it is killed the
|
||||
// whole pod will die.
|
||||
// TODO: Cache this value.
|
||||
var oomScoreAdj int
|
||||
if containerInfo.Name == PodInfraContainerName {
|
||||
oomScoreAdj = qos.PodInfraOOMAdj
|
||||
} else {
|
||||
oomScoreAdj = qos.GetContainerOOMScoreAdjust(container, int64(dm.machineInfo.MemoryCapacity))
|
||||
}
|
||||
if err = dm.oomAdjuster.ApplyOOMScoreAdjContainer(cgroupName, oomScoreAdj, 5); err != nil {
|
||||
if err == os.ErrNotExist {
|
||||
// Container exited. We cannot do anything about it. Ignore this error.
|
||||
glog.V(2).Infof("Failed to apply OOM score adj on container %q with ID %q. Init process does not exist.", containerInfo.Name, containerInfo.ID)
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run a single container from a pod. Returns the docker container ID
|
||||
// If do not need to pass labels, just pass nil.
|
||||
func (dm *DockerManager) runContainerInPod(pod *api.Pod, container *api.Container, netMode, ipcMode, pidMode string, restartCount int) (kubecontainer.ContainerID, error) {
|
||||
@@ -1418,24 +1450,9 @@ func (dm *DockerManager) runContainerInPod(pod *api.Pod, container *api.Containe
|
||||
return kubecontainer.ContainerID{}, fmt.Errorf("can't get init PID for container %q", id)
|
||||
}
|
||||
|
||||
// Set OOM score of the container based on the priority of the container.
|
||||
// Processes in lower-priority pods should be killed first if the system runs out of memory.
|
||||
// The main pod infrastructure container is considered high priority, since if it is killed the
|
||||
// whole pod will die.
|
||||
var oomScoreAdj int
|
||||
if container.Name == PodInfraContainerName {
|
||||
oomScoreAdj = qos.PodInfraOOMAdj
|
||||
} else {
|
||||
oomScoreAdj = qos.GetContainerOOMScoreAdjust(container, int64(dm.machineInfo.MemoryCapacity))
|
||||
if err := dm.applyOOMScoreAdj(container, containerInfo); err != nil {
|
||||
return kubecontainer.ContainerID{}, fmt.Errorf("failed to apply oom-score-adj to container %q- %v", err, containerInfo.Name)
|
||||
}
|
||||
cgroupName, err := dm.procFs.GetFullContainerName(containerInfo.State.Pid)
|
||||
if err != nil {
|
||||
return kubecontainer.ContainerID{}, fmt.Errorf("GetFullContainerName: %v", err)
|
||||
}
|
||||
if err = dm.oomAdjuster.ApplyOOMScoreAdjContainer(cgroupName, oomScoreAdj, 5); err != nil {
|
||||
return kubecontainer.ContainerID{}, fmt.Errorf("ApplyOOMScoreAdjContainer: %v", err)
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user