From b6318d4e5b9b8eb0d2e2d5a8568df14817733f26 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 7 Feb 2023 13:10:30 -0800 Subject: [PATCH] kubectl/pkg/drain: Include namespace in evictPods return error And also in the terminating-namespace log output. This makes it easier to track down drain-blocking pods, without having to hunt around in earlier logs for 'evicting pod ...' messages. Before this change, caller logs might look like: evicting pod {namespace}/{name} ... error when waiting for pod "{name}" terminating: global timeout reached: 20s With this change, they will look like: evicting pod {namespace}/{name} ... error when waiting for pod "{name}" in namespace "{namespace}" to terminate: global timeout reached: 20s --- staging/src/k8s.io/kubectl/pkg/drain/drain.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/staging/src/k8s.io/kubectl/pkg/drain/drain.go b/staging/src/k8s.io/kubectl/pkg/drain/drain.go index ccb4c8b4652..5a5c9f44d52 100644 --- a/staging/src/k8s.io/kubectl/pkg/drain/drain.go +++ b/staging/src/k8s.io/kubectl/pkg/drain/drain.go @@ -315,7 +315,7 @@ func (d *Helper) evictPods(pods []corev1.Pod, evictionGroupVersion schema.GroupV } else if apierrors.IsForbidden(err) && apierrors.HasStatusCause(err, corev1.NamespaceTerminatingCause) { // an eviction request in a deleting namespace will throw a forbidden error, // if the pod is not marked deleted, we retry until it is. - fmt.Fprintf(d.ErrOut, "error when evicting pod %q (will retry after 5s): %v\n", activePod.Name, err) + fmt.Fprintf(d.ErrOut, "error when evicting pod %q from terminating namespace %q (will retry after 5s): %v\n", activePod.Name, activePod.Namespace, err) time.Sleep(5 * time.Second) } else { returnCh <- fmt.Errorf("error when evicting pods/%q -n %q: %v", activePod.Name, activePod.Namespace, err) @@ -342,7 +342,7 @@ func (d *Helper) evictPods(pods []corev1.Pod, evictionGroupVersion schema.GroupV if err == nil { returnCh <- nil } else { - returnCh <- fmt.Errorf("error when waiting for pod %q terminating: %v", pod.Name, err) + returnCh <- fmt.Errorf("error when waiting for pod %q in namespace %q to terminate: %v", pod.Name, pod.Namespace, err) } }(pod, returnCh) }