Skip to content

Commit

Permalink
Merge pull request kubernetes#77838 from tedyu/matched-plugin
Browse files Browse the repository at this point in the history
Move the array of plugin names to inside the last if block in VolumePluginMgr#FindPluginBySpec
  • Loading branch information
k8s-ci-robot authored May 14, 2019
2 parents a60d212 + 2001fee commit ca9347f
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions pkg/volume/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,19 +647,16 @@ func (pm *VolumePluginMgr) FindPluginBySpec(spec *Spec) (VolumePlugin, error) {
return nil, fmt.Errorf("Could not find plugin because volume spec is nil")
}

matchedPluginNames := []string{}
matches := []VolumePlugin{}
for k, v := range pm.plugins {
for _, v := range pm.plugins {
if v.CanSupport(spec) {
matchedPluginNames = append(matchedPluginNames, k)
matches = append(matches, v)
}
}

pm.refreshProbedPlugins()
for pluginName, plugin := range pm.probedPlugins {
for _, plugin := range pm.probedPlugins {
if plugin.CanSupport(spec) {
matchedPluginNames = append(matchedPluginNames, pluginName)
matches = append(matches, plugin)
}
}
Expand All @@ -668,6 +665,10 @@ func (pm *VolumePluginMgr) FindPluginBySpec(spec *Spec) (VolumePlugin, error) {
return nil, fmt.Errorf("no volume plugin matched")
}
if len(matches) > 1 {
matchedPluginNames := []string{}
for _, plugin := range matches {
matchedPluginNames = append(matchedPluginNames, plugin.GetPluginName())
}
return nil, fmt.Errorf("multiple volume plugins matched: %s", strings.Join(matchedPluginNames, ","))
}
return matches[0], nil
Expand All @@ -684,11 +685,9 @@ func (pm *VolumePluginMgr) IsPluginMigratableBySpec(spec *Spec) (bool, error) {
return false, fmt.Errorf("could not find if plugin is migratable because volume spec is nil")
}

matchedPluginNames := []string{}
matches := []VolumePlugin{}
for k, v := range pm.plugins {
for _, v := range pm.plugins {
if v.CanSupport(spec) {
matchedPluginNames = append(matchedPluginNames, k)
matches = append(matches, v)
}
}
Expand All @@ -698,6 +697,10 @@ func (pm *VolumePluginMgr) IsPluginMigratableBySpec(spec *Spec) (bool, error) {
return false, nil
}
if len(matches) > 1 {
matchedPluginNames := []string{}
for _, plugin := range matches {
matchedPluginNames = append(matchedPluginNames, plugin.GetPluginName())
}
return false, fmt.Errorf("multiple volume plugins matched: %s", strings.Join(matchedPluginNames, ","))
}

Expand All @@ -711,23 +714,24 @@ func (pm *VolumePluginMgr) FindPluginByName(name string) (VolumePlugin, error) {
defer pm.mutex.Unlock()

// Once we can get rid of legacy names we can reduce this to a map lookup.
matchedPluginNames := []string{}
matches := []VolumePlugin{}
if v, found := pm.plugins[name]; found {
matchedPluginNames = append(matchedPluginNames, name)
matches = append(matches, v)
}

pm.refreshProbedPlugins()
if plugin, found := pm.probedPlugins[name]; found {
matchedPluginNames = append(matchedPluginNames, name)
matches = append(matches, plugin)
}

if len(matches) == 0 {
return nil, fmt.Errorf("no volume plugin matched")
}
if len(matches) > 1 {
matchedPluginNames := []string{}
for _, plugin := range matches {
matchedPluginNames = append(matchedPluginNames, plugin.GetPluginName())
}
return nil, fmt.Errorf("multiple volume plugins matched: %s", strings.Join(matchedPluginNames, ","))
}
return matches[0], nil
Expand Down

0 comments on commit ca9347f

Please sign in to comment.