From 32f05cda4a2109c9eeecf73b9a34e354ef8caff3 Mon Sep 17 00:00:00 2001 From: Yu-Ju Hong Date: Fri, 21 Oct 2016 10:06:19 -0700 Subject: [PATCH] CRI: Handle container/sandbox restarts for pod with RestartPolicy == Never If all sandbox and containers are dead in a pod, and the restart policy is "Never", kubelet should not try to recreate all of them. --- pkg/kubelet/kuberuntime/kuberuntime_manager.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/kubelet/kuberuntime/kuberuntime_manager.go b/pkg/kubelet/kuberuntime/kuberuntime_manager.go index 1e19bc2742..d4bd574db9 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_manager.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_manager.go @@ -471,13 +471,6 @@ func (m *kubeGenericRuntimeManager) computePodContainerChanges(pod *api.Pod, pod // check the status of containers. for index, container := range pod.Spec.Containers { - if sandboxChanged { - message := fmt.Sprintf("Container %+v's pod sandbox is dead, the container will be recreated.", container) - glog.Info(message) - changes.ContainersToStart[index] = message - continue - } - containerStatus := podStatus.FindContainerStatusByName(container.Name) if containerStatus == nil || containerStatus.State != kubecontainer.ContainerStateRunning { if kubecontainer.ShouldContainerBeRestarted(&container, pod, podStatus) { @@ -487,6 +480,14 @@ func (m *kubeGenericRuntimeManager) computePodContainerChanges(pod *api.Pod, pod } continue } + if sandboxChanged { + if pod.Spec.RestartPolicy != api.RestartPolicyNever { + message := fmt.Sprintf("Container %+v's pod sandbox is dead, the container will be recreated.", container) + glog.Info(message) + changes.ContainersToStart[index] = message + } + continue + } if initFailed { // Initialization failed and Container exists.