mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 07:20:13 +00:00
kubelet: Don't attempt to apply the oom score if the container is not running
Containers could terminate before kubelet applies the oom score. This is normal and the function should not error out.
This commit is contained in:
parent
9784dff94e
commit
e3e1c7a6a1
@ -1494,14 +1494,28 @@ func (dm *DockerManager) runContainerInPod(pod *api.Pod, container *api.Containe
|
||||
if err != nil {
|
||||
return kubecontainer.ContainerID{}, fmt.Errorf("InspectContainer: %v", err)
|
||||
}
|
||||
|
||||
if !containerInfo.State.Running {
|
||||
if container.Name == PodInfraContainerName {
|
||||
// If the infra container exited prematurely, return an error to raise
|
||||
// awareness.
|
||||
return id, fmt.Errorf("Infra container %q exited prematruely", id)
|
||||
}
|
||||
// For a user container, simply returns since we cannot apply oom score
|
||||
// anymore.
|
||||
glog.V(4).Info("Container %q already exited", containerInfo.ID)
|
||||
return id, nil
|
||||
}
|
||||
|
||||
// Ensure the PID actually exists, else we'll move ourselves.
|
||||
// TODO: Should we simply log the error (or send an event) and move on? We
|
||||
// don't check the oom score in the next sync and correct it anyway.
|
||||
if containerInfo.State.Pid == 0 {
|
||||
return kubecontainer.ContainerID{}, fmt.Errorf("can't get init PID for container %q", id)
|
||||
}
|
||||
|
||||
// Check if current docker version is higher than 1.10. Otherwise, we have to apply OOMScoreAdj instead of using docker API.
|
||||
err = dm.applyOOMScoreAdjIfNeeded(container, containerInfo)
|
||||
if err != nil {
|
||||
// TODO: Remove this logic after we stop supporting docker version < 1.10.
|
||||
if err := dm.applyOOMScoreAdjIfNeeded(container, containerInfo); err != nil {
|
||||
return kubecontainer.ContainerID{}, err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user