diff --git a/pkg/kubelet/kuberuntime/kuberuntime_container.go b/pkg/kubelet/kuberuntime/kuberuntime_container.go index 433659a39d6e3..b8f9f07efb6cf 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_container.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_container.go @@ -595,8 +595,15 @@ func (m *kubeGenericRuntimeManager) killContainer(pod *v1.Pod, containerID kubec var containerSpec *v1.Container if pod != nil { if containerSpec = kubecontainer.GetContainerSpec(pod, containerName); containerSpec == nil { - return fmt.Errorf("failed to get containerSpec %q(id=%q) in pod %q when killing container for reason %q", - containerName, containerID.String(), format.Pod(pod), message) + // after a kubelet restart, it's not 100% certain that the + // pod we're given has the container we need in the spec + // -- we try to recover that here. + restoredPod, restoredContainer, err := m.restoreSpecsFromContainerLabels(containerID) + if err != nil { + return fmt.Errorf("failed to get containerSpec %q(id=%q) in pod %q when killing container for reason %q. error: %v", + containerName, containerID.String(), format.Pod(pod), reason, err) + } + pod, containerSpec = restoredPod, restoredContainer } } else { // Restore necessary information if one of the specs is nil.