Merge pull request #129218 from novahe/master

Add lock for csiNode update
This commit is contained in:
Kubernetes Prow Robot 2025-03-14 05:29:46 -07:00 committed by GitHub
commit 2491c0b150
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -379,6 +379,9 @@ func (nim *nodeInfoManager) tryUpdateCSINode(
maxAttachLimit int64,
topology map[string]string) error {
nim.lock.Lock()
defer nim.lock.Unlock()
nodeInfo, err := csiKubeClient.StorageV1().CSINodes().Get(context.TODO(), string(nim.nodeName), metav1.GetOptions{})
if nodeInfo == nil || errors.IsNotFound(err) {
nodeInfo, err = nim.CreateCSINode()
@ -412,6 +415,9 @@ func (nim *nodeInfoManager) InitializeCSINodeWithAnnotation() error {
}
func (nim *nodeInfoManager) tryInitializeCSINodeWithAnnotation(csiKubeClient clientset.Interface) error {
nim.lock.Lock()
defer nim.lock.Unlock()
nodeInfo, err := csiKubeClient.StorageV1().CSINodes().Get(context.TODO(), string(nim.nodeName), metav1.GetOptions{})
if nodeInfo == nil || errors.IsNotFound(err) {
// CreateCSINode will set the annotation
@ -602,6 +608,9 @@ func (nim *nodeInfoManager) tryUninstallDriverFromCSINode(
csiKubeClient clientset.Interface,
csiDriverName string) error {
nim.lock.Lock()
defer nim.lock.Unlock()
nodeInfoClient := csiKubeClient.StorageV1().CSINodes()
nodeInfo, err := nodeInfoClient.Get(context.TODO(), string(nim.nodeName), metav1.GetOptions{})
if err != nil && errors.IsNotFound(err) {