From f5d8c636c721c21c741618cc0d1011f58add5a55 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Fri, 15 Apr 2022 09:26:19 -0400 Subject: [PATCH] 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. --- .changelog/12573.txt | 3 +++ command/alloc_status.go | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .changelog/12573.txt diff --git a/.changelog/12573.txt b/.changelog/12573.txt new file mode 100644 index 000000000..95505f36d --- /dev/null +++ b/.changelog/12573.txt @@ -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` +``` diff --git a/command/alloc_status.go b/command/alloc_status.go index 0d8b413c0..e8d26b6ce 100644 --- a/command/alloc_status.go +++ b/command/alloc_status.go @@ -826,9 +826,14 @@ FOUND: fmt.Sprintf("%s|%v", volReq.Name, *volMount.ReadOnly)) case structs.VolumeTypeCSI: 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 // off with the -verbose flag - vol, _, err := client.CSIVolumes().Info(volReq.Source, nil) + vol, _, err := client.CSIVolumes().Info(source, nil) if err != nil { c.Ui.Error(fmt.Sprintf("Error retrieving volume info for %q: %s", volReq.Name, err))