Skip to content

Commit

Permalink
filter volumes by type in 'nomad node status' output
Browse files Browse the repository at this point in the history
Volume requests can be either CSI or host volumes, so when displaying the CSI
volume info for `nomad node status -verbose` we need to filter out the host
volumes.
  • Loading branch information
tgross committed Sep 16, 2020
1 parent 679fee9 commit 91c799b
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions command/node_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/nomad/api"
"github.com/hashicorp/nomad/api/contexts"
"github.com/hashicorp/nomad/helper"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/posener/complete"
)

Expand Down Expand Up @@ -326,7 +327,9 @@ func nodeCSIVolumeNames(n *api.Node, allocs []*api.Allocation) []string {
}

for _, v := range tg.Volumes {
names = append(names, v.Name)
if v.Type == structs.VolumeTypeCSI {
names = append(names, v.Name)
}
}
}
sort.Strings(names)
Expand Down Expand Up @@ -550,8 +553,10 @@ func (c *NodeStatusCommand) outputNodeCSIVolumeInfo(client *api.Client, node *ap
}

for _, v := range tg.Volumes {
names = append(names, v.Name)
requests[v.Source] = v
if v.Type == structs.VolumeTypeCSI {
names = append(names, v.Name)
requests[v.Source] = v
}
}
}
if len(names) == 0 {
Expand All @@ -577,16 +582,18 @@ func (c *NodeStatusCommand) outputNodeCSIVolumeInfo(client *api.Client, node *ap
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,
))
v, ok := volumes[name]
if ok {
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))
Expand Down

0 comments on commit 91c799b

Please sign in to comment.