mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 05:03:09 +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
|
var fatal error
|
||||||
|
|
||||||
for _, info := range o.nodeInfos {
|
for _, info := range o.nodeInfos {
|
||||||
var err error
|
if err := o.deleteOrEvictPodsSimple(info); err == nil {
|
||||||
if !o.drainer.DryRun {
|
|
||||||
err = o.deleteOrEvictPodsSimple(info)
|
|
||||||
}
|
|
||||||
if err == nil || o.drainer.DryRun {
|
|
||||||
drainedNodes.Insert(info.Name)
|
drainedNodes.Insert(info.Name)
|
||||||
printObj(info.Object, o.Out)
|
printObj(info.Object, o.Out)
|
||||||
} else {
|
} else {
|
||||||
@ -328,6 +324,12 @@ func (o *DrainCmdOptions) deleteOrEvictPodsSimple(nodeInfo *resource.Info) error
|
|||||||
if warnings := list.Warnings(); warnings != "" {
|
if warnings := list.Warnings(); warnings != "" {
|
||||||
fmt.Fprintf(o.ErrOut, "WARNING: %s\n", 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 {
|
if err := o.drainer.DeleteOrEvictPods(list.Pods()); err != nil {
|
||||||
pendingList, newErrs := o.drainer.GetPodsForDeletion(nodeInfo.Name)
|
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 {
|
for _, pod := range pods {
|
||||||
go func(pod corev1.Pod, returnCh chan error) {
|
go func(pod corev1.Pod, returnCh chan error) {
|
||||||
for {
|
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 {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
// return here or we'll leak a goroutine.
|
// return here or we'll leak a goroutine.
|
||||||
|
Loading…
Reference in New Issue
Block a user