mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
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:
commit
646afd52ff
@ -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)
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user