Skip to content

Commit 30a9b8b

Browse files
authored
Merge pull request kubernetes#94389 from pacoxu/fix/94378
add lock for csi node update
2 parents 293a53f + 2360f22 commit 30a9b8b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pkg/volume/csi/nodeinfomanager/nodeinfomanager.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"fmt"
2626
"math"
2727
"strings"
28+
"sync"
2829

2930
"time"
3031

@@ -66,6 +67,8 @@ type nodeInfoManager struct {
6667
nodeName types.NodeName
6768
volumeHost volume.VolumeHost
6869
migratedPlugins map[string](func() bool)
70+
// lock protects changes to node.
71+
lock sync.Mutex
6972
}
7073

7174
// If no updates is needed, the function must return the same Node object as the input.
@@ -175,6 +178,9 @@ func (nim *nodeInfoManager) updateNode(updateFuncs ...nodeUpdateFunc) error {
175178
// the effects of previous updateFuncs to avoid potential conflicts. For example, if multiple
176179
// functions update the same field, updates in the last function are persisted.
177180
func (nim *nodeInfoManager) tryUpdateNode(updateFuncs ...nodeUpdateFunc) error {
181+
nim.lock.Lock()
182+
defer nim.lock.Unlock()
183+
178184
// Retrieve the latest version of Node before attempting update, so that
179185
// existing changes are not overwritten.
180186

0 commit comments

Comments
 (0)