From 05365d7cb2a5ebe10bec3d53544c2f2ab2bf6997 Mon Sep 17 00:00:00 2001 From: Anirudh Date: Tue, 25 Oct 2016 11:18:58 -0700 Subject: [PATCH] Moving deletion behavior from the NC into PodGC This should be a NOP because we're just moving functionality around and thanks to #35476, the podGC controller should always run anyway. --- pkg/controller/node/controller_utils.go | 11 +-------- pkg/controller/node/nodecontroller_test.go | 4 ++-- pkg/controller/podgc/gc_controller.go | 27 ++++++++++++++++++++-- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/pkg/controller/node/controller_utils.go b/pkg/controller/node/controller_utils.go index 0d7bae3a75e..c237b6bdccc 100644 --- a/pkg/controller/node/controller_utils.go +++ b/pkg/controller/node/controller_utils.go @@ -135,12 +135,6 @@ func (nc *NodeController) maybeDeleteTerminatingPod(obj interface{}) { return } - // delete terminating pods that have not yet been scheduled - if len(pod.Spec.NodeName) == 0 { - utilruntime.HandleError(nc.forcefullyDeletePod(pod)) - return - } - nodeObj, found, err := nc.nodeStore.Store.GetByKey(pod.Spec.NodeName) if err != nil { // this can only happen if the Store.KeyFunc has a problem creating @@ -150,11 +144,8 @@ func (nc *NodeController) maybeDeleteTerminatingPod(obj interface{}) { return } - // delete terminating pods that have been scheduled on - // nonexistent nodes + // if there is no such node, do nothing and let the podGC clean it up. if !found { - glog.Warningf("Unable to find Node: %v, deleting all assigned Pods.", pod.Spec.NodeName) - utilruntime.HandleError(nc.forcefullyDeletePod(pod)) return } diff --git a/pkg/controller/node/nodecontroller_test.go b/pkg/controller/node/nodecontroller_test.go index 8449ccd1919..0e66f142394 100644 --- a/pkg/controller/node/nodecontroller_test.go +++ b/pkg/controller/node/nodecontroller_test.go @@ -1723,14 +1723,14 @@ func TestCheckPod(t *testing.T) { ObjectMeta: api.ObjectMeta{DeletionTimestamp: &unversioned.Time{}}, Spec: api.PodSpec{NodeName: ""}, }, - prune: true, + prune: false, }, { pod: api.Pod{ ObjectMeta: api.ObjectMeta{DeletionTimestamp: &unversioned.Time{}}, Spec: api.PodSpec{NodeName: "nonexistant"}, }, - prune: true, + prune: false, }, } diff --git a/pkg/controller/podgc/gc_controller.go b/pkg/controller/podgc/gc_controller.go index f640e1d856a..27bad9ce617 100644 --- a/pkg/controller/podgc/gc_controller.go +++ b/pkg/controller/podgc/gc_controller.go @@ -125,6 +125,7 @@ func (gcc *PodGCController) gc() { gcc.gcTerminated(pods) } gcc.gcOrphaned(pods) + gcc.gcUnscheduledTerminating(pods) } func isPodTerminated(pod *api.Pod) bool { @@ -168,7 +169,7 @@ func (gcc *PodGCController) gcTerminated(pods []*api.Pod) { wait.Wait() } -// cleanupOrphanedPods deletes pods that are bound to nodes that don't exist. +// gcOrphaned deletes pods that are bound to nodes that don't exist. func (gcc *PodGCController) gcOrphaned(pods []*api.Pod) { glog.V(4).Infof("GC'ing orphaned") @@ -183,7 +184,29 @@ func (gcc *PodGCController) gcOrphaned(pods []*api.Pod) { if err := gcc.deletePod(pod.Namespace, pod.Name); err != nil { utilruntime.HandleError(err) } else { - glog.V(4).Infof("Forced deletion of oprhaned Pod %s succeeded", pod.Name) + glog.V(4).Infof("Forced deletion of orphaned Pod %s succeeded", pod.Name) + } + } +} + +// gcUnscheduledTerminating deletes pods that are terminating and haven't been scheduled to a particular node. +func (gcc *PodGCController) gcUnscheduledTerminating(pods []*api.Pod) { + glog.V(4).Infof("GC'ing unscheduled pods which are terminating.") + + for _, pod := range pods { + if pod.DeletionTimestamp == nil { + continue + } + + if len(pod.Spec.NodeName) > 0 { + continue + } + + glog.V(2).Infof("Found unscheduled terminating Pod %v not assigned to any Node. Deleting.", pod.Name) + if err := gcc.deletePod(pod.Namespace, pod.Name); err != nil { + utilruntime.HandleError(err) + } else { + glog.V(4).Infof("Forced deletion of unscheduled terminating Pod %s succeeded", pod.Name) } } }