@@ -463,28 +463,53 @@ func (vm *Manager) deleteVolume(ctx context.Context, v *api.Volume) error {
463463// leak. It's acceptable for now because we expect neither exceptionally long
464464// lived managers nor exceptionally high plugin churn.
465465func (vm * Manager ) getPlugin (name string ) (Plugin , error ) {
466- // if the plugin already exists, we can just return it.
467- if p , ok := vm .plugins [name ]; ok {
468- return p , nil
469- }
470-
471- // otherwise, we need to load the plugin.
472- pc , err := vm .pg .Get (name , DockerCSIPluginCap )
473- if err != nil {
474- return nil , err
475- }
476-
477- if pc == nil {
478- return nil , errors .New ("driver \" " + name + "\" not found" )
479- }
480-
481- pa , ok := pc .(mobyplugin.AddrPlugin )
482- if ! ok {
483- return nil , errors .New ("plugin for driver \" " + name + "\" does not implement PluginAddr" )
484- }
485-
486- p := vm .newPlugin (pa , vm .provider )
487- vm .plugins [name ] = p
488-
489- return p , nil
466+ // normalize driver name by stripping any tag (e.g. ":latest")
467+ canon := name
468+ if i := strings .IndexRune (name , ':' ); i >= 0 {
469+ canon = name [:i ]
470+ }
471+
472+ // Fast path: exact key or canonical key already loaded
473+ if p , ok := vm .plugins [name ]; ok {
474+ return p , nil
475+ }
476+ if p , ok := vm .plugins [canon ]; ok {
477+ // also alias the original name to it for future lookups
478+ vm .plugins [name ] = p
479+ return p , nil
480+ }
481+
482+ // Try plugin getter with full name first
483+ pc , err := vm .pg .Get (name , DockerCSIPluginCap )
484+ if err != nil {
485+ // retry using canonical name if different
486+ if canon != name {
487+ pc2 , err2 := vm .pg .Get (canon , DockerCSIPluginCap )
488+ if err2 == nil && pc2 != nil {
489+ pc = pc2
490+ }
491+ }
492+ if pc == nil {
493+ return nil , err
494+ }
495+ }
496+
497+ if pc == nil {
498+ return nil , errors .New ("driver \" " + name + "\" not found" )
499+ }
500+
501+ pa , ok := pc .(mobyplugin.AddrPlugin )
502+ if ! ok {
503+ return nil , errors .New ("plugin for driver \" " + name + "\" does not implement PluginAddr" )
504+ }
505+
506+ // create plugin instance once
507+ p := vm .newPlugin (pa , vm .provider )
508+
509+ // store under canonical, plugin-reported, and requested names
510+ vm .plugins [canon ] = p
511+ vm .plugins [pa .Name ()] = p
512+ vm .plugins [name ] = p
513+
514+ return p , nil
490515}
0 commit comments