mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
add lock for csi node update
Signed-off-by: pacoxu <paco.xu@daocloud.io>
This commit is contained in:
parent
e23d83eead
commit
2360f228ab
@ -25,6 +25,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -66,6 +67,8 @@ type nodeInfoManager struct {
|
|||||||
nodeName types.NodeName
|
nodeName types.NodeName
|
||||||
volumeHost volume.VolumeHost
|
volumeHost volume.VolumeHost
|
||||||
migratedPlugins map[string](func() bool)
|
migratedPlugins map[string](func() bool)
|
||||||
|
// lock protects changes to node.
|
||||||
|
lock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no updates is needed, the function must return the same Node object as the input.
|
// 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 {
|
|||||||
// the effects of previous updateFuncs to avoid potential conflicts. For example, if multiple
|
// the effects of previous updateFuncs to avoid potential conflicts. For example, if multiple
|
||||||
// functions update the same field, updates in the last function are persisted.
|
// functions update the same field, updates in the last function are persisted.
|
||||||
func (nim *nodeInfoManager) tryUpdateNode(updateFuncs ...nodeUpdateFunc) error {
|
func (nim *nodeInfoManager) tryUpdateNode(updateFuncs ...nodeUpdateFunc) error {
|
||||||
|
nim.lock.Lock()
|
||||||
|
defer nim.lock.Unlock()
|
||||||
|
|
||||||
// Retrieve the latest version of Node before attempting update, so that
|
// Retrieve the latest version of Node before attempting update, so that
|
||||||
// existing changes are not overwritten.
|
// existing changes are not overwritten.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user