From d3529d7be62b7083f7e20ba737376c5d3cadac4d Mon Sep 17 00:00:00 2001 From: hc-github-team-nomad-core <82989552+hc-github-team-nomad-core@users.noreply.github.com> Date: Fri, 4 Aug 2023 04:36:50 -0500 Subject: [PATCH] Backport of CLI: make snapshot name requiered in creating volume snapshots into release/1.6.x (#18152) This pull request was automerged via backport-assistant --- .changelog/17958.txt | 3 +++ command/volume_snapshot_create.go | 24 ++++++++++-------------- 2 files changed, 13 insertions(+), 14 deletions(-) create mode 100644 .changelog/17958.txt diff --git a/.changelog/17958.txt b/.changelog/17958.txt new file mode 100644 index 000000000..536fcbdd8 --- /dev/null +++ b/.changelog/17958.txt @@ -0,0 +1,3 @@ +```release-note:bug +cli: Snapshot name is required in `volume snapshot create` command +``` diff --git a/command/volume_snapshot_create.go b/command/volume_snapshot_create.go index 7e912f348..9cd567477 100644 --- a/command/volume_snapshot_create.go +++ b/command/volume_snapshot_create.go @@ -19,17 +19,16 @@ type VolumeSnapshotCreateCommand struct { func (c *VolumeSnapshotCreateCommand) Help() string { helpText := ` -Usage: nomad volume snapshot create [snapshot_name] +Usage: nomad volume snapshot create Create a snapshot of an external storage volume. This command requires a - volume ID or prefix. If there is an exact match based on the provided volume - ID or prefix, then the specific volume is snapshotted. Otherwise, a list of - matching volumes and information will be displayed. The volume must still be - registered with Nomad in order to be snapshotted. + volume ID or prefix and snapthost name. If there is an exact match based on + the provided volume ID or prefix, then the specific volume is snapshotted. + Otherwise, a list of matching volumes and information will be displayed. The + volume must still be registered with Nomad in order to be snapshotted. - If an optional snapshot name is provided, the argument will be passed to the - CSI plugin to be used as the ID of the resulting snapshot. Not all plugins - accept this name and it may be ignored. + Snapshot name will be passed to the CSI plugin to be used as the ID of the + resulting snapshot. When ACLs are enabled, this command requires a token with the 'csi-write-volume' capability for the volume's namespace. @@ -100,16 +99,13 @@ func (c *VolumeSnapshotCreateCommand) Run(args []string) int { // Check that we at least one argument args = flags.Args() - if l := len(args); l == 0 { - c.Ui.Error("This command takes at least one argument: [snapshot name]") + if l := len(args); l != 2 { + c.Ui.Error("This command takes two arguments: ") c.Ui.Error(commandErrorText(c)) return 1 } volID := args[0] - snapshotName := "" - if len(args) == 2 { - snapshotName = args[1] - } + snapshotName := args[1] // Get the HTTP client client, err := c.Meta.Client()