Commit 9c508f12 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #49596 from jingxu97/July/checkVolumeSpecNil

Automatic merge from submit-queue Check volumespec is nil in FindPluginBySpec
parents 92d9e442 c18ecb08
......@@ -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