kubelet: do not cleanup volumes if pod is being killed

This commit is contained in:
Ryan Phillips 2021-04-26 09:46:51 -05:00
parent 19c7089245
commit 1f81b44cc7
2 changed files with 11 additions and 0 deletions

View File

@ -1596,6 +1596,12 @@ func syncAndVerifyPodDir(t *testing.T, testKubelet *TestKubelet, pods []*v1.Pod,
kl.podManager.SetPods(pods)
kl.HandlePodSyncs(pods)
kl.HandlePodCleanups()
// The first time HandlePodCleanups() is run the pod is placed into the
// podKiller, and bypasses the pod directory cleanup. The pod is
// already killed in the second run to HandlePodCleanups() and will
// cleanup the directories.
time.Sleep(2 * time.Second)
kl.HandlePodCleanups()
for i, pod := range podsToCheck {
exist := dirExists(kl.getPodDir(pod.UID))
assert.Equal(t, shouldExist, exist, "directory of pod %d", i)

View File

@ -133,6 +133,11 @@ func (kl *Kubelet) cleanupOrphanedPodDirs(pods []*v1.Pod, runningPods []*kubecon
if allPods.Has(string(uid)) {
continue
}
// if the pod is within termination grace period, we shouldn't cleanup the underlying volumes
if kl.podKiller.IsPodPendingTerminationByUID(uid) {
klog.V(3).InfoS("Pod is pending termination", "podUID", uid)
continue
}
// If volumes have not been unmounted/detached, do not delete directory.
// Doing so may result in corruption of data.
// TODO: getMountedVolumePathListFromDisk() call may be redundant with