@@ -23,7 +23,6 @@ import (
23
23
"path"
24
24
"sort"
25
25
"strings"
26
- "sync"
27
26
"time"
28
27
29
28
"context"
@@ -84,25 +83,14 @@ func ProbeVolumePlugins() []volume.VolumePlugin {
84
83
// volume.VolumePlugin methods
85
84
var _ volume.VolumePlugin = & csiPlugin {}
86
85
87
- type csiDriver struct {
88
- driverName string
89
- driverEndpoint string
90
- highestSupportedVersion * utilversion.Version
91
- }
92
-
93
- type csiDriversStore struct {
94
- driversMap map [string ]csiDriver
95
- sync.RWMutex
96
- }
97
-
98
86
// RegistrationHandler is the handler which is fed to the pluginwatcher API.
99
87
type RegistrationHandler struct {
100
88
}
101
89
102
90
// TODO (verult) consider using a struct instead of global variables
103
91
// csiDrivers map keep track of all registered CSI drivers on the node and their
104
92
// corresponding sockets
105
- var csiDrivers csiDriversStore
93
+ var csiDrivers = & DriversStore {}
106
94
107
95
var nim nodeinfomanager.Interface
108
96
@@ -141,17 +129,12 @@ func (h *RegistrationHandler) RegisterPlugin(pluginName string, endpoint string,
141
129
return err
142
130
}
143
131
144
- func () {
145
- // Storing endpoint of newly registered CSI driver into the map, where CSI driver name will be the key
146
- // all other CSI components will be able to get the actual socket of CSI drivers by its name.
147
-
148
- // It's not necessary to lock the entire RegistrationCallback() function because only the CSI
149
- // client depends on this driver map, and the CSI client does not depend on node information
150
- // updated in the rest of the function.
151
- csiDrivers .Lock ()
152
- defer csiDrivers .Unlock ()
153
- csiDrivers .driversMap [pluginName ] = csiDriver {driverName : pluginName , driverEndpoint : endpoint , highestSupportedVersion : highestSupportedVersion }
154
- }()
132
+ // Storing endpoint of newly registered CSI driver into the map, where CSI driver name will be the key
133
+ // all other CSI components will be able to get the actual socket of CSI drivers by its name.
134
+ csiDrivers .Set (pluginName , Driver {
135
+ endpoint : endpoint ,
136
+ highestSupportedVersion : highestSupportedVersion ,
137
+ })
155
138
156
139
// Get node info from the driver.
157
140
csi , err := newCsiDriverClient (csiDriverName (pluginName ))
@@ -200,15 +183,7 @@ func (h *RegistrationHandler) validateVersions(callerName, pluginName string, en
200
183
return nil , err
201
184
}
202
185
203
- // Check for existing drivers with the same name
204
- var existingDriver csiDriver
205
- driverExists := false
206
- func () {
207
- csiDrivers .RLock ()
208
- defer csiDrivers .RUnlock ()
209
- existingDriver , driverExists = csiDrivers .driversMap [pluginName ]
210
- }()
211
-
186
+ existingDriver , driverExists := csiDrivers .Get (pluginName )
212
187
if driverExists {
213
188
if ! existingDriver .highestSupportedVersion .LessThan (newDriverHighestVersion ) {
214
189
err := fmt .Errorf ("%s for CSI driver %q failed. Another driver with the same name is already registered with a higher supported version: %q" , callerName , pluginName , existingDriver .highestSupportedVersion )
@@ -245,8 +220,7 @@ func (p *csiPlugin) Init(host volume.VolumeHost) error {
245
220
}
246
221
}
247
222
248
- // Initializing csiDrivers map and label management channels
249
- csiDrivers = csiDriversStore {driversMap : map [string ]csiDriver {}}
223
+ // Initializing the label management channels
250
224
nim = nodeinfomanager .NewNodeInfoManager (host .GetNodeName (), host )
251
225
252
226
// TODO(#70514) Init CSINodeInfo object if the CRD exists and create Driver
@@ -657,11 +631,7 @@ func (p *csiPlugin) getPublishContext(client clientset.Interface, handle, driver
657
631
}
658
632
659
633
func unregisterDriver (driverName string ) error {
660
- func () {
661
- csiDrivers .Lock ()
662
- defer csiDrivers .Unlock ()
663
- delete (csiDrivers .driversMap , driverName )
664
- }()
634
+ csiDrivers .Delete (driverName )
665
635
666
636
if err := nim .UninstallCSIDriver (driverName ); err != nil {
667
637
klog .Errorf ("Error uninstalling CSI driver: %v" , err )
0 commit comments