mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 22:17:14 +00:00
Always restart container in unknown state.
This commit is contained in:
parent
271784e5fa
commit
45064d7a1e
@ -57,6 +57,10 @@ func ShouldContainerBeRestarted(container *api.Container, pod *api.Pod, podStatu
|
||||
if status.State == ContainerStateRunning {
|
||||
return false
|
||||
}
|
||||
// Always restart container in unknown state now
|
||||
if status.State == ContainerStateUnknown {
|
||||
return true
|
||||
}
|
||||
// Check RestartPolicy for dead container
|
||||
if pod.Spec.RestartPolicy == api.RestartPolicyNever {
|
||||
glog.V(4).Infof("Already ran container %q of pod %q, do nothing", container.Name, format.Pod(pod))
|
||||
|
@ -148,6 +148,7 @@ func TestShouldContainerBeRestarted(t *testing.T) {
|
||||
{Name: "alive"},
|
||||
{Name: "succeed"},
|
||||
{Name: "failed"},
|
||||
{Name: "unknown"},
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -175,6 +176,10 @@ func TestShouldContainerBeRestarted(t *testing.T) {
|
||||
State: ContainerStateExited,
|
||||
ExitCode: 2,
|
||||
},
|
||||
{
|
||||
Name: "unknown",
|
||||
State: ContainerStateUnknown,
|
||||
},
|
||||
{
|
||||
Name: "failed",
|
||||
State: ContainerStateExited,
|
||||
@ -192,6 +197,7 @@ func TestShouldContainerBeRestarted(t *testing.T) {
|
||||
"alive": {false, false, false},
|
||||
"succeed": {false, false, true},
|
||||
"failed": {false, true, true},
|
||||
"unknown": {true, true, true},
|
||||
}
|
||||
for _, c := range pod.Spec.Containers {
|
||||
for i, policy := range policies {
|
||||
|
@ -345,6 +345,7 @@ func (dm *DockerManager) inspectContainer(id string, podName, podNamespace strin
|
||||
Hash: hash,
|
||||
}
|
||||
if iResult.State.Running {
|
||||
// Container that are running, restarting and paused
|
||||
status.State = kubecontainer.ContainerStateRunning
|
||||
status.StartedAt = iResult.State.StartedAt
|
||||
if containerName == PodInfraContainerName {
|
||||
@ -355,6 +356,7 @@ func (dm *DockerManager) inspectContainer(id string, podName, podNamespace strin
|
||||
|
||||
// Find containers that have exited or failed to start.
|
||||
if !iResult.State.FinishedAt.IsZero() || iResult.State.ExitCode != 0 {
|
||||
// Containers that are exited, dead or created (docker failed to start container)
|
||||
// When a container fails to start State.ExitCode is non-zero, FinishedAt and StartedAt are both zero
|
||||
reason := ""
|
||||
message := iResult.State.Error
|
||||
@ -394,8 +396,8 @@ func (dm *DockerManager) inspectContainer(id string, podName, podNamespace strin
|
||||
status.StartedAt = startedAt
|
||||
status.FinishedAt = finishedAt
|
||||
} else {
|
||||
// Non-running containers that are not terminatd could be pasued, or created (but not yet
|
||||
// started), etc. Kubelet doesn't handle these scenarios yet.
|
||||
// Non-running containers that are created (not yet started or kubelet failed before calling
|
||||
// start container function etc.) Kubelet doesn't handle these scenarios yet.
|
||||
status.State = kubecontainer.ContainerStateUnknown
|
||||
}
|
||||
return &status, "", nil
|
||||
|
Loading…
Reference in New Issue
Block a user