Skip to content

Commit

Permalink
Remove premature CreateVolume error if requested IOPS is below minimum
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSirenko committed Jan 10, 2024
1 parent fd7dbc2 commit 7e8ec74
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 45 deletions.
15 changes: 4 additions & 11 deletions pkg/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,7 @@ func (c *cloud) CreateDisk(ctx context.Context, volumeName string, diskOptions *
} else if diskOptions.IOPSPerGB > 0 {
requestedIops = int64(diskOptions.IOPSPerGB) * capacityGiB
}
iops, err = capIOPS(createType, capacityGiB, requestedIops, minIops, maxIops, maxIopsPerGb, diskOptions.AllowIOPSPerGBIncrease)
if err != nil {
return nil, err
}
iops = capIOPS(createType, capacityGiB, requestedIops, minIops, maxIops, maxIopsPerGb, diskOptions.AllowIOPSPerGBIncrease)
}

var tags []*ec2.Tag
Expand Down Expand Up @@ -1505,10 +1502,10 @@ func getVolumeAttachmentsList(volume *ec2.Volume) []string {
}

// Calculate actual IOPS for a volume and cap it at supported AWS limits.
func capIOPS(volumeType string, requestedCapacityGiB int64, requestedIops int64, minTotalIOPS, maxTotalIOPS, maxIOPSPerGB int64, allowIncrease bool) (int64, error) {
func capIOPS(volumeType string, requestedCapacityGiB int64, requestedIops int64, minTotalIOPS, maxTotalIOPS, maxIOPSPerGB int64, allowIncrease bool) int64 {
// If requestedIops is zero the user did not request a specific amount, and the default will be used instead
if requestedIops == 0 {
return 0, nil
return 0
}

iops := requestedIops
Expand All @@ -1517,10 +1514,6 @@ func capIOPS(volumeType string, requestedCapacityGiB int64, requestedIops int64,
if allowIncrease {
iops = minTotalIOPS
klog.V(5).InfoS("[Debug] Increased IOPS to the min supported limit", "volumeType", volumeType, "requestedCapacityGiB", requestedCapacityGiB, "limit", iops)
} else if volumeType == VolumeTypeGP3 {
klog.V(5).InfoS("[Debug] Did not increase IOPS", "volumeType", volumeType, "requestedCapacityGiB", requestedCapacityGiB)
} else {
return 0, fmt.Errorf("invalid IOPS: %d is too low, it must be at least %d", iops, minTotalIOPS)
}
}
if iops > maxTotalIOPS {
Expand All @@ -1532,5 +1525,5 @@ func capIOPS(volumeType string, requestedCapacityGiB int64, requestedIops int64,
iops = maxIopsByCapacity
klog.V(5).InfoS("[Debug] Capped IOPS for volume", "volumeType", volumeType, "requestedCapacityGiB", requestedCapacityGiB, "maxIOPSPerGB", maxIOPSPerGB, "limit", iops)
}
return iops, nil
return iops
}
34 changes: 0 additions & 34 deletions pkg/cloud/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,23 +575,6 @@ func TestCreateDisk(t *testing.T) {
expCreateVolumeInput: nil,
expErr: fmt.Errorf("invalid StorageClass parameters; specify either IOPS or IOPSPerGb, not both"),
},
{
name: "fail: io1 with too low iopsPerGB",
volumeName: "vol-test-name",
diskOptions: &DiskOptions{
CapacityBytes: util.GiBToBytes(4),
Tags: map[string]string{VolumeNameTagKey: "vol-test", AwsEbsDriverTagKey: "true"},
VolumeType: VolumeTypeIO1,
IOPSPerGB: 1,
},
expDisk: &Disk{
VolumeID: "vol-test",
CapacityGiB: 4,
AvailabilityZone: defaultZone,
},
expCreateVolumeInput: nil,
expErr: fmt.Errorf("invalid IOPS: 4 is too low, it must be at least 100"),
},
{
name: "success: small io1 with too high iopsPerGB",
volumeName: "vol-test-name",
Expand Down Expand Up @@ -650,23 +633,6 @@ func TestCreateDisk(t *testing.T) {
},
expErr: nil,
},
{
name: "fail: io2 with too low iopsPerGB",
volumeName: "vol-test-name",
diskOptions: &DiskOptions{
CapacityBytes: util.GiBToBytes(4),
Tags: map[string]string{VolumeNameTagKey: "vol-test", AwsEbsDriverTagKey: "true"},
VolumeType: VolumeTypeIO2,
IOPSPerGB: 1,
},
expDisk: &Disk{
VolumeID: "vol-test",
CapacityGiB: 4,
AvailabilityZone: defaultZone,
},
expCreateVolumeInput: nil,
expErr: fmt.Errorf("invalid IOPS: 4 is too low, it must be at least 100"),
},
{
name: "success: small io2 with too high iopsPerGB",
volumeName: "vol-test-name",
Expand Down

0 comments on commit 7e8ec74

Please sign in to comment.