mirror of https://github.com/k3s-io/k3s
Merge pull request #79483 from yujuhong/automated-cherry-pick-of-#79451-upstream-release-1.14
Automated cherry pick of #79451: kubelet: retry pod sandbox creation when containers werek3s-v1.14.4
commit
55bca275e5
|
@ -477,11 +477,15 @@ func (m *kubeGenericRuntimeManager) computePodActions(pod *v1.Pod, podStatus *ku
|
||||||
// If we need to (re-)create the pod sandbox, everything will need to be
|
// If we need to (re-)create the pod sandbox, everything will need to be
|
||||||
// killed and recreated, and init containers should be purged.
|
// killed and recreated, and init containers should be purged.
|
||||||
if createPodSandbox {
|
if createPodSandbox {
|
||||||
if !shouldRestartOnFailure(pod) && attempt != 0 {
|
if !shouldRestartOnFailure(pod) && attempt != 0 && len(podStatus.ContainerStatuses) != 0 {
|
||||||
// Should not restart the pod, just return.
|
// Should not restart the pod, just return.
|
||||||
// we should not create a sandbox for a pod if it is already done.
|
// we should not create a sandbox for a pod if it is already done.
|
||||||
// if all containers are done and should not be started, there is no need to create a new sandbox.
|
// if all containers are done and should not be started, there is no need to create a new sandbox.
|
||||||
// this stops confusing logs on pods whose containers all have exit codes, but we recreate a sandbox before terminating it.
|
// this stops confusing logs on pods whose containers all have exit codes, but we recreate a sandbox before terminating it.
|
||||||
|
//
|
||||||
|
// If ContainerStatuses is empty, we assume that we've never
|
||||||
|
// successfully created any containers. In this case, we should
|
||||||
|
// retry creating the sandbox.
|
||||||
changes.CreateSandbox = false
|
changes.CreateSandbox = false
|
||||||
return changes
|
return changes
|
||||||
}
|
}
|
||||||
|
|
|
@ -852,6 +852,26 @@ func TestComputePodActions(t *testing.T) {
|
||||||
ContainersToKill: map[kubecontainer.ContainerID]containerToKillInfo{},
|
ContainersToKill: map[kubecontainer.ContainerID]containerToKillInfo{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"Verify we create a pod sandbox if no ready sandbox for pod with RestartPolicy=Never and no containers have ever been created": {
|
||||||
|
mutatePodFn: func(pod *v1.Pod) {
|
||||||
|
pod.Spec.RestartPolicy = v1.RestartPolicyNever
|
||||||
|
},
|
||||||
|
mutateStatusFn: func(status *kubecontainer.PodStatus) {
|
||||||
|
// no ready sandbox
|
||||||
|
status.SandboxStatuses[0].State = runtimeapi.PodSandboxState_SANDBOX_NOTREADY
|
||||||
|
status.SandboxStatuses[0].Metadata.Attempt = uint32(2)
|
||||||
|
// no visible containers
|
||||||
|
status.ContainerStatuses = []*kubecontainer.ContainerStatus{}
|
||||||
|
},
|
||||||
|
actions: podActions{
|
||||||
|
SandboxID: baseStatus.SandboxStatuses[0].Id,
|
||||||
|
Attempt: uint32(3),
|
||||||
|
CreateSandbox: true,
|
||||||
|
KillPod: true,
|
||||||
|
ContainersToStart: []int{0, 1, 2},
|
||||||
|
ContainersToKill: map[kubecontainer.ContainerID]containerToKillInfo{},
|
||||||
|
},
|
||||||
|
},
|
||||||
"Kill and recreate the container if the container is in unknown state": {
|
"Kill and recreate the container if the container is in unknown state": {
|
||||||
mutatePodFn: func(pod *v1.Pod) { pod.Spec.RestartPolicy = v1.RestartPolicyNever },
|
mutatePodFn: func(pod *v1.Pod) { pod.Spec.RestartPolicy = v1.RestartPolicyNever },
|
||||||
mutateStatusFn: func(status *kubecontainer.PodStatus) {
|
mutateStatusFn: func(status *kubecontainer.PodStatus) {
|
||||||
|
@ -1028,6 +1048,36 @@ func TestComputePodActionsWithInitContainers(t *testing.T) {
|
||||||
ContainersToKill: getKillMapWithInitContainers(basePod, baseStatus, []int{}),
|
ContainersToKill: getKillMapWithInitContainers(basePod, baseStatus, []int{}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"Pod sandbox not ready, init container failed, but RestartPolicy == Never; kill pod only": {
|
||||||
|
mutatePodFn: func(pod *v1.Pod) { pod.Spec.RestartPolicy = v1.RestartPolicyNever },
|
||||||
|
mutateStatusFn: func(status *kubecontainer.PodStatus) {
|
||||||
|
status.SandboxStatuses[0].State = runtimeapi.PodSandboxState_SANDBOX_NOTREADY
|
||||||
|
},
|
||||||
|
actions: podActions{
|
||||||
|
KillPod: true,
|
||||||
|
CreateSandbox: false,
|
||||||
|
SandboxID: baseStatus.SandboxStatuses[0].Id,
|
||||||
|
Attempt: uint32(1),
|
||||||
|
ContainersToStart: []int{},
|
||||||
|
ContainersToKill: getKillMapWithInitContainers(basePod, baseStatus, []int{}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Pod sandbox not ready, and RestartPolicy == Never, but no visible init containers; create a new pod sandbox": {
|
||||||
|
mutatePodFn: func(pod *v1.Pod) { pod.Spec.RestartPolicy = v1.RestartPolicyNever },
|
||||||
|
mutateStatusFn: func(status *kubecontainer.PodStatus) {
|
||||||
|
status.SandboxStatuses[0].State = runtimeapi.PodSandboxState_SANDBOX_NOTREADY
|
||||||
|
status.ContainerStatuses = []*kubecontainer.ContainerStatus{}
|
||||||
|
},
|
||||||
|
actions: podActions{
|
||||||
|
KillPod: true,
|
||||||
|
CreateSandbox: true,
|
||||||
|
SandboxID: baseStatus.SandboxStatuses[0].Id,
|
||||||
|
Attempt: uint32(1),
|
||||||
|
NextInitContainerToStart: &basePod.Spec.InitContainers[0],
|
||||||
|
ContainersToStart: []int{},
|
||||||
|
ContainersToKill: getKillMapWithInitContainers(basePod, baseStatus, []int{}),
|
||||||
|
},
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
pod, status := makeBasePodAndStatusWithInitContainers()
|
pod, status := makeBasePodAndStatusWithInitContainers()
|
||||||
if test.mutatePodFn != nil {
|
if test.mutatePodFn != nil {
|
||||||
|
|
Loading…
Reference in New Issue