Skip to content

Commit

Permalink
CSI: Allow NodePublishVolume even when plugin does not support staging
Browse files Browse the repository at this point in the history
Signed-off-by: Olli Janatuinen <olli.janatuinen@gmail.com>
  • Loading branch information
olljanat committed Feb 13, 2023
1 parent 8892b33 commit 1cca63f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 25 deletions.
11 changes: 6 additions & 5 deletions agent/csi/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,15 @@ func (np *nodePlugin) NodePublishVolume(ctx context.Context, req *api.VolumeAssi

publishTarget := publishPath(req)

// some volumes do not require staging. we can check this by checkign the
// staging variable, or we can just see if there is a staging path in the
// map.
// Some volumes plugins require staging; we track this with a boolean, which
// also implies a staging path in the path map. If the plugin is marked as
// requiring staging but does not have a staging path in the map, that is an
// error.
var stagingPath string
if vs, ok := np.volumeMap[req.ID]; ok {
stagingPath = vs.stagingPath
} else {
return status.Error(codes.FailedPrecondition, "volume not staged")
} else if np.staging {
return status.Error(codes.FailedPrecondition, "volume requires staging but was not staged")
}

c, err := np.Client(ctx)
Expand Down
58 changes: 38 additions & 20 deletions agent/csi/plugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,30 +80,48 @@ func TestNodeUnstageVolume(t *testing.T) {
}

func TestNodePublishVolume(t *testing.T) {
plugin := "plugin-3"
node := "node-1"
nodePlugin := newVolumeClient(plugin, node)
s := &api.VolumeAssignment{
VolumeID: "vol3",
AccessMode: &api.VolumeAccessMode{
Scope: api.VolumeScopeMultiNode,
Sharing: api.VolumeSharingOneWriter,
AccessType: &api.VolumeAccessMode_Mount{
Mount: &api.VolumeAccessMode_MountVolume{},
},
var testcases = []struct {
staging bool
plugin string
}{
{
plugin: "staging-plugin",
staging: true,
},
Driver: &api.Driver{
Name: plugin,
{
plugin: "non-staging-plugin",
staging: false,
},
}
err := nodePlugin.NodePublishVolume(context.Background(), s)
assert.Equal(t, codes.FailedPrecondition, testutils.ErrorCode(err))

// Volume needs to be staged before publishing. Stage -> Publish
err = nodePlugin.NodeStageVolume(context.Background(), s)
require.NoError(t, err)
err = nodePlugin.NodePublishVolume(context.Background(), s)
require.NoError(t, err)
for _, tc := range testcases {
nodePlugin := newVolumeClient(tc.plugin, "node-1")
s := &api.VolumeAssignment{
VolumeID: "vol3",
AccessMode: &api.VolumeAccessMode{
Scope: api.VolumeScopeMultiNode,
Sharing: api.VolumeSharingOneWriter,
AccessType: &api.VolumeAccessMode_Mount{
Mount: &api.VolumeAccessMode_MountVolume{},
},
},
Driver: &api.Driver{
Name: tc.plugin,
},
}

nodePlugin.staging = tc.staging
if nodePlugin.staging {
err := nodePlugin.NodePublishVolume(context.Background(), s)
assert.Equal(t, codes.FailedPrecondition, testutils.ErrorCode(err))

// Volume needs to be staged before publishing. Stage -> Publish
err = nodePlugin.NodeStageVolume(context.Background(), s)
require.NoError(t, err)
}
err := nodePlugin.NodePublishVolume(context.Background(), s)
require.NoError(t, err)
}
}

func TestNodeUnpublishVolume(t *testing.T) {
Expand Down

0 comments on commit 1cca63f

Please sign in to comment.