@@ -32,6 +32,7 @@ import (
32
32
"google.golang.org/grpc/codes"
33
33
"google.golang.org/grpc/status"
34
34
"google.golang.org/protobuf/types/known/timestamppb"
35
+ azcache "sigs.k8s.io/cloud-provider-azure/pkg/cache"
35
36
36
37
"k8s.io/klog/v2"
37
38
)
@@ -151,6 +152,11 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
151
152
}
152
153
}
153
154
155
+ if acquired := cs .Driver .volumeLocks .TryAcquire (name ); ! acquired {
156
+ return nil , status .Errorf (codes .Aborted , volumeOperationAlreadyExistsFmt , name )
157
+ }
158
+ defer cs .Driver .volumeLocks .Release (name )
159
+
154
160
nfsVol , err := newNFSVolume (name , reqCapacity , parameters , cs .Driver .defaultOnDeletePolicy )
155
161
if err != nil {
156
162
return nil , status .Error (codes .InvalidArgument , err .Error ())
@@ -230,7 +236,21 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
230
236
nfsVol .onDelete = cs .Driver .defaultOnDeletePolicy
231
237
}
232
238
239
+ if acquired := cs .Driver .volumeLocks .TryAcquire (volumeID ); ! acquired {
240
+ return nil , status .Errorf (codes .Aborted , volumeOperationAlreadyExistsFmt , volumeID )
241
+ }
242
+ defer cs .Driver .volumeLocks .Release (volumeID )
243
+
233
244
if ! strings .EqualFold (nfsVol .onDelete , retain ) {
245
+ // check whether volumeID is in the cache
246
+ cache , err := cs .Driver .volDeletionCache .Get (volumeID , azcache .CacheReadTypeDefault )
247
+ if err != nil {
248
+ return nil , status .Errorf (codes .Internal , err .Error ())
249
+ }
250
+ if cache != nil {
251
+ klog .V (2 ).Infof ("DeleteVolume: volume %s is already deleted" , volumeID )
252
+ return & csi.DeleteVolumeResponse {}, nil
253
+ }
234
254
// mount nfs base share so we can delete the subdirectory
235
255
if err = cs .internalMount (ctx , nfsVol , nil , volCap ); err != nil {
236
256
return nil , status .Errorf (codes .Internal , "failed to mount nfs server: %v" , err .Error ())
@@ -281,6 +301,7 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
281
301
klog .V (2 ).Infof ("DeleteVolume: volume(%s) is set to retain, not deleting/archiving subdirectory" , volumeID )
282
302
}
283
303
304
+ cs .Driver .volDeletionCache .Set (volumeID , "" )
284
305
return & csi.DeleteVolumeResponse {}, nil
285
306
}
286
307
0 commit comments