Skip to content

Commit

Permalink
volumes: add capabilities to volume status
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tgross committed Feb 20, 2025
1 parent dde8eac commit 31e84b4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
16 changes: 15 additions & 1 deletion command/volume_status_csi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
16 changes: 15 additions & 1 deletion command/volume_status_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

0 comments on commit 31e84b4

Please sign in to comment.