@@ -28,6 +28,7 @@ import (
2828 "google.golang.org/grpc/codes"
2929 "google.golang.org/grpc/status"
3030 "k8s.io/klog/v2"
31+ azcache "sigs.k8s.io/cloud-provider-azure/pkg/cache"
3132)
3233
3334const (
@@ -147,6 +148,11 @@ func (d *Driver) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest)
147148 return & csi.DeleteVolumeResponse {}, nil
148149 }
149150
151+ if acquired := d .volumeLocks .TryAcquire (volumeID ); ! acquired {
152+ return nil , status .Errorf (codes .Aborted , volumeOperationAlreadyExistsFmt , volumeID )
153+ }
154+ defer d .volumeLocks .Release (volumeID )
155+
150156 var volCap * csi.VolumeCapability
151157 secrets := req .GetSecrets ()
152158 mountOptions := getMountOptions (secrets )
@@ -167,6 +173,16 @@ func (d *Driver) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest)
167173
168174 if len (req .GetSecrets ()) > 0 && ! strings .EqualFold (smbVol .onDelete , retain ) {
169175 klog .V (2 ).Infof ("begin to delete or archive subdirectory since secret is provided" )
176+ // check whether volumeID is in the cache
177+ cache , err := d .volDeletionCache .Get (volumeID , azcache .CacheReadTypeDefault )
178+ if err != nil {
179+ return nil , status .Errorf (codes .Internal , err .Error ())
180+ }
181+ if cache != nil {
182+ klog .V (2 ).Infof ("DeleteVolume: volume %s is already deleted" , volumeID )
183+ return & csi.DeleteVolumeResponse {}, nil
184+ }
185+
170186 // mount smb base share so we can delete or archive the subdirectory
171187 if err = d .internalMount (ctx , smbVol , volCap , secrets ); err != nil {
172188 return nil , status .Errorf (codes .Internal , "failed to mount smb server: %v" , err .Error ())
@@ -211,6 +227,7 @@ func (d *Driver) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest)
211227 klog .V (2 ).Infof ("DeleteVolume(%s) does not delete subdirectory" , volumeID )
212228 }
213229
230+ d .volDeletionCache .Set (volumeID , "" )
214231 return & csi.DeleteVolumeResponse {}, nil
215232}
216233
0 commit comments