Skip to content

Commit 2491c0b

Browse files
authored
Merge pull request kubernetes#129218 from novahe/master
Add lock for csiNode update
2 parents af3b4cd + a70b6b9 commit 2491c0b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pkg/volume/csi/nodeinfomanager/nodeinfomanager.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,9 @@ func (nim *nodeInfoManager) tryUpdateCSINode(
379379
maxAttachLimit int64,
380380
topology map[string]string) error {
381381

382+
nim.lock.Lock()
383+
defer nim.lock.Unlock()
384+
382385
nodeInfo, err := csiKubeClient.StorageV1().CSINodes().Get(context.TODO(), string(nim.nodeName), metav1.GetOptions{})
383386
if nodeInfo == nil || errors.IsNotFound(err) {
384387
nodeInfo, err = nim.CreateCSINode()
@@ -412,6 +415,9 @@ func (nim *nodeInfoManager) InitializeCSINodeWithAnnotation() error {
412415
}
413416

414417
func (nim *nodeInfoManager) tryInitializeCSINodeWithAnnotation(csiKubeClient clientset.Interface) error {
418+
nim.lock.Lock()
419+
defer nim.lock.Unlock()
420+
415421
nodeInfo, err := csiKubeClient.StorageV1().CSINodes().Get(context.TODO(), string(nim.nodeName), metav1.GetOptions{})
416422
if nodeInfo == nil || errors.IsNotFound(err) {
417423
// CreateCSINode will set the annotation
@@ -602,6 +608,9 @@ func (nim *nodeInfoManager) tryUninstallDriverFromCSINode(
602608
csiKubeClient clientset.Interface,
603609
csiDriverName string) error {
604610

611+
nim.lock.Lock()
612+
defer nim.lock.Unlock()
613+
605614
nodeInfoClient := csiKubeClient.StorageV1().CSINodes()
606615
nodeInfo, err := nodeInfoClient.Get(context.TODO(), string(nim.nodeName), metav1.GetOptions{})
607616
if err != nil && errors.IsNotFound(err) {

0 commit comments

Comments
 (0)