Skip to content

Commit

Permalink
csi: get plugin ID for creating snapshot from volume, not args
Browse files Browse the repository at this point in the history
The `CreateSnapshot` RPC expects a plugin ID to be set by the API, but
in the common case of the `nomad volume snapshot create` command, we
don't ask the user for the plugin ID because it's available from the
volume we're snapshotting.

Change the order of the RPC so that we get the volume first and then
use the volume's plugin ID for the plugin we send the CSI RPC to.
  • Loading branch information
tgross committed Mar 4, 2022
1 parent e3001f6 commit 9e1412c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
28 changes: 14 additions & 14 deletions nomad/csi_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -1095,29 +1095,29 @@ func (v *CSIVolume) CreateSnapshot(args *structs.CSISnapshotCreateRequest, reply
return fmt.Errorf("snapshot cannot be nil")
}

plugin, err := state.CSIPluginByID(nil, snap.PluginID)
vol, err := state.CSIVolumeByID(nil, args.RequestNamespace(), snap.SourceVolumeID)
if err != nil {
multierror.Append(&mErr,
fmt.Errorf("error querying plugin %q: %v", snap.PluginID, err))
multierror.Append(&mErr, fmt.Errorf("error querying volume %q: %v", snap.SourceVolumeID, err))
continue
}
if plugin == nil {
multierror.Append(&mErr, fmt.Errorf("no such plugin %q", snap.PluginID))
if vol == nil {
multierror.Append(&mErr, fmt.Errorf("no such volume %q", snap.SourceVolumeID))
continue
}
if !plugin.HasControllerCapability(structs.CSIControllerSupportsCreateDeleteSnapshot) {

plugin, err := state.CSIPluginByID(nil, vol.PluginID)
if err != nil {
multierror.Append(&mErr,
fmt.Errorf("plugin %q does not support snapshot", snap.PluginID))
fmt.Errorf("error querying plugin %q: %v", vol.PluginID, err))
continue
}

vol, err := state.CSIVolumeByID(nil, args.RequestNamespace(), snap.SourceVolumeID)
if err != nil {
multierror.Append(&mErr, fmt.Errorf("error querying volume %q: %v", snap.SourceVolumeID, err))
if plugin == nil {
multierror.Append(&mErr, fmt.Errorf("no such plugin %q", vol.PluginID))
continue
}
if vol == nil {
multierror.Append(&mErr, fmt.Errorf("no such volume %q", snap.SourceVolumeID))
if !plugin.HasControllerCapability(structs.CSIControllerSupportsCreateDeleteSnapshot) {
multierror.Append(&mErr,
fmt.Errorf("plugin %q does not support snapshot", vol.PluginID))
continue
}

Expand All @@ -1127,7 +1127,7 @@ func (v *CSIVolume) CreateSnapshot(args *structs.CSISnapshotCreateRequest, reply
Secrets: vol.Secrets,
Parameters: snap.Parameters,
}
cReq.PluginID = plugin.ID
cReq.PluginID = vol.PluginID
cResp := &cstructs.ClientCSIControllerCreateSnapshotResponse{}
err = v.srv.RPC(method, cReq, cResp)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion nomad/csi_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,6 @@ func TestCSIVolumeEndpoint_CreateSnapshot(t *testing.T) {
SourceVolumeID: "test-volume0",
Secrets: structs.CSISecrets{"mysecret": "secretvalue"},
Parameters: map[string]string{"myparam": "paramvalue"},
PluginID: "minnie",
}},
WriteRequest: structs.WriteRequest{
Region: "global",
Expand Down

0 comments on commit 9e1412c

Please sign in to comment.