@@ -69,6 +69,7 @@ const (
69
69
var (
70
70
backOffDuration map [types.NamespacedName ]time.Duration
71
71
backOffDurationMapMutex = sync.Mutex {}
72
+ volumePermissionLockMap * sync.Map
72
73
)
73
74
74
75
// Add creates a new CnsFileAccessConfig Controller and adds it to the Manager.
@@ -96,7 +97,7 @@ func Add(mgr manager.Manager, clusterFlavor cnstypes.CnsClusterFlavor,
96
97
}
97
98
}
98
99
}
99
-
100
+ volumePermissionLockMap = & sync. Map {}
100
101
// Initialize the k8s orchestrator interface.
101
102
coCommonInterface , err := commonco .GetContainerOrchestratorInterface (ctx , common .Kubernetes ,
102
103
cnstypes .CnsClusterFlavorWorkload , & syncer .COInitParams )
@@ -621,6 +622,10 @@ func removeFinalizerFromPVC(ctx context.Context, client client.Client,
621
622
func (r * ReconcileCnsFileAccessConfig ) removePermissionsForFileVolume (ctx context.Context , volumeID string ,
622
623
instance * cnsfileaccessconfigv1alpha1.CnsFileAccessConfig , skipConfigureVolumeACL bool ) error {
623
624
log := logger .GetLogger (ctx )
625
+ volumePermissionLock , _ := volumePermissionLockMap .LoadOrStore (volumeID , & sync.Mutex {})
626
+ instanceLock , _ := volumePermissionLock .(* sync.Mutex )
627
+ instanceLock .Lock ()
628
+ defer instanceLock .Unlock ()
624
629
cnsFileVolumeClientInstance , err := cnsfilevolumeclient .GetFileVolumeClientInstance (ctx )
625
630
if err != nil {
626
631
return logger .LogNewErrorf (log , "Failed to get CNSFileVolumeClient instance. Error: %+v" , err )
@@ -663,6 +668,10 @@ func (r *ReconcileCnsFileAccessConfig) configureNetPermissionsForFileVolume(ctx
663
668
volumeID string , vm * vmoperatorv1alpha4.VirtualMachine , instance * cnsfileaccessconfigv1alpha1.CnsFileAccessConfig ,
664
669
removePermission bool ) error {
665
670
log := logger .GetLogger (ctx )
671
+ volumePermissionLock , _ := volumePermissionLockMap .LoadOrStore (volumeID , & sync.Mutex {})
672
+ instanceLock , _ := volumePermissionLock .(* sync.Mutex )
673
+ instanceLock .Lock ()
674
+ defer instanceLock .Unlock ()
666
675
tkgVMIP , err := r .getVMExternalIP (ctx , vm )
667
676
if err != nil {
668
677
return logger .LogNewErrorf (log , "Failed to get external facing IP address for VM: %s/%s instance. Error: %+v" ,
0 commit comments