Skip to content

Commit a0af3ab

Browse files
authored
Merge pull request #428 from andyzhangx/updatesvc-endpoint-lock
chore: refine update svc endpoint lock
2 parents 553444d + 7400cc2 commit a0af3ab

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

deploy/example/storageclass-blob-nfs.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ metadata:
55
name: blob-nfs
66
provisioner: blob.csi.azure.com
77
parameters:
8-
storageAccount: EXISTING_STORAGE_ACCOUNT_NAME
98
protocol: nfs
109
volumeBindingMode: Immediate

pkg/blob/azure.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ func (d *Driver) getServicePrincipalToken(env azure.Environment, resource string
167167
}
168168

169169
func (d *Driver) updateSubnetServiceEndpoints(ctx context.Context) error {
170+
if d.cloud.SubnetsClient == nil {
171+
return fmt.Errorf("SubnetsClient is nil")
172+
}
173+
170174
resourceGroup := d.cloud.ResourceGroup
171175
if len(d.cloud.VnetResourceGroup) > 0 {
172176
resourceGroup = d.cloud.VnetResourceGroup
@@ -175,9 +179,11 @@ func (d *Driver) updateSubnetServiceEndpoints(ctx context.Context) error {
175179
vnetName := d.cloud.VnetName
176180
subnetName := d.cloud.SubnetName
177181

178-
if d.cloud.SubnetsClient == nil {
179-
return fmt.Errorf("SubnetsClient is nil")
180-
}
182+
klog.V(2).Infof("updateSubnetServiceEndpoints on VnetName: %s, SubnetName: %s", vnetName, subnetName)
183+
184+
lockKey := resourceGroup + vnetName + subnetName
185+
d.subnetLockMap.LockEntry(lockKey)
186+
defer d.subnetLockMap.UnlockEntry(lockKey)
181187

182188
subnet, err := d.cloud.SubnetsClient.Get(ctx, resourceGroup, vnetName, subnetName, "")
183189
if err != nil {
@@ -208,15 +214,11 @@ func (d *Driver) updateSubnetServiceEndpoints(ctx context.Context) error {
208214
serviceEndpoints = append(serviceEndpoints, storageServiceEndpoint)
209215
subnet.SubnetPropertiesFormat.ServiceEndpoints = &serviceEndpoints
210216

211-
lockKey := resourceGroup + vnetName + subnetName
212-
d.subnetLockMap.LockEntry(lockKey)
213-
defer d.subnetLockMap.UnlockEntry(lockKey)
214-
215217
err = d.cloud.SubnetsClient.CreateOrUpdate(context.Background(), resourceGroup, vnetName, subnetName, subnet)
216218
if err != nil {
217219
return fmt.Errorf("failed to update the subnet %s under vnet %s: %v", subnetName, vnetName, err)
218220
}
219-
klog.V(4).Infof("serviceEndpoint(%s) is appended in subnet(%s)", storageService, subnetName)
221+
klog.V(2).Infof("serviceEndpoint(%s) is appended in subnet(%s)", storageService, subnetName)
220222
}
221223

222224
return nil

0 commit comments

Comments
 (0)