Skip to content

Commit

Permalink
pkg/kubelet: try restoring the container spec if its nil
Browse files Browse the repository at this point in the history
We're not guaranteed that the pod passed in has the ContainerSpec
we're looking for. With this, we check if the pod has the container
spec, and if it doesn't, we try to recover it one more time.

Datadog: **NOT FROM UPSTREAM K8S**. From Lyft: lyft@612f24c
  • Loading branch information
tomwans authored and bpineau committed Aug 28, 2020
1 parent 3509e1d commit d83ce4f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/kubelet/kuberuntime/kuberuntime_container.go
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit d83ce4f

Please sign in to comment.