From 0aca822f8dac52f4a71efb3611f5a2d841c7ee0f Mon Sep 17 00:00:00 2001 From: Danielle Lancashire Date: Fri, 7 Feb 2020 15:38:02 +0100 Subject: [PATCH] sched/feasible: Validate CSIVolume's correctly Previously we were looking up plugins based on the Alias Name for a CSI Volume within the context of its task group. Here we first look up a volume based on its identifier and then validate the existence of the plugin based on its `PluginID`. --- scheduler/feasible.go | 13 ++++++------- scheduler/feasible_test.go | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/scheduler/feasible.go b/scheduler/feasible.go index f2ddc6888..78a5a245f 100644 --- a/scheduler/feasible.go +++ b/scheduler/feasible.go @@ -230,20 +230,19 @@ func (c *CSIVolumeChecker) hasPlugins(n *structs.Node) bool { ws := memdb.NewWatchSet() for _, req := range c.volumes { - // Check that this node has a healthy running plugin with the right PluginID - plugin, ok := n.CSINodePlugins[req.Name] - if !(ok && plugin.Healthy) { - return false - } - // Get the volume to check that it's healthy (there's a healthy controller // and the volume hasn't encountered an error or been marked for GC vol, err := c.ctx.State().CSIVolumeByID(ws, req.Source) - if err != nil || vol == nil { return false } + // Check that this node has a healthy running plugin with the right PluginID + plugin, ok := n.CSINodePlugins[vol.PluginID] + if !(ok && plugin.Healthy) { + return false + } + if (req.ReadOnly && !vol.CanReadOnly()) || !vol.CanWrite() { return false diff --git a/scheduler/feasible_test.go b/scheduler/feasible_test.go index dd2c48279..e5b49745f 100644 --- a/scheduler/feasible_test.go +++ b/scheduler/feasible_test.go @@ -293,9 +293,9 @@ func TestCSIVolumeChecker(t *testing.T) { noVolumes := map[string]*structs.VolumeRequest{} volumes := map[string]*structs.VolumeRequest{ - "foo": { + "baz": { Type: "csi", - Name: "foo", + Name: "baz", Source: "volume-id", }, "nonsense": {