Skip to content

Commit ca9347f

Browse files
authored
Merge pull request kubernetes#77838 from tedyu/matched-plugin
Move the array of plugin names to inside the last if block in VolumePluginMgr#FindPluginBySpec
2 parents a60d212 + 2001fee commit ca9347f

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

pkg/volume/plugins.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -647,19 +647,16 @@ func (pm *VolumePluginMgr) FindPluginBySpec(spec *Spec) (VolumePlugin, error) {
647647
return nil, fmt.Errorf("Could not find plugin because volume spec is nil")
648648
}
649649

650-
matchedPluginNames := []string{}
651650
matches := []VolumePlugin{}
652-
for k, v := range pm.plugins {
651+
for _, v := range pm.plugins {
653652
if v.CanSupport(spec) {
654-
matchedPluginNames = append(matchedPluginNames, k)
655653
matches = append(matches, v)
656654
}
657655
}
658656

659657
pm.refreshProbedPlugins()
660-
for pluginName, plugin := range pm.probedPlugins {
658+
for _, plugin := range pm.probedPlugins {
661659
if plugin.CanSupport(spec) {
662-
matchedPluginNames = append(matchedPluginNames, pluginName)
663660
matches = append(matches, plugin)
664661
}
665662
}
@@ -668,6 +665,10 @@ func (pm *VolumePluginMgr) FindPluginBySpec(spec *Spec) (VolumePlugin, error) {
668665
return nil, fmt.Errorf("no volume plugin matched")
669666
}
670667
if len(matches) > 1 {
668+
matchedPluginNames := []string{}
669+
for _, plugin := range matches {
670+
matchedPluginNames = append(matchedPluginNames, plugin.GetPluginName())
671+
}
671672
return nil, fmt.Errorf("multiple volume plugins matched: %s", strings.Join(matchedPluginNames, ","))
672673
}
673674
return matches[0], nil
@@ -684,11 +685,9 @@ func (pm *VolumePluginMgr) IsPluginMigratableBySpec(spec *Spec) (bool, error) {
684685
return false, fmt.Errorf("could not find if plugin is migratable because volume spec is nil")
685686
}
686687

687-
matchedPluginNames := []string{}
688688
matches := []VolumePlugin{}
689-
for k, v := range pm.plugins {
689+
for _, v := range pm.plugins {
690690
if v.CanSupport(spec) {
691-
matchedPluginNames = append(matchedPluginNames, k)
692691
matches = append(matches, v)
693692
}
694693
}
@@ -698,6 +697,10 @@ func (pm *VolumePluginMgr) IsPluginMigratableBySpec(spec *Spec) (bool, error) {
698697
return false, nil
699698
}
700699
if len(matches) > 1 {
700+
matchedPluginNames := []string{}
701+
for _, plugin := range matches {
702+
matchedPluginNames = append(matchedPluginNames, plugin.GetPluginName())
703+
}
701704
return false, fmt.Errorf("multiple volume plugins matched: %s", strings.Join(matchedPluginNames, ","))
702705
}
703706

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

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

721722
pm.refreshProbedPlugins()
722723
if plugin, found := pm.probedPlugins[name]; found {
723-
matchedPluginNames = append(matchedPluginNames, name)
724724
matches = append(matches, plugin)
725725
}
726726

727727
if len(matches) == 0 {
728728
return nil, fmt.Errorf("no volume plugin matched")
729729
}
730730
if len(matches) > 1 {
731+
matchedPluginNames := []string{}
732+
for _, plugin := range matches {
733+
matchedPluginNames = append(matchedPluginNames, plugin.GetPluginName())
734+
}
731735
return nil, fmt.Errorf("multiple volume plugins matched: %s", strings.Join(matchedPluginNames, ","))
732736
}
733737
return matches[0], nil

0 commit comments

Comments
 (0)