mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
csi: add -secret and -parameter flag to volume snapshot create (#12360)
Pass-through the `-secret` and `-parameter` flags to allow setting parameters for the snapshot and overriding the secrets we've stored on the CSI volume in the state store.
This commit is contained in:
3
.changelog/12360.txt
Normal file
3
.changelog/12360.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
```release-note:improvement
|
||||||
|
csi: Added `-secret` and `-parameter` flags to `volume snapshot create` command
|
||||||
|
```
|
||||||
@@ -120,6 +120,10 @@ func (v *CSIVolumes) CreateSnapshot(snap *CSISnapshot, w *WriteOptions) (*CSISna
|
|||||||
req := &CSISnapshotCreateRequest{
|
req := &CSISnapshotCreateRequest{
|
||||||
Snapshots: []*CSISnapshot{snap},
|
Snapshots: []*CSISnapshot{snap},
|
||||||
}
|
}
|
||||||
|
if w == nil {
|
||||||
|
w = &WriteOptions{}
|
||||||
|
}
|
||||||
|
w.SetHeadersFromCSISecrets(snap.Secrets)
|
||||||
resp := &CSISnapshotCreateResponse{}
|
resp := &CSISnapshotCreateResponse{}
|
||||||
meta, err := v.client.write("/v1/volumes/snapshot", req, resp, w)
|
meta, err := v.client.write("/v1/volumes/snapshot", req, resp, w)
|
||||||
return resp, meta, err
|
return resp, meta, err
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/nomad/api"
|
"github.com/hashicorp/nomad/api"
|
||||||
"github.com/hashicorp/nomad/api/contexts"
|
"github.com/hashicorp/nomad/api/contexts"
|
||||||
|
flaghelper "github.com/hashicorp/nomad/helper/flags"
|
||||||
"github.com/posener/complete"
|
"github.com/posener/complete"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -34,7 +35,20 @@ General Options:
|
|||||||
|
|
||||||
` + generalOptionsUsage(usageOptsDefault) + `
|
` + generalOptionsUsage(usageOptsDefault) + `
|
||||||
|
|
||||||
|
Snapshot Create Options:
|
||||||
|
|
||||||
|
-parameter
|
||||||
|
Parameters to pass to the plugin to create a snapshot. Accepts multiple
|
||||||
|
flags in the form -parameter key=value
|
||||||
|
|
||||||
|
-secret
|
||||||
|
Secrets to pass to the plugin to create snapshot. Accepts multiple
|
||||||
|
flags in the form -secret key=value
|
||||||
|
|
||||||
|
-verbose
|
||||||
|
Display full information for the resulting snapshot.
|
||||||
`
|
`
|
||||||
|
|
||||||
return strings.TrimSpace(helpText)
|
return strings.TrimSpace(helpText)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +84,11 @@ func (c *VolumeSnapshotCreateCommand) Run(args []string) int {
|
|||||||
flags.Usage = func() { c.Ui.Output(c.Help()) }
|
flags.Usage = func() { c.Ui.Output(c.Help()) }
|
||||||
|
|
||||||
var verbose bool
|
var verbose bool
|
||||||
|
var parametersArgs flaghelper.StringFlag
|
||||||
|
var secretsArgs flaghelper.StringFlag
|
||||||
flags.BoolVar(&verbose, "verbose", false, "")
|
flags.BoolVar(&verbose, "verbose", false, "")
|
||||||
|
flags.Var(¶metersArgs, "parameter", "parameters for snapshot, ex. -parameter key=value")
|
||||||
|
flags.Var(&secretsArgs, "secret", "secrets for snapshot, ex. -secret key=value")
|
||||||
|
|
||||||
if err := flags.Parse(args); err != nil {
|
if err := flags.Parse(args); err != nil {
|
||||||
c.Ui.Error(fmt.Sprintf("Error parsing arguments %s", err))
|
c.Ui.Error(fmt.Sprintf("Error parsing arguments %s", err))
|
||||||
@@ -97,9 +115,30 @@ func (c *VolumeSnapshotCreateCommand) Run(args []string) int {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
secrets := api.CSISecrets{}
|
||||||
|
for _, kv := range secretsArgs {
|
||||||
|
s := strings.Split(kv, "=")
|
||||||
|
if len(s) == 2 {
|
||||||
|
secrets[s[0]] = s[1]
|
||||||
|
} else {
|
||||||
|
c.Ui.Error("Secret must be in the format: -secret key=value")
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
params := map[string]string{}
|
||||||
|
for _, kv := range parametersArgs {
|
||||||
|
p := strings.Split(kv, "=")
|
||||||
|
if len(p) == 2 {
|
||||||
|
params[p[0]] = p[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
snaps, _, err := client.CSIVolumes().CreateSnapshot(&api.CSISnapshot{
|
snaps, _, err := client.CSIVolumes().CreateSnapshot(&api.CSISnapshot{
|
||||||
SourceVolumeID: volID,
|
SourceVolumeID: volID,
|
||||||
Name: snapshotName,
|
Name: snapshotName,
|
||||||
|
Secrets: secrets,
|
||||||
|
Parameters: params,
|
||||||
}, nil)
|
}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Ui.Error(fmt.Sprintf("Error snapshotting volume: %s", err))
|
c.Ui.Error(fmt.Sprintf("Error snapshotting volume: %s", err))
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ func (c *VolumeSnapshotDeleteCommand) Run(args []string) int {
|
|||||||
}
|
}
|
||||||
// Check that we get exactly two arguments
|
// Check that we get exactly two arguments
|
||||||
args = flags.Args()
|
args = flags.Args()
|
||||||
if l := len(args); l != 2 {
|
if l := len(args); l < 2 {
|
||||||
c.Ui.Error("This command takes two arguments: <plugin id> <snapshot id>")
|
c.Ui.Error("This command takes two arguments: <plugin id> <snapshot id>")
|
||||||
c.Ui.Error(commandErrorText(c))
|
c.Ui.Error(commandErrorText(c))
|
||||||
return 1
|
return 1
|
||||||
@@ -97,6 +97,9 @@ func (c *VolumeSnapshotDeleteCommand) Run(args []string) int {
|
|||||||
s := strings.Split(kv, "=")
|
s := strings.Split(kv, "=")
|
||||||
if len(s) == 2 {
|
if len(s) == 2 {
|
||||||
secrets[s[0]] = s[1]
|
secrets[s[0]] = s[1]
|
||||||
|
} else {
|
||||||
|
c.Ui.Error("Secret must be in the format: -secret key=value")
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,12 @@ General Options:
|
|||||||
|
|
||||||
List Options:
|
List Options:
|
||||||
|
|
||||||
|
-page-token
|
||||||
|
Where to start pagination.
|
||||||
|
|
||||||
|
-per-page
|
||||||
|
How many results to show per page. Defaults to 30.
|
||||||
|
|
||||||
-plugin: Display only snapshots managed by a particular plugin. This
|
-plugin: Display only snapshots managed by a particular plugin. This
|
||||||
parameter is required.
|
parameter is required.
|
||||||
|
|
||||||
@@ -43,12 +49,10 @@ List Options:
|
|||||||
Secrets to pass to the plugin to list snapshots. Accepts multiple
|
Secrets to pass to the plugin to list snapshots. Accepts multiple
|
||||||
flags in the form -secret key=value
|
flags in the form -secret key=value
|
||||||
|
|
||||||
-per-page
|
-verbose
|
||||||
How many results to show per page. Defaults to 30.
|
Display full information for snapshots.
|
||||||
|
|
||||||
-page-token
|
|
||||||
Where to start pagination.
|
|
||||||
`
|
`
|
||||||
|
|
||||||
return strings.TrimSpace(helpText)
|
return strings.TrimSpace(helpText)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,6 +143,9 @@ func (c *VolumeSnapshotListCommand) Run(args []string) int {
|
|||||||
s := strings.Split(kv, "=")
|
s := strings.Split(kv, "=")
|
||||||
if len(s) == 2 {
|
if len(s) == 2 {
|
||||||
secrets[s[0]] = s[1]
|
secrets[s[0]] = s[1]
|
||||||
|
} else {
|
||||||
|
c.Ui.Error("Secret must be in the format: -secret key=value")
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1195,10 +1195,16 @@ func (v *CSIVolume) CreateSnapshot(args *structs.CSISnapshotCreateRequest, reply
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
secrets := vol.Secrets
|
||||||
|
for k, v := range snap.Secrets {
|
||||||
|
// merge request secrets onto volume secrets
|
||||||
|
secrets[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
cReq := &cstructs.ClientCSIControllerCreateSnapshotRequest{
|
cReq := &cstructs.ClientCSIControllerCreateSnapshotRequest{
|
||||||
ExternalSourceVolumeID: vol.ExternalID,
|
ExternalSourceVolumeID: vol.ExternalID,
|
||||||
Name: snap.Name,
|
Name: snap.Name,
|
||||||
Secrets: vol.Secrets,
|
Secrets: secrets,
|
||||||
Parameters: snap.Parameters,
|
Parameters: snap.Parameters,
|
||||||
}
|
}
|
||||||
cReq.PluginID = pluginID
|
cReq.PluginID = pluginID
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
---
|
---
|
||||||
layout: docs
|
layout: docs
|
||||||
|
|
||||||
page_title: 'Commands: volume snapshot create'
|
page_title: 'Commands: volume snapshot create'
|
||||||
description: |
|
description: |
|
||||||
Create external volume snapshots.
|
Create external volume snapshots.
|
||||||
@@ -35,6 +36,16 @@ When ACLs are enabled, this command requires a token with the
|
|||||||
|
|
||||||
@include 'general_options.mdx'
|
@include 'general_options.mdx'
|
||||||
|
|
||||||
|
## Snapshot Create Options
|
||||||
|
|
||||||
|
- `-parameter`: Parameters to pass to the plugin to create a
|
||||||
|
snapshot. Accepts multiple flags in the form `-parameter key=value`
|
||||||
|
|
||||||
|
- `-secret`: Secrets to pass to the plugin to create a snapshot. Accepts
|
||||||
|
multiple flags in the form `-secret key=value`
|
||||||
|
|
||||||
|
- `-verbose`: Display full information for the resulting snapshot.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
Snapshot a volume:
|
Snapshot a volume:
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ Nomad.
|
|||||||
|
|
||||||
## Snapshot List Options
|
## Snapshot List Options
|
||||||
|
|
||||||
|
- `-page-token`: Where to start pagination.
|
||||||
|
- `-per-page`: How many results to show per page.
|
||||||
- `-plugin`: Display only snapshots managed by a particular [CSI
|
- `-plugin`: Display only snapshots managed by a particular [CSI
|
||||||
plugin][csi_plugin]. This flag is required and accepts a plugin ID
|
plugin][csi_plugin]. This flag is required and accepts a plugin ID
|
||||||
or prefix. If there is an exact match based on the provided plugin,
|
or prefix. If there is an exact match based on the provided plugin,
|
||||||
@@ -36,8 +38,7 @@ Nomad.
|
|||||||
matching plugins will be displayed.
|
matching plugins will be displayed.
|
||||||
- `-secret`: Secrets to pass to the plugin to list snapshots. Accepts
|
- `-secret`: Secrets to pass to the plugin to list snapshots. Accepts
|
||||||
multiple flags in the form `-secret key=value`
|
multiple flags in the form `-secret key=value`
|
||||||
- `-per-page`: How many results to show per page.
|
- `-verbose`: Display full information for the resulting snapshot.
|
||||||
- `-page-token`: Where to start pagination.
|
|
||||||
|
|
||||||
When ACLs are enabled, this command requires a token with the
|
When ACLs are enabled, this command requires a token with the
|
||||||
`csi-list-volumes` capability for the plugin's namespace.
|
`csi-list-volumes` capability for the plugin's namespace.
|
||||||
|
|||||||
Reference in New Issue
Block a user