Skip to content

Commit

Permalink
csi: respect -verbose flag for allocs in volume status
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross committed Feb 28, 2022
1 parent 636345a commit ba9187b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/12153.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
csi: Respect the verbose flag in the output of `volume status`
```
2 changes: 1 addition & 1 deletion command/volume_deregister.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (c *VolumeDeregisterCommand) Run(args []string) int {
if len(vols) > 1 {
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 })
out, err := csiFormatSortedVolumes(vols, fullId)
out, err := csiFormatSortedVolumes(vols)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error formatting: %s", err))
return 1
Expand Down
2 changes: 1 addition & 1 deletion command/volume_detach.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (c *VolumeDetachCommand) Run(args []string) int {
if len(vols) > 1 {
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 })
out, err := csiFormatSortedVolumes(vols, fullId)
out, err := csiFormatSortedVolumes(vols)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error formatting: %s", err))
return 1
Expand Down
5 changes: 5 additions & 0 deletions command/volume_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ func (c *VolumeStatusCommand) Run(args []string) int {
return 1
}

// Truncate alloc and node IDs unless full length is requested
c.length = shortId
if c.verbose {
c.length = fullId
}
c.length = fullId

// Get the HTTP client
Expand Down
6 changes: 3 additions & 3 deletions command/volume_status_csi.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,16 @@ func (c *VolumeStatusCommand) csiFormatVolumes(vols []*api.CSIVolumeListStub) (s
return out, nil
}

return csiFormatSortedVolumes(vols, c.length)
return csiFormatSortedVolumes(vols)
}

// 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[0] = "ID|Name|Plugin ID|Schedulable|Access Mode"
for i, v := range vols {
rows[i+1] = fmt.Sprintf("%s|%s|%s|%t|%s",
limit(v.ID, length),
v.ID,
v.Name,
v.PluginID,
v.Schedulable,
Expand Down

0 comments on commit ba9187b

Please sign in to comment.