Skip to content

Commit

Permalink
Merge pull request #12528 from juanvallejo/jvallejo/improve-oadm-mana…
Browse files Browse the repository at this point in the history
…ge-node-output

Merged by openshift-bot
  • Loading branch information
OpenShift Bot authored May 8, 2017
2 parents 561ef98 + 81f37bd commit 5468a46
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
14 changes: 9 additions & 5 deletions pkg/cmd/admin/node/evacuate.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type EvacuateOptions struct {
DryRun bool
Force bool
GracePeriod int64

printPodHeaders bool
}

// NewEvacuateOptions creates a new EvacuateOptions with default values.
Expand All @@ -36,6 +38,8 @@ func NewEvacuateOptions(nodeOptions *NodeOptions) *EvacuateOptions {
DryRun: false,
Force: false,
GracePeriod: 30,

printPodHeaders: true,
}
}

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

func (e *EvacuateOptions) Run() error {
if e.DryRun {
listpodsOp := ListPodsOptions{Options: e.Options, printPodHeaders: e.printPodHeaders}
return listpodsOp.Run()
}

nodes, err := e.Options.GetNodes()
if err != nil {
return err
Expand All @@ -66,11 +75,6 @@ func (e *EvacuateOptions) Run() error {
}

func (e *EvacuateOptions) RunEvacuate(node *kapi.Node) error {
if e.DryRun {
listpodsOp := ListPodsOptions{Options: e.Options}
return listpodsOp.Run()
}

// We do *not* automatically mark the node unschedulable to perform evacuation.
// Rationale: If we unschedule the node and later the operation is unsuccessful (stopped by user, network error, etc.),
// we may not be able to recover in some cases to mark the node back to schedulable. To avoid these cases, we recommend
Expand Down
10 changes: 10 additions & 0 deletions pkg/cmd/admin/node/listpods.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (

type ListPodsOptions struct {
Options *NodeOptions

printPodHeaders bool
}

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

fmt.Fprint(l.Options.ErrWriter, "\nListing matched pods on node: ", node.ObjectMeta.Name, "\n\n")
if p, ok := printer.(*kprinters.HumanReadablePrinter); ok {
if l.printPodHeaders {
p.EnsurePrintHeaders()
}
p.PrintObj(pods, l.Options.Writer)
return err
}

printer.PrintObj(pods, l.Options.Writer)

return err
Expand Down
4 changes: 3 additions & 1 deletion pkg/cmd/admin/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewCommandManageNode(f *clientcmd.Factory, commandName, fullName string, ou
opts := &NodeOptions{}
schedulableOp := &SchedulableOptions{Options: opts}
evacuateOp := NewEvacuateOptions(opts)
listpodsOp := &ListPodsOptions{Options: opts}
listpodsOp := &ListPodsOptions{Options: opts, printPodHeaders: true}

cmd := &cobra.Command{
Use: commandName,
Expand Down Expand Up @@ -91,8 +91,10 @@ func NewCommandManageNode(f *clientcmd.Factory, commandName, fullName string, ou
schedulableOp.Schedulable = schedulable
err = schedulableOp.Run()
} else if evacuate {
evacuateOp.printPodHeaders = !kcmdutil.GetFlagBool(c, "no-headers")
err = evacuateOp.Run()
} else if listpods {
listpodsOp.printPodHeaders = !kcmdutil.GetFlagBool(c, "no-headers")
err = listpodsOp.Run()
}
kcmdutil.CheckErr(err)
Expand Down

0 comments on commit 5468a46

Please sign in to comment.