@@ -19,6 +19,12 @@ import (
1919 "context"
2020 "errors"
2121 "fmt"
22+ "os"
23+ "strconv"
24+ "strings"
25+ "time"
26+
27+ "github.com/cenkalti/backoff/v4"
2228 "github.com/container-storage-interface/spec/lib/go/csi"
2329 "github.com/kubernetes-sigs/aws-fsx-openzfs-csi-driver/pkg/cloud"
2430 "github.com/kubernetes-sigs/aws-fsx-openzfs-csi-driver/pkg/driver/internal"
@@ -27,9 +33,6 @@ import (
2733 "google.golang.org/grpc/status"
2834 "google.golang.org/protobuf/types/known/timestamppb"
2935 "k8s.io/klog/v2"
30- "os"
31- "strconv"
32- "strings"
3336)
3437
3538var (
@@ -95,6 +98,7 @@ type controllerService struct {
9598 cloud cloud.Cloud
9699 inFlight * internal.InFlight
97100 driverOptions * DriverOptions
101+ backoff backoff.BackOff
98102}
99103
100104// newControllerService creates a new controller service
@@ -122,6 +126,7 @@ func newControllerService(driverOptions *DriverOptions) controllerService {
122126 cloud : cloudSrv ,
123127 inFlight : internal .NewInFlight (),
124128 driverOptions : driverOptions ,
129+ backoff : backoff .NewExponentialBackOff (), // Default spec: https://pkg.go.dev/github.com/cenkalti/backoff/v4#pkg-constants
125130 }
126131}
127132
@@ -355,6 +360,30 @@ func (d *controllerService) DeleteVolume(ctx context.Context, req *csi.DeleteVol
355360 return nil , status .Errorf (codes .Internal , "Could not delete volume ID %q: %v" , volumeID , err )
356361 }
357362
363+ // Wait until volume not found
364+ describeRetry := func () error {
365+ if splitVolumeId [0 ] == cloud .FilesystemPrefix {
366+ _ , err = d .cloud .DescribeFileSystem (ctx , volumeID )
367+ }
368+ if splitVolumeId [0 ] == cloud .VolumePrefix {
369+ _ , err = d .cloud .DescribeVolume (ctx , volumeID )
370+ }
371+
372+ if err != nil {
373+ if err == cloud .ErrNotFound {
374+ return nil
375+ }
376+ return status .Error (codes .Internal , err .Error ())
377+ }
378+ return status .Errorf (codes .Internal , "Volume ID %q still exists" , volumeID )
379+ }
380+
381+ err = backoff .RetryNotify (describeRetry , d .backoff , notifyRetryError )
382+ if err != nil {
383+ return nil , status .Errorf (codes .Internal , "Could not delete volume ID %q: %v" , volumeID , err )
384+ }
385+
386+ klog .V (4 ).InfoS ("DeleteVolume: volume not found, returning with success" , "volumeId" , volumeID )
358387 return & csi.DeleteVolumeResponse {}, nil
359388}
360389
@@ -785,3 +814,7 @@ func (d *controllerService) appendSnapshotARN(ctx context.Context, parameters ma
785814
786815 return nil
787816}
817+
818+ func notifyRetryError (err error , t time.Duration ) {
819+ klog .ErrorS (err , fmt .Sprintf ("Retrying in %f seconds" , t .Seconds ()))
820+ }
0 commit comments