Merge pull request #49596 from jingxu97/July/checkVolumeSpecNil

Automatic merge from submit-queue

Check volumespec is nil in FindPluginBySpec
This commit is contained in:
Kubernetes Submit Queue 2017-08-11 17:36:22 -07:00 committed by GitHub
commit 9c508f12fb
2 changed files with 15 additions and 0 deletions

View File

@ -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) {

View File

@ -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) {