Skip to content

Commit 6fc9027

Browse files
committed
init
1 parent 1af7a16 commit 6fc9027

File tree

4 files changed

+226
-241
lines changed

4 files changed

+226
-241
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.20
44

55
require (
66
github.com/aws/aws-sdk-go v1.44.327
7+
github.com/cenkalti/backoff/v4 v4.3.0
78
github.com/container-storage-interface/spec v1.7.0
89
github.com/golang/mock v1.6.0
910
github.com/kubernetes-csi/csi-test/v5 v5.0.0
@@ -29,7 +30,6 @@ require (
2930
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
3031
github.com/beorn7/perks v1.0.1 // indirect
3132
github.com/blang/semver/v4 v4.0.0 // indirect
32-
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
3333
github.com/cespare/xxhash/v2 v2.1.2 // indirect
3434
github.com/coreos/go-semver v0.3.0 // indirect
3535
github.com/coreos/go-systemd/v22 v22.4.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM
6161
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
6262
github.com/cenkalti/backoff/v4 v4.1.3 h1:cFAlzYUlVYDysBEH2T5hyJZMh3+5+WCBvSnK6Q8UtC4=
6363
github.com/cenkalti/backoff/v4 v4.1.3/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
64+
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
65+
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
6466
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
6567
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
6668
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=

pkg/driver/controller.go

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

3538
var (
@@ -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

Comments
 (0)