Skip to content

Commit f8acafd

Browse files
committed
fix: delete volume error in archive deletion mode
1 parent 4d10e97 commit f8acafd

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

pkg/smb/controllerserver.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3334
const (
@@ -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

pkg/smb/smb.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ type Driver struct {
8282
enableGetVolumeStats bool
8383
// a timed cache storing volume stats <volumeID, volumeStats>
8484
volStatsCache azcache.Resource
85+
// a timed cache storing volume deletion records <volumeID, "">
86+
volDeletionCache azcache.Resource
8587
// this only applies to Windows node
8688
removeSMBMappingDuringUnmount bool
8789
krb5CacheDirectory string
@@ -120,6 +122,9 @@ func NewDriver(options *DriverOptions) *Driver {
120122
if driver.volStatsCache, err = azcache.NewTimedCache(time.Duration(options.VolStatsCacheExpireInMinutes)*time.Minute, getter, false); err != nil {
121123
klog.Fatalf("%v", err)
122124
}
125+
if driver.volDeletionCache, err = azcache.NewTimedCache(time.Minute, getter, false); err != nil {
126+
klog.Fatalf("%v", err)
127+
}
123128
return &driver
124129
}
125130

0 commit comments

Comments
 (0)