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.
This commit is contained in:
Tim Gross 2020-09-16 15:00:12 -04:00 committed by GitHub
parent f5700611c0
commit 7a691d0000
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 13 deletions

View File

@ -12,6 +12,7 @@ import (
"github.com/hashicorp/nomad/api" "github.com/hashicorp/nomad/api"
"github.com/hashicorp/nomad/api/contexts" "github.com/hashicorp/nomad/api/contexts"
"github.com/hashicorp/nomad/helper" "github.com/hashicorp/nomad/helper"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/posener/complete" "github.com/posener/complete"
) )
@ -326,7 +327,9 @@ func nodeCSIVolumeNames(n *api.Node, allocs []*api.Allocation) []string {
} }
for _, v := range tg.Volumes { for _, v := range tg.Volumes {
names = append(names, v.Name) if v.Type == structs.VolumeTypeCSI {
names = append(names, v.Name)
}
} }
} }
sort.Strings(names) sort.Strings(names)
@ -550,8 +553,10 @@ func (c *NodeStatusCommand) outputNodeCSIVolumeInfo(client *api.Client, node *ap
} }
for _, v := range tg.Volumes { for _, v := range tg.Volumes {
names = append(names, v.Name) if v.Type == structs.VolumeTypeCSI {
requests[v.Source] = v names = append(names, v.Name)
requests[v.Source] = v
}
} }
} }
if len(names) == 0 { 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 := make([]string, 0, len(names)+1)
output = append(output, "ID|Name|Plugin ID|Schedulable|Provider|Access Mode") output = append(output, "ID|Name|Plugin ID|Schedulable|Provider|Access Mode")
for _, name := range names { for _, name := range names {
v := volumes[name] v, ok := volumes[name]
output = append(output, fmt.Sprintf( if ok {
"%s|%s|%s|%t|%s|%s", output = append(output, fmt.Sprintf(
v.ID, "%s|%s|%s|%t|%s|%s",
name, v.ID,
v.PluginID, name,
v.Schedulable, v.PluginID,
v.Provider, v.Schedulable,
v.AccessMode, v.Provider,
)) v.AccessMode,
))
}
} }
c.Ui.Output(formatList(output)) c.Ui.Output(formatList(output))