Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry pick of #94389: add lock for csi node update #95057

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/volume/csi/nodeinfomanager/nodeinfomanager.go
Expand Up @@ -25,6 +25,7 @@ import (
"fmt"
"math"
"strings"
"sync"

"time"

Expand Down Expand Up @@ -66,6 +67,8 @@ type nodeInfoManager struct {
nodeName types.NodeName
volumeHost volume.VolumeHost
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.
Expand Down Expand Up @@ -175,6 +178,9 @@ func (nim *nodeInfoManager) updateNode(updateFuncs ...nodeUpdateFunc) error {
// 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.
func (nim *nodeInfoManager) tryUpdateNode(updateFuncs ...nodeUpdateFunc) error {
nim.lock.Lock()
defer nim.lock.Unlock()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this been tested to verify it prevents race conditions ?


// Retrieve the latest version of Node before attempting update, so that
// existing changes are not overwritten.

Expand Down