Skip to content

Commit cb00630

Browse files
committed
avoid empty volumes output in node status
1 parent 2c9cad2 commit cb00630

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

command/node_status.go

+28-23
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,6 @@ func (c *NodeStatusCommand) outputTruncatedNodeDriverInfo(node *api.Node) string
518518
}
519519

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

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

532-
for _, volName := range names {
533-
info := node.HostVolumes[volName]
534-
output = append(output, fmt.Sprintf("%s|%v|%s", volName, info.ReadOnly, info.Path))
531+
if len(names) > 0 {
532+
c.Ui.Output(c.Colorize().Color("\n[bold]Host Volumes"))
533+
for _, volName := range names {
534+
info := node.HostVolumes[volName]
535+
output = append(output, fmt.Sprintf("%s|%v|%s", volName, info.ReadOnly, info.Path))
536+
}
537+
c.Ui.Output(formatList(output))
535538
}
536-
c.Ui.Output(formatList(output))
537539
}
538540

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

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

572-
// Output the volumes in name order
573-
output := make([]string, 0, len(names)+1)
574-
output = append(output, "ID|Name|Plugin ID|Schedulable|Provider|Access Mode")
575-
for _, name := range names {
576-
v := volumes[name]
577-
output = append(output, fmt.Sprintf(
578-
"%s|%s|%s|%t|%s|%s",
579-
v.ID,
580-
name,
581-
v.PluginID,
582-
v.Schedulable,
583-
v.Provider,
584-
v.AccessMode,
585-
))
586-
}
587-
588-
c.Ui.Output(formatList(output))
573+
if len(names) > 0 {
574+
c.Ui.Output(c.Colorize().Color("\n[bold]CSI Volumes"))
575+
576+
// Output the volumes in name order
577+
output := make([]string, 0, len(names)+1)
578+
output = append(output, "ID|Name|Plugin ID|Schedulable|Provider|Access Mode")
579+
for _, name := range names {
580+
v := volumes[name]
581+
output = append(output, fmt.Sprintf(
582+
"%s|%s|%s|%t|%s|%s",
583+
v.ID,
584+
name,
585+
v.PluginID,
586+
v.Schedulable,
587+
v.Provider,
588+
v.AccessMode,
589+
))
590+
}
591+
592+
c.Ui.Output(formatList(output))
593+
}
589594
}
590595

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

0 commit comments

Comments
 (0)