Skip to content

Commit

Permalink
Merge pull request kubernetes#109853 from ping035627/k8s-220506
Browse files Browse the repository at this point in the history
Cleanup FindPluginBySpec() in VolumePluginMgr
  • Loading branch information
k8s-ci-robot authored Jul 1, 2022
2 parents fa16bf8 + bbeec9b commit 20a7253
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions pkg/volume/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,34 +662,33 @@ func (pm *VolumePluginMgr) FindPluginBySpec(spec *Spec) (VolumePlugin, error) {
return nil, fmt.Errorf("could not find plugin because volume spec is nil")
}

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

pm.refreshProbedPlugins()
for _, plugin := range pm.probedPlugins {
if plugin.CanSupport(spec) {
matches = append(matches, plugin)
match = plugin
matchedPluginNames = append(matchedPluginNames, plugin.GetPluginName())
}
}

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

// Issue warning if the matched provider is deprecated
pm.logDeprecation(matches[0].GetPluginName())
return matches[0], nil
pm.logDeprecation(match.GetPluginName())
return match, nil
}

// FindPluginByName fetches a plugin by name or by legacy name. If no plugin
Expand Down

0 comments on commit 20a7253

Please sign in to comment.