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,9 +327,11 @@ func nodeCSIVolumeNames(n *api.Node, allocs []*api.Allocation) []string {
} }
for _, v := range tg.Volumes { for _, v := range tg.Volumes {
if v.Type == structs.VolumeTypeCSI {
names = append(names, v.Name) names = append(names, v.Name)
} }
} }
}
sort.Strings(names) sort.Strings(names)
return names return names
} }
@ -550,10 +553,12 @@ func (c *NodeStatusCommand) outputNodeCSIVolumeInfo(client *api.Client, node *ap
} }
for _, v := range tg.Volumes { for _, v := range tg.Volumes {
if v.Type == structs.VolumeTypeCSI {
names = append(names, v.Name) names = append(names, v.Name)
requests[v.Source] = v requests[v.Source] = v
} }
} }
}
if len(names) == 0 { if len(names) == 0 {
return return
} }
@ -577,7 +582,8 @@ 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]
if ok {
output = append(output, fmt.Sprintf( output = append(output, fmt.Sprintf(
"%s|%s|%s|%t|%s|%s", "%s|%s|%s|%t|%s|%s",
v.ID, v.ID,
@ -588,6 +594,7 @@ func (c *NodeStatusCommand) outputNodeCSIVolumeInfo(client *api.Client, node *ap
v.AccessMode, v.AccessMode,
)) ))
} }
}
c.Ui.Output(formatList(output)) c.Ui.Output(formatList(output))
} }