csi: when warning for multiple prefix matches, use full ID (#11853)

When the `volume deregister` or `volume detach` commands get an ID
prefix that matches multiple volumes, show the full length of the
volume IDs in the list of volumes shown so so that the user can select
the correct one.
This commit is contained in:
Tim Gross 2022-01-14 12:25:48 -05:00 committed by GitHub
parent 9c4864badd
commit 33f7c6cba4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 2 deletions

3
.changelog/11853.txt Normal file
View File

@ -0,0 +1,3 @@
```bug
csi: Fixed a bug in `volume deregister` and `volume detach` commands where volume IDs were truncated when asking the user to select one of several prefix matches
```

View File

@ -101,7 +101,7 @@ func (c *VolumeDeregisterCommand) Run(args []string) int {
} }
if len(vols) > 1 { if len(vols) > 1 {
sort.Slice(vols, func(i, j int) bool { return vols[i].ID < vols[j].ID }) sort.Slice(vols, func(i, j int) bool { return vols[i].ID < vols[j].ID })
out, err := csiFormatSortedVolumes(vols, shortId) out, err := csiFormatSortedVolumes(vols, fullId)
if err != nil { if err != nil {
c.Ui.Error(fmt.Sprintf("Error formatting: %s", err)) c.Ui.Error(fmt.Sprintf("Error formatting: %s", err))
return 1 return 1

View File

@ -123,7 +123,7 @@ func (c *VolumeDetachCommand) Run(args []string) int {
} }
if len(vols) > 1 { if len(vols) > 1 {
sort.Slice(vols, func(i, j int) bool { return vols[i].ID < vols[j].ID }) sort.Slice(vols, func(i, j int) bool { return vols[i].ID < vols[j].ID })
out, err := csiFormatSortedVolumes(vols, shortId) out, err := csiFormatSortedVolumes(vols, fullId)
if err != nil { if err != nil {
c.Ui.Error(fmt.Sprintf("Error formatting: %s", err)) c.Ui.Error(fmt.Sprintf("Error formatting: %s", err))
return 1 return 1