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