Skip to content

Commit

Permalink
Improve handling of InsufficientVolumeCapacity errors
Browse files Browse the repository at this point in the history
Signed-off-by: torredil <[email protected]>
  • Loading branch information
torredil committed Sep 19, 2024
1 parent deb9544 commit ba9c02c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ var (

// ErrInvalidRequest is returned if parameters were rejected by driver
ErrInvalidRequest = errors.New("invalid request")

// ErrInsufficientVolumeCapacity is returned when there's not enough capacity to fulfill the volume provision request.
ErrInsufficientVolumeCapacity = errors.New("There is not enough capacity to fulfill your EBS volume provision request. You can try to provision a different volume type, EBS volume in a different availability zone, or you can wait for additional capacity to become available.")
)

// Set during build time via -ldflags
Expand Down Expand Up @@ -665,6 +668,9 @@ func (c *cloud) CreateDisk(ctx context.Context, volumeName string, diskOptions *
c.latestClientTokens.Set(volumeName, &nextTokenNumber)
return nil, ErrIdempotentParameterMismatch
}
if isAWSErrorInsufficientVolumeCapacity(err) {
return nil, ErrInsufficientVolumeCapacity
}
return nil, fmt.Errorf("could not create volume in EC2: %w", err)
}

Expand Down Expand Up @@ -1684,6 +1690,12 @@ func isAWSErrorInvalidParameter(err error) bool {
return false
}

// isAWSErrorInsufficientVolumeCapacity returns a boolean indicating whether the
// given error is an AWS InsufficientVolumeCapacity error.
func isAWSErrorInsufficientVolumeCapacity(err error) bool {
return isAWSError(err, "InsufficientVolumeCapacity")
}

// Checks for desired size on volume by also verifying volume size by describing volume.
// This is to get around potential eventual consistency problems with describing volume modifications
// objects and ensuring that we read two different objects to verify volume state.
Expand Down
16 changes: 16 additions & 0 deletions pkg/cloud/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,22 @@ func TestCreateDisk(t *testing.T) {
},
expErr: fmt.Errorf("invalid AWS VolumeType %q", "invalidVolumeType"),
},
{
name: "failure: InsufficientVolumeCapacity error",
volumeName: "vol-test-name-error",
diskOptions: &DiskOptions{
CapacityBytes: util.GiBToBytes(1),
Tags: map[string]string{VolumeNameTagKey: "vol-test", AwsEbsDriverTagKey: "true"},
AvailabilityZone: expZone,
},
expCreateVolumeInput: &ec2.CreateVolumeInput{
Iops: aws.Int32(2000),
},
expErr: ErrInsufficientVolumeCapacity,
expCreateVolumeErr: &smithy.GenericAPIError{
Code: "InsufficientVolumeCapacity",
},
},
}
for _, tc := range testCases {
tc := tc
Expand Down

0 comments on commit ba9c02c

Please sign in to comment.