csi: respect -verbose flag for allocs in volume status (#12153)

This commit is contained in:
Tim Gross 2022-03-01 07:57:29 -05:00 committed by GitHub
parent 166011237b
commit 02ae95ab22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 5 deletions

3
.changelog/12153.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:improvement
csi: Respect the verbose flag in the output of `volume status`
```

View File

@ -106,7 +106,7 @@ func (c *VolumeDeregisterCommand) Run(args []string) int {
if len(vols) > 1 { if len(vols) > 1 {
if (volID != vols[0].ID) || (c.allNamespaces() && vols[0].ID == vols[1].ID) { if (volID != vols[0].ID) || (c.allNamespaces() && vols[0].ID == vols[1].ID) {
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, fullId) out, err := csiFormatSortedVolumes(vols)
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

@ -128,7 +128,7 @@ func (c *VolumeDetachCommand) Run(args []string) int {
if len(vols) > 1 { if len(vols) > 1 {
if (volID != vols[0].ID) || (c.allNamespaces() && vols[0].ID == vols[1].ID) { if (volID != vols[0].ID) || (c.allNamespaces() && vols[0].ID == vols[1].ID) {
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, fullId) out, err := csiFormatSortedVolumes(vols)
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

@ -109,6 +109,11 @@ func (c *VolumeStatusCommand) Run(args []string) int {
return 1 return 1
} }
// Truncate alloc and node IDs unless full length is requested
c.length = shortId
if c.verbose {
c.length = fullId
}
c.length = fullId c.length = fullId
// Get the HTTP client // Get the HTTP client

View File

@ -160,16 +160,16 @@ func (c *VolumeStatusCommand) csiFormatVolumes(vols []*api.CSIVolumeListStub) (s
return out, nil return out, nil
} }
return csiFormatSortedVolumes(vols, c.length) return csiFormatSortedVolumes(vols)
} }
// Format the volumes, assumes that we're already sorted by volume ID // Format the volumes, assumes that we're already sorted by volume ID
func csiFormatSortedVolumes(vols []*api.CSIVolumeListStub, length int) (string, error) { func csiFormatSortedVolumes(vols []*api.CSIVolumeListStub) (string, error) {
rows := make([]string, len(vols)+1) rows := make([]string, len(vols)+1)
rows[0] = "ID|Name|Plugin ID|Schedulable|Access Mode" rows[0] = "ID|Name|Plugin ID|Schedulable|Access Mode"
for i, v := range vols { for i, v := range vols {
rows[i+1] = fmt.Sprintf("%s|%s|%s|%t|%s", rows[i+1] = fmt.Sprintf("%s|%s|%s|%t|%s",
limit(v.ID, length), v.ID,
v.Name, v.Name,
v.PluginID, v.PluginID,
v.Schedulable, v.Schedulable,