volumes: add capabilities to volume status (#25173)

Job authors need to be able to review what capabilities a dynamic host volume or
CSI volume has so that they can set the correct access mode and attachment mode
in their job. Add these to the CLI output of `volume status`.

Ref: https://hashicorp.atlassian.net/browse/NET-12063
This commit is contained in:
Tim Gross
2025-02-20 14:40:31 -05:00
committed by GitHub
parent dde8eac42c
commit d63c1d0bad
3 changed files with 33 additions and 2 deletions

3
.changelog/25173.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:improvement
csi: Show volume capabilities in the volume status command
```

View File

@@ -224,8 +224,13 @@ func (c *VolumeStatusCommand) formatCSIBasic(vol *api.CSIVolume) (string, error)
full = append(full, topo)
}
banner := "\n[bold]Capabilities[reset]"
caps := formatCSIVolumeCapabilities(vol.RequestedCapabilities)
full = append(full, banner)
full = append(full, caps)
// Format the allocs
banner := c.Colorize().Color("\n[bold]Allocations[reset]")
banner = c.Colorize().Color("\n[bold]Allocations[reset]")
allocs := formatAllocListStubs(vol.Allocations, c.verbose, c.length)
full = append(full, banner)
full = append(full, allocs)
@@ -291,3 +296,12 @@ func csiVolMountOption(volume, request *api.CSIMountOptions) string {
return out
}
func formatCSIVolumeCapabilities(caps []*api.CSIVolumeCapability) string {
lines := make([]string, len(caps)+1)
lines[0] = "Access Mode|Attachment Mode"
for i, cap := range caps {
lines[i+1] = fmt.Sprintf("%s|%s", cap.AccessMode, cap.AttachmentMode)
}
return formatList(lines)
}

View File

@@ -151,8 +151,13 @@ func formatHostVolume(vol *api.HostVolume, opts formatOpts) (string, error) {
full := []string{formatKV(output)}
banner := "\n[bold]Capabilities[reset]"
caps := formatHostVolumeCapabilities(vol.RequestedCapabilities)
full = append(full, banner)
full = append(full, caps)
// Format the allocs
banner := "\n[bold]Allocations[reset]"
banner = "\n[bold]Allocations[reset]"
allocs := formatAllocListStubs(vol.Allocations, opts.verbose, opts.length)
full = append(full, banner)
full = append(full, allocs)
@@ -196,3 +201,12 @@ func formatHostVolumes(vols []*api.HostVolumeStub, opts formatOpts) (string, err
}
return formatList(rows), nil
}
func formatHostVolumeCapabilities(caps []*api.HostVolumeCapability) string {
lines := make([]string, len(caps)+1)
lines[0] = "Access Mode|Attachment Mode"
for i, cap := range caps {
lines[i+1] = fmt.Sprintf("%s|%s", cap.AccessMode, cap.AttachmentMode)
}
return formatList(lines)
}