From d63c1d0baddaac4c77e3d0577979467562f43491 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Thu, 20 Feb 2025 14:40:31 -0500 Subject: [PATCH] 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 --- .changelog/25173.txt | 3 +++ command/volume_status_csi.go | 16 +++++++++++++++- command/volume_status_host.go | 16 +++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 .changelog/25173.txt diff --git a/.changelog/25173.txt b/.changelog/25173.txt new file mode 100644 index 000000000..61dd831a0 --- /dev/null +++ b/.changelog/25173.txt @@ -0,0 +1,3 @@ +```release-note:improvement +csi: Show volume capabilities in the volume status command +``` diff --git a/command/volume_status_csi.go b/command/volume_status_csi.go index 01644b513..8b8b9a986 100644 --- a/command/volume_status_csi.go +++ b/command/volume_status_csi.go @@ -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) +} diff --git a/command/volume_status_host.go b/command/volume_status_host.go index 018834eef..5f8f4232a 100644 --- a/command/volume_status_host.go +++ b/command/volume_status_host.go @@ -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) +}