Commit c18ecb08 authored by Jing Xu's avatar Jing Xu

Check volumespec is nil in FindPluginBySpec

This PR fixes issue #49513
parent bb485466
......@@ -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) {
......
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment