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
This commit is contained in:
W. Trevor King 2023-02-07 13:10:30 -08:00
parent e4c8802407
commit b6318d4e5b

View File

@ -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)
}