Skip to content

Commit 5468a46

Browse files
author
OpenShift Bot
authored
Merge pull request #12528 from juanvallejo/jvallejo/improve-oadm-manage-node-output
Merged by openshift-bot
2 parents 561ef98 + 81f37bd commit 5468a46

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

pkg/cmd/admin/node/evacuate.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ type EvacuateOptions struct {
2727
DryRun bool
2828
Force bool
2929
GracePeriod int64
30+
31+
printPodHeaders bool
3032
}
3133

3234
// NewEvacuateOptions creates a new EvacuateOptions with default values.
@@ -36,6 +38,8 @@ func NewEvacuateOptions(nodeOptions *NodeOptions) *EvacuateOptions {
3638
DryRun: false,
3739
Force: false,
3840
GracePeriod: 30,
41+
42+
printPodHeaders: true,
3943
}
4044
}
4145

@@ -49,6 +53,11 @@ func (e *EvacuateOptions) AddFlags(cmd *cobra.Command) {
4953
}
5054

5155
func (e *EvacuateOptions) Run() error {
56+
if e.DryRun {
57+
listpodsOp := ListPodsOptions{Options: e.Options, printPodHeaders: e.printPodHeaders}
58+
return listpodsOp.Run()
59+
}
60+
5261
nodes, err := e.Options.GetNodes()
5362
if err != nil {
5463
return err
@@ -66,11 +75,6 @@ func (e *EvacuateOptions) Run() error {
6675
}
6776

6877
func (e *EvacuateOptions) RunEvacuate(node *kapi.Node) error {
69-
if e.DryRun {
70-
listpodsOp := ListPodsOptions{Options: e.Options}
71-
return listpodsOp.Run()
72-
}
73-
7478
// We do *not* automatically mark the node unschedulable to perform evacuation.
7579
// Rationale: If we unschedule the node and later the operation is unsuccessful (stopped by user, network error, etc.),
7680
// we may not be able to recover in some cases to mark the node back to schedulable. To avoid these cases, we recommend

pkg/cmd/admin/node/listpods.go

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717

1818
type ListPodsOptions struct {
1919
Options *NodeOptions
20+
21+
printPodHeaders bool
2022
}
2123

2224
func (l *ListPodsOptions) AddFlags(cmd *cobra.Command) {
@@ -71,6 +73,14 @@ func (l *ListPodsOptions) runListPods(node *kapi.Node, printer kprinters.Resourc
7173
}
7274

7375
fmt.Fprint(l.Options.ErrWriter, "\nListing matched pods on node: ", node.ObjectMeta.Name, "\n\n")
76+
if p, ok := printer.(*kprinters.HumanReadablePrinter); ok {
77+
if l.printPodHeaders {
78+
p.EnsurePrintHeaders()
79+
}
80+
p.PrintObj(pods, l.Options.Writer)
81+
return err
82+
}
83+
7484
printer.PrintObj(pods, l.Options.Writer)
7585

7686
return err

pkg/cmd/admin/node/node.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func NewCommandManageNode(f *clientcmd.Factory, commandName, fullName string, ou
5858
opts := &NodeOptions{}
5959
schedulableOp := &SchedulableOptions{Options: opts}
6060
evacuateOp := NewEvacuateOptions(opts)
61-
listpodsOp := &ListPodsOptions{Options: opts}
61+
listpodsOp := &ListPodsOptions{Options: opts, printPodHeaders: true}
6262

6363
cmd := &cobra.Command{
6464
Use: commandName,
@@ -91,8 +91,10 @@ func NewCommandManageNode(f *clientcmd.Factory, commandName, fullName string, ou
9191
schedulableOp.Schedulable = schedulable
9292
err = schedulableOp.Run()
9393
} else if evacuate {
94+
evacuateOp.printPodHeaders = !kcmdutil.GetFlagBool(c, "no-headers")
9495
err = evacuateOp.Run()
9596
} else if listpods {
97+
listpodsOp.printPodHeaders = !kcmdutil.GetFlagBool(c, "no-headers")
9698
err = listpodsOp.Run()
9799
}
98100
kcmdutil.CheckErr(err)

0 commit comments

Comments
 (0)