Check for sandboxes before deleting the pod from apiserver

This commit is contained in:
Keerthan Reddy,Mala 2020-03-25 14:55:18 -07:00
parent a1dc52efb6
commit aae8a2847a

View File

@ -940,6 +940,24 @@ func (kl *Kubelet) PodResourcesAreReclaimed(pod *v1.Pod, status v1.PodStatus) bo
klog.V(3).Infof("Pod %q is terminated, but some containers have not been cleaned up: %s", format.Pod(pod), statusStr)
return false
}
// pod's sandboxes should be deleted
filter := &runtimeapi.PodSandboxFilter{
LabelSelector: map[string]string{kubetypes.KubernetesPodUIDLabel: string(pod.UID)},
}
sandboxes, err := kl.runtimeService.ListPodSandbox(filter)
if err != nil {
klog.V(3).Infof("Pod %q is terminated, Error getting pod sandboxes from the runtime service: %s", format.Pod(pod), err)
return false
}
if len(sandboxes) > 0 {
var sandboxStr string
for _, sandbox := range sandboxes {
sandboxStr += fmt.Sprintf("%+v ", sandbox)
}
klog.V(3).Infof("Pod %q is terminated, but some pod sandboxes have not been cleaned up: %s", format.Pod(pod), sandboxStr)
return false
}
if kl.podVolumesExist(pod.UID) && !kl.keepTerminatedPodVolumes {
// We shouldn't delete pods whose volumes have not been cleaned up if we are not keeping terminated pod volumes
klog.V(3).Infof("Pod %q is terminated, but some volumes have not been cleaned up", format.Pod(pod))