CSI: handle per-alloc volumes in `alloc status -verbose` CLI (#12573)

The Nomad client's `csi_hook` interpolates the alloc suffix with the
volume request's name for CSI volumes with `per_alloc = true`, turning
`example` into `example[1]`. We need to do this same behavior in the
`alloc status` output so that we show the correct volume.
This commit is contained in:
Tim Gross 2022-04-15 09:26:19 -04:00 committed by GitHub
parent e8b0b91418
commit f5d8c636c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

3
.changelog/12573.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
csi: Fixed a bug where per-alloc volumes used the incorrect ID when querying for `alloc status -verbose`
```

View File

@ -826,9 +826,14 @@ FOUND:
fmt.Sprintf("%s|%v", volReq.Name, *volMount.ReadOnly)) fmt.Sprintf("%s|%v", volReq.Name, *volMount.ReadOnly))
case structs.VolumeTypeCSI: case structs.VolumeTypeCSI:
if verbose { if verbose {
source := volReq.Source
if volReq.PerAlloc {
source = source + structs.AllocSuffix(alloc.Name)
}
// there's an extra API call per volume here so we toggle it // there's an extra API call per volume here so we toggle it
// off with the -verbose flag // off with the -verbose flag
vol, _, err := client.CSIVolumes().Info(volReq.Source, nil) vol, _, err := client.CSIVolumes().Info(source, nil)
if err != nil { if err != nil {
c.Ui.Error(fmt.Sprintf("Error retrieving volume info for %q: %s", c.Ui.Error(fmt.Sprintf("Error retrieving volume info for %q: %s",
volReq.Name, err)) volReq.Name, err))