From 1d3d3d5ff12f61f1115be894b313ac143db93140 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Wed, 16 Sep 2020 15:00:12 -0400 Subject: [PATCH] filter volumes by type in 'nomad node status' output (#8902) 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. --- command/node_status.go | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/command/node_status.go b/command/node_status.go index 0fcc2232b0a7..0e3a269b4a58 100644 --- a/command/node_status.go +++ b/command/node_status.go @@ -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" ) @@ -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) @@ -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 { @@ -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))