Skip to content

Commit aae8a28

Browse files
committed
Check for sandboxes before deleting the pod from apiserver
1 parent a1dc52e commit aae8a28

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pkg/kubelet/kubelet_pods.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,24 @@ func (kl *Kubelet) PodResourcesAreReclaimed(pod *v1.Pod, status v1.PodStatus) bo
940940
klog.V(3).Infof("Pod %q is terminated, but some containers have not been cleaned up: %s", format.Pod(pod), statusStr)
941941
return false
942942
}
943+
// pod's sandboxes should be deleted
944+
filter := &runtimeapi.PodSandboxFilter{
945+
LabelSelector: map[string]string{kubetypes.KubernetesPodUIDLabel: string(pod.UID)},
946+
}
947+
sandboxes, err := kl.runtimeService.ListPodSandbox(filter)
948+
if err != nil {
949+
klog.V(3).Infof("Pod %q is terminated, Error getting pod sandboxes from the runtime service: %s", format.Pod(pod), err)
950+
return false
951+
}
952+
if len(sandboxes) > 0 {
953+
var sandboxStr string
954+
for _, sandbox := range sandboxes {
955+
sandboxStr += fmt.Sprintf("%+v ", sandbox)
956+
}
957+
klog.V(3).Infof("Pod %q is terminated, but some pod sandboxes have not been cleaned up: %s", format.Pod(pod), sandboxStr)
958+
return false
959+
}
960+
943961
if kl.podVolumesExist(pod.UID) && !kl.keepTerminatedPodVolumes {
944962
// We shouldn't delete pods whose volumes have not been cleaned up if we are not keeping terminated pod volumes
945963
klog.V(3).Infof("Pod %q is terminated, but some volumes have not been cleaned up", format.Pod(pod))

0 commit comments

Comments
 (0)