Skip to content

Commit

Permalink
Merge pull request #481 from sjenning/dont-rerun-init-ocp-master
Browse files Browse the repository at this point in the history
Bug 1770017: kubelet: do not rerun init containers if any main containers have status
  • Loading branch information
openshift-merge-robot committed Dec 13, 2020
2 parents 8ed9339 + e46dd8a commit e386040
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/kubelet/kuberuntime/kuberuntime_container.go
Expand Up @@ -742,6 +742,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]
Expand Down

0 comments on commit e386040

Please sign in to comment.