diff --git a/pkg/volume/plugins.go b/pkg/volume/plugins.go index cbc27391096..39c67366ffc 100644 --- a/pkg/volume/plugins.go +++ b/pkg/volume/plugins.go @@ -387,6 +387,10 @@ func (pm *VolumePluginMgr) FindPluginBySpec(spec *Spec) (VolumePlugin, error) { pm.mutex.Lock() defer pm.mutex.Unlock() + if spec == nil { + return nil, fmt.Errorf("Could not find plugin because volume spec is nil") + } + matches := []string{} for k, v := range pm.plugins { if v.CanSupport(spec) { diff --git a/pkg/volume/plugins_test.go b/pkg/volume/plugins_test.go index 2279e849646..fc319e10271 100644 --- a/pkg/volume/plugins_test.go +++ b/pkg/volume/plugins_test.go @@ -112,6 +112,17 @@ func TestVolumePluginMgrFunc(t *testing.T) { if plug.GetPluginName() != "testPlugin" { t.Errorf("Wrong name: %s", plug.GetPluginName()) } + + plug, err = vpm.FindPluginBySpec(nil) + if err == nil { + t.Errorf("Should return error if volume spec is nil") + } + + volumeSpec := &Spec{} + plug, err = vpm.FindPluginBySpec(volumeSpec) + if err != nil { + t.Errorf("Should return test plugin if volume spec is not nil") + } } func Test_ValidatePodTemplate(t *testing.T) {