Merge pull request #82660 from sallyom/list-pods-dry-run-drain

When running `kubectl drain` in dry-run, list warnings and pods that would be deleted.
This commit is contained in:
Kubernetes Prow Robot 2019-12-05 17:14:50 -08:00 committed by GitHub
commit 646afd52ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View File

@ -289,11 +289,7 @@ func (o *DrainCmdOptions) RunDrain() error {
var fatal error
for _, info := range o.nodeInfos {
var err error
if !o.drainer.DryRun {
err = o.deleteOrEvictPodsSimple(info)
}
if err == nil || o.drainer.DryRun {
if err := o.deleteOrEvictPodsSimple(info); err == nil {
drainedNodes.Insert(info.Name)
printObj(info.Object, o.Out)
} else {
@ -328,6 +324,12 @@ func (o *DrainCmdOptions) deleteOrEvictPodsSimple(nodeInfo *resource.Info) error
if warnings := list.Warnings(); warnings != "" {
fmt.Fprintf(o.ErrOut, "WARNING: %s\n", warnings)
}
if o.drainer.DryRun {
for _, pod := range list.Pods() {
fmt.Fprintf(o.Out, "evicting pod %s/%s (dry run)\n", pod.Namespace, pod.Name)
}
return nil
}
if err := o.drainer.DeleteOrEvictPods(list.Pods()); err != nil {
pendingList, newErrs := o.drainer.GetPodsForDeletion(nodeInfo.Name)

View File

@ -216,7 +216,7 @@ func (d *Helper) evictPods(pods []corev1.Pod, policyGroupVersion string, getPodF
for _, pod := range pods {
go func(pod corev1.Pod, returnCh chan error) {
for {
fmt.Fprintf(d.Out, "evicting pod %q\n", pod.Name)
fmt.Fprintf(d.Out, "evicting pod %s/%s\n", pod.Namespace, pod.Name)
select {
case <-ctx.Done():
// return here or we'll leak a goroutine.