From c8d02f703bd99fb580a2bc4b49a4870fa16f9fe8 Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Fri, 13 Nov 2020 10:35:54 -0600 Subject: [PATCH] kubelet: do not rerun init containers if any main containers have status --- pkg/kubelet/kuberuntime/kuberuntime_container.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/kubelet/kuberuntime/kuberuntime_container.go b/pkg/kubelet/kuberuntime/kuberuntime_container.go index 30f8c6d7ae6..4df83e48f67 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_container.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_container.go @@ -744,6 +744,18 @@ func findNextInitContainerToRun(pod *v1.Pod, podStatus *kubecontainer.PodStatus) return nil, nil, true } + // If any of the main containers have status and are Running, then all init containers must + // have been executed at some point in the past. However, they could have been removed + // from the container runtime now, and if we proceed, it would appear as if they + // never ran and will re-execute improperly. + for i := range pod.Spec.Containers { + container := &pod.Spec.Containers[i] + status := podStatus.FindContainerStatusByName(container.Name) + if status != nil && status.State == kubecontainer.ContainerStateRunning { + return nil, nil, true + } + } + // If there are failed containers, return the status of the last failed one. for i := len(pod.Spec.InitContainers) - 1; i >= 0; i-- { container := &pod.Spec.InitContainers[i]