Skip to content

Commit

Permalink
avoid empty volumes output in node status
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross committed Jul 23, 2020
1 parent 2c9cad2 commit cb00630
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions command/node_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,6 @@ func (c *NodeStatusCommand) outputTruncatedNodeDriverInfo(node *api.Node) string
}

func (c *NodeStatusCommand) outputNodeVolumeInfo(node *api.Node) {
c.Ui.Output(c.Colorize().Color("\n[bold]Host Volumes"))

names := make([]string, 0, len(node.HostVolumes))
for name := range node.HostVolumes {
Expand All @@ -529,15 +528,17 @@ func (c *NodeStatusCommand) outputNodeVolumeInfo(node *api.Node) {
output := make([]string, 0, len(names)+1)
output = append(output, "Name|ReadOnly|Source")

for _, volName := range names {
info := node.HostVolumes[volName]
output = append(output, fmt.Sprintf("%s|%v|%s", volName, info.ReadOnly, info.Path))
if len(names) > 0 {
c.Ui.Output(c.Colorize().Color("\n[bold]Host Volumes"))
for _, volName := range names {
info := node.HostVolumes[volName]
output = append(output, fmt.Sprintf("%s|%v|%s", volName, info.ReadOnly, info.Path))
}
c.Ui.Output(formatList(output))
}
c.Ui.Output(formatList(output))
}

func (c *NodeStatusCommand) outputNodeCSIVolumeInfo(client *api.Client, node *api.Node, runningAllocs []*api.Allocation) {
c.Ui.Output(c.Colorize().Color("\n[bold]CSI Volumes"))

// Duplicate nodeCSIVolumeNames to sort by name but also index volume names to ids
var names []string
Expand Down Expand Up @@ -569,23 +570,27 @@ func (c *NodeStatusCommand) outputNodeCSIVolumeInfo(client *api.Client, node *ap
}
}

// Output the volumes in name order
output := make([]string, 0, len(names)+1)
output = append(output, "ID|Name|Plugin ID|Schedulable|Provider|Access Mode")
for _, name := range names {
v := volumes[name]
output = append(output, fmt.Sprintf(
"%s|%s|%s|%t|%s|%s",
v.ID,
name,
v.PluginID,
v.Schedulable,
v.Provider,
v.AccessMode,
))
}

c.Ui.Output(formatList(output))
if len(names) > 0 {
c.Ui.Output(c.Colorize().Color("\n[bold]CSI Volumes"))

// Output the volumes in name order
output := make([]string, 0, len(names)+1)
output = append(output, "ID|Name|Plugin ID|Schedulable|Provider|Access Mode")
for _, name := range names {
v := volumes[name]
output = append(output, fmt.Sprintf(
"%s|%s|%s|%t|%s|%s",
v.ID,
name,
v.PluginID,
v.Schedulable,
v.Provider,
v.AccessMode,
))
}

c.Ui.Output(formatList(output))
}
}

func (c *NodeStatusCommand) outputNodeDriverInfo(node *api.Node) {
Expand Down

0 comments on commit cb00630

Please sign in to comment.