Skip to content

Commit 756dd5f

Browse files
authored
add per volume lock for removePermissionsForFileVolume and configureNetPermissionsForFileVolume (#3439)
1 parent 748a09c commit 756dd5f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pkg/syncer/cnsoperator/controller/cnsfileaccessconfig/cnsfileaccessconfig_controller.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const (
6969
var (
7070
backOffDuration map[types.NamespacedName]time.Duration
7171
backOffDurationMapMutex = sync.Mutex{}
72+
volumePermissionLockMap *sync.Map
7273
)
7374

7475
// Add creates a new CnsFileAccessConfig Controller and adds it to the Manager.
@@ -96,7 +97,7 @@ func Add(mgr manager.Manager, clusterFlavor cnstypes.CnsClusterFlavor,
9697
}
9798
}
9899
}
99-
100+
volumePermissionLockMap = &sync.Map{}
100101
// Initialize the k8s orchestrator interface.
101102
coCommonInterface, err := commonco.GetContainerOrchestratorInterface(ctx, common.Kubernetes,
102103
cnstypes.CnsClusterFlavorWorkload, &syncer.COInitParams)
@@ -621,6 +622,10 @@ func removeFinalizerFromPVC(ctx context.Context, client client.Client,
621622
func (r *ReconcileCnsFileAccessConfig) removePermissionsForFileVolume(ctx context.Context, volumeID string,
622623
instance *cnsfileaccessconfigv1alpha1.CnsFileAccessConfig, skipConfigureVolumeACL bool) error {
623624
log := logger.GetLogger(ctx)
625+
volumePermissionLock, _ := volumePermissionLockMap.LoadOrStore(volumeID, &sync.Mutex{})
626+
instanceLock, _ := volumePermissionLock.(*sync.Mutex)
627+
instanceLock.Lock()
628+
defer instanceLock.Unlock()
624629
cnsFileVolumeClientInstance, err := cnsfilevolumeclient.GetFileVolumeClientInstance(ctx)
625630
if err != nil {
626631
return logger.LogNewErrorf(log, "Failed to get CNSFileVolumeClient instance. Error: %+v", err)
@@ -663,6 +668,10 @@ func (r *ReconcileCnsFileAccessConfig) configureNetPermissionsForFileVolume(ctx
663668
volumeID string, vm *vmoperatorv1alpha4.VirtualMachine, instance *cnsfileaccessconfigv1alpha1.CnsFileAccessConfig,
664669
removePermission bool) error {
665670
log := logger.GetLogger(ctx)
671+
volumePermissionLock, _ := volumePermissionLockMap.LoadOrStore(volumeID, &sync.Mutex{})
672+
instanceLock, _ := volumePermissionLock.(*sync.Mutex)
673+
instanceLock.Lock()
674+
defer instanceLock.Unlock()
666675
tkgVMIP, err := r.getVMExternalIP(ctx, vm)
667676
if err != nil {
668677
return logger.LogNewErrorf(log, "Failed to get external facing IP address for VM: %s/%s instance. Error: %+v",

0 commit comments

Comments
 (0)