From 8f74c8970bb891b0487514d456e337c5afe16837 Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Sun, 20 Oct 2019 16:24:59 -0400 Subject: [PATCH] daemonset: Ignore namespace termination errors when creating pods Instead of reporting an event or displaying an error, simply exit when the namespace is being terminated. This reduces the amount of controller churn on namespace shutdown. While we could technically exit the entire processing loop early for very large daemon sets, we should wait for more evidence that is an issue before changing that logic substantially. --- pkg/controller/daemon/daemon_controller.go | 25 ++++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/pkg/controller/daemon/daemon_controller.go b/pkg/controller/daemon/daemon_controller.go index bac4ddc4c20..2d42a2020a3 100644 --- a/pkg/controller/daemon/daemon_controller.go +++ b/pkg/controller/daemon/daemon_controller.go @@ -1053,15 +1053,22 @@ func (dsc *DaemonSetsController) syncNodes(ds *apps.DaemonSet, podsToDelete, nod ds, metav1.NewControllerRef(ds, controllerKind)) } - if err != nil && errors.IsTimeout(err) { - // Pod is created but its initialization has timed out. - // If the initialization is successful eventually, the - // controller will observe the creation via the informer. - // If the initialization fails, or if the pod keeps - // uninitialized for a long time, the informer will not - // receive any update, and the controller will create a new - // pod when the expectation expires. - return + if err != nil { + if errors.HasStatusCause(err, v1.NamespaceTerminatingCause) { + // If the namespace is being torn down, we can safely ignore + // this error since all subsequent creations will fail. + return + } + if errors.IsTimeout(err) { + // Pod is created but its initialization has timed out. + // If the initialization is successful eventually, the + // controller will observe the creation via the informer. + // If the initialization fails, or if the pod keeps + // uninitialized for a long time, the informer will not + // receive any update, and the controller will create a new + // pod when the expectation expires. + return + } } if err != nil { klog.V(2).Infof("Failed creation, decrementing expectations for set %q/%q", ds.Namespace, ds.Name)