Skip to content

Commit

Permalink
Merge pull request #744 from chrishenzie/create-volume-idempotency
Browse files Browse the repository at this point in the history
Make CreateVolume idempotent
  • Loading branch information
k8s-ci-robot authored Feb 18, 2021
2 parents c547161 + 8cf86b7 commit 1a15fcc
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 7 deletions.
10 changes: 10 additions & 0 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
csi "github.com/container-storage-interface/spec/lib/go/csi"
"github.com/golang/protobuf/ptypes"
"github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/cloud"
"github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/driver/internal"
"github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/util"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -56,6 +57,7 @@ var (
// controllerService represents the controller service of CSI driver
type controllerService struct {
cloud cloud.Cloud
inFlight *internal.InFlight
driverOptions *DriverOptions
}

Expand Down Expand Up @@ -87,6 +89,7 @@ func newControllerService(driverOptions *DriverOptions) controllerService {

return controllerService{
cloud: cloud,
inFlight: internal.NewInFlight(),
driverOptions: driverOptions,
}
}
Expand Down Expand Up @@ -201,6 +204,13 @@ func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVol
return newCreateVolumeResponse(disk), nil
}

// check if a request is already in-flight because the CreateVolume API is not idempotent
if ok := d.inFlight.Insert(req); !ok {
msg := fmt.Sprintf("Create volume request for %s is already in progress", volName)
return nil, status.Error(codes.Aborted, msg)
}
defer d.inFlight.Delete(req)

// create a new volume
zone := pickAvailabilityZone(req.GetAccessibilityRequirements())
outpostArn := getOutpostArn(req.GetAccessibilityRequirements())
Expand Down
Loading

0 comments on commit 1a15fcc

Please sign in to comment.