mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #101524 from rphillips/add_sync_to_killpod_2
kubelet: do not cleanup volumes if pod is being killed
This commit is contained in:
commit
2b8a7809b4
@ -119,7 +119,9 @@ type TestKubelet struct {
|
|||||||
|
|
||||||
func (tk *TestKubelet) Cleanup() {
|
func (tk *TestKubelet) Cleanup() {
|
||||||
if tk.kubelet != nil {
|
if tk.kubelet != nil {
|
||||||
|
tk.kubelet.podKiller.Close()
|
||||||
os.RemoveAll(tk.kubelet.rootDirectory)
|
os.RemoveAll(tk.kubelet.rootDirectory)
|
||||||
|
tk.kubelet = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,6 +294,7 @@ func newTestKubeletWithImageList(
|
|||||||
kubelet.backOff = flowcontrol.NewBackOff(time.Second, time.Minute)
|
kubelet.backOff = flowcontrol.NewBackOff(time.Second, time.Minute)
|
||||||
kubelet.backOff.Clock = fakeClock
|
kubelet.backOff.Clock = fakeClock
|
||||||
kubelet.podKiller = NewPodKiller(kubelet)
|
kubelet.podKiller = NewPodKiller(kubelet)
|
||||||
|
go kubelet.podKiller.PerformPodKillingWork()
|
||||||
kubelet.resyncInterval = 10 * time.Second
|
kubelet.resyncInterval = 10 * time.Second
|
||||||
kubelet.workQueue = queue.NewBasicWorkQueue(fakeClock)
|
kubelet.workQueue = queue.NewBasicWorkQueue(fakeClock)
|
||||||
// Relist period does not affect the tests.
|
// Relist period does not affect the tests.
|
||||||
@ -420,9 +423,7 @@ func TestSyncPodsStartPod(t *testing.T) {
|
|||||||
|
|
||||||
func TestHandlePodCleanupsPerQOS(t *testing.T) {
|
func TestHandlePodCleanupsPerQOS(t *testing.T) {
|
||||||
testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */)
|
testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */)
|
||||||
go testKubelet.kubelet.podKiller.PerformPodKillingWork()
|
|
||||||
defer testKubelet.Cleanup()
|
defer testKubelet.Cleanup()
|
||||||
defer testKubelet.kubelet.podKiller.Close()
|
|
||||||
|
|
||||||
pod := &kubecontainer.Pod{
|
pod := &kubecontainer.Pod{
|
||||||
ID: "12345678",
|
ID: "12345678",
|
||||||
@ -612,9 +613,7 @@ func TestDispatchWorkOfActivePod(t *testing.T) {
|
|||||||
|
|
||||||
func TestHandlePodCleanups(t *testing.T) {
|
func TestHandlePodCleanups(t *testing.T) {
|
||||||
testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */)
|
testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */)
|
||||||
go testKubelet.kubelet.podKiller.PerformPodKillingWork()
|
|
||||||
defer testKubelet.Cleanup()
|
defer testKubelet.Cleanup()
|
||||||
defer testKubelet.kubelet.podKiller.Close()
|
|
||||||
|
|
||||||
pod := &kubecontainer.Pod{
|
pod := &kubecontainer.Pod{
|
||||||
ID: "12345678",
|
ID: "12345678",
|
||||||
@ -643,8 +642,6 @@ func TestHandlePodRemovesWhenSourcesAreReady(t *testing.T) {
|
|||||||
|
|
||||||
testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */)
|
testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */)
|
||||||
defer testKubelet.Cleanup()
|
defer testKubelet.Cleanup()
|
||||||
go testKubelet.kubelet.podKiller.PerformPodKillingWork()
|
|
||||||
defer testKubelet.kubelet.podKiller.Close()
|
|
||||||
|
|
||||||
fakePod := &kubecontainer.Pod{
|
fakePod := &kubecontainer.Pod{
|
||||||
ID: "1",
|
ID: "1",
|
||||||
@ -683,8 +680,6 @@ func TestHandlePodRemovesWhenSourcesAreReady(t *testing.T) {
|
|||||||
func TestKillPodFollwedByIsPodPendingTermination(t *testing.T) {
|
func TestKillPodFollwedByIsPodPendingTermination(t *testing.T) {
|
||||||
testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */)
|
testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */)
|
||||||
defer testKubelet.Cleanup()
|
defer testKubelet.Cleanup()
|
||||||
defer testKubelet.kubelet.podKiller.Close()
|
|
||||||
go testKubelet.kubelet.podKiller.PerformPodKillingWork()
|
|
||||||
|
|
||||||
pod := &kubecontainer.Pod{
|
pod := &kubecontainer.Pod{
|
||||||
ID: "12345678",
|
ID: "12345678",
|
||||||
@ -1596,6 +1591,12 @@ func syncAndVerifyPodDir(t *testing.T, testKubelet *TestKubelet, pods []*v1.Pod,
|
|||||||
kl.podManager.SetPods(pods)
|
kl.podManager.SetPods(pods)
|
||||||
kl.HandlePodSyncs(pods)
|
kl.HandlePodSyncs(pods)
|
||||||
kl.HandlePodCleanups()
|
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 {
|
for i, pod := range podsToCheck {
|
||||||
exist := dirExists(kl.getPodDir(pod.UID))
|
exist := dirExists(kl.getPodDir(pod.UID))
|
||||||
assert.Equal(t, shouldExist, exist, "directory of pod %d", i)
|
assert.Equal(t, shouldExist, exist, "directory of pod %d", i)
|
||||||
|
@ -133,6 +133,11 @@ func (kl *Kubelet) cleanupOrphanedPodDirs(pods []*v1.Pod, runningPods []*kubecon
|
|||||||
if allPods.Has(string(uid)) {
|
if allPods.Has(string(uid)) {
|
||||||
continue
|
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.
|
// If volumes have not been unmounted/detached, do not delete directory.
|
||||||
// Doing so may result in corruption of data.
|
// Doing so may result in corruption of data.
|
||||||
// TODO: getMountedVolumePathListFromDisk() call may be redundant with
|
// TODO: getMountedVolumePathListFromDisk() call may be redundant with
|
||||||
|
Loading…
Reference in New Issue
Block a user