mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-09 21:21:14 +00:00
Merge pull request #126420 from hoskeri/fix-container-succeeded-check-status
kuberuntime_manager: fix container success check.
This commit is contained in:
@@ -534,10 +534,11 @@ func shouldRestartOnFailure(pod *v1.Pod) bool {
|
||||
|
||||
func containerSucceeded(c *v1.Container, podStatus *kubecontainer.PodStatus) bool {
|
||||
cStatus := podStatus.FindContainerStatusByName(c.Name)
|
||||
if cStatus == nil || cStatus.State == kubecontainer.ContainerStateRunning {
|
||||
if cStatus == nil {
|
||||
return false
|
||||
}
|
||||
return cStatus.ExitCode == 0
|
||||
// Container has exited, with an exit code of 0.
|
||||
return cStatus.State == kubecontainer.ContainerStateExited && cStatus.ExitCode == 0
|
||||
}
|
||||
|
||||
func isInPlacePodVerticalScalingAllowed(pod *v1.Pod) bool {
|
||||
|
@@ -995,6 +995,22 @@ func TestComputePodActions(t *testing.T) {
|
||||
ContainersToKill: getKillMap(basePod, baseStatus, []int{}),
|
||||
},
|
||||
},
|
||||
"restart created but not started containers if RestartPolicy == OnFailure": {
|
||||
mutatePodFn: func(pod *v1.Pod) { pod.Spec.RestartPolicy = v1.RestartPolicyOnFailure },
|
||||
mutateStatusFn: func(status *kubecontainer.PodStatus) {
|
||||
// The first container completed, don't restart it.
|
||||
status.ContainerStatuses[0].State = kubecontainer.ContainerStateExited
|
||||
status.ContainerStatuses[0].ExitCode = 0
|
||||
|
||||
// The second container was created, but never started.
|
||||
status.ContainerStatuses[1].State = kubecontainer.ContainerStateCreated
|
||||
},
|
||||
actions: podActions{
|
||||
SandboxID: baseStatus.SandboxStatuses[0].Id,
|
||||
ContainersToStart: []int{1},
|
||||
ContainersToKill: getKillMap(basePod, baseStatus, []int{}),
|
||||
},
|
||||
},
|
||||
"don't restart containers if RestartPolicy == Never": {
|
||||
mutatePodFn: func(pod *v1.Pod) { pod.Spec.RestartPolicy = v1.RestartPolicyNever },
|
||||
mutateStatusFn: func(status *kubecontainer.PodStatus) {
|
||||
|
Reference in New Issue
Block a user