Skip to content

Commit

Permalink
adding throughput field in provider spec
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabh-11 committed Aug 16, 2022
1 parent e624706 commit bc85436
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 1 deletion.
7 changes: 7 additions & 0 deletions pkg/aws/apis/aws_provider_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ type AWSEbsBlockDeviceSpec struct {
// Do not specify it in requests to create gp2, st1, sc1, or standard volumes.
Iops int64 `json:"iops,omitempty"`

// The throughput that the volume supports, in MiB/s.
//
// This parameter is valid only for gp3 volumes.
//
// Valid Range: The range as of 16th Aug 2022 is from 125 MiB/s to 1000 MiB/s. For more info refer (http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html)
Throughput *int64 `json:"throughput,omitempty"`

// Identifier (key ID, key alias, ID ARN, or alias ARN) for a customer managed
// CMK under which the EBS volume is encrypted.
//
Expand Down
5 changes: 5 additions & 0 deletions pkg/aws/apis/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ func validateBlockDevices(blockDevices []awsapi.AWSBlockDeviceMappingSpec, fldPa
if disk.Ebs.Iops < 0 || (disk.Ebs.VolumeType == awsapi.VolumeTypeIO1 && disk.Ebs.Iops == 0) {
allErrs = append(allErrs, field.Required(idxPath.Child("ebs.iops"), "Please mention a valid EBS volume iops"))
}

// validate throughput
if disk.Ebs.Throughput != nil && *disk.Ebs.Throughput <= 0 {
allErrs = append(allErrs, field.Invalid(idxPath.Child("ebs.throughput"), *disk.Ebs.Throughput, "Throughput should be a positive value"))
}
}

if rootPartitionCount > 1 {
Expand Down
91 changes: 90 additions & 1 deletion pkg/aws/apis/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package validation

import (
"fmt"
"github.com/aws/aws-sdk-go/aws"

awsapi "github.com/gardener/machine-controller-manager-provider-aws/pkg/aws/apis"
. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -126,6 +127,46 @@ var _ = Describe("Validation", func() {
errToHaveOccurred: false,
},
}),
Entry("AWS machine class with gp3 type block device", &data{
setup: setup{},
action: action{
spec: &awsapi.AWSProviderSpec{
AMI: "ami-123456789",
BlockDevices: []awsapi.AWSBlockDeviceMappingSpec{
{
Ebs: awsapi.AWSEbsBlockDeviceSpec{
VolumeSize: 50,
VolumeType: "gp3",
Iops: 3500,
Throughput: aws.Int64(200),
},
},
},
IAM: awsapi.AWSIAMProfileSpec{
Name: "test-iam",
},
Region: "eu-west-1",
MachineType: "m4.large",
KeyName: "test-ssh-publickey",
NetworkInterfaces: []awsapi.AWSNetworkInterfaceSpec{
{
SecurityGroupIDs: []string{
"sg-00002132323",
},
SubnetID: "subnet-123456",
},
},
Tags: map[string]string{
"kubernetes.io/cluster/shoot--test": "1",
"kubernetes.io/role/test": "1",
},
},
secret: providerSecret,
},
expect: expect{
errToHaveOccurred: false,
},
}),
Entry("AMI field missing", &data{
setup: setup{},
action: action{
Expand Down Expand Up @@ -834,7 +875,7 @@ var _ = Describe("Validation", func() {
},
},
}),
Entry("EBS volume of type gp3 is missing iops field", &data{
Entry("EBS volume of type gp3 is missing iops and throughout field", &data{
setup: setup{},
action: action{
spec: &awsapi.AWSProviderSpec{
Expand Down Expand Up @@ -919,6 +960,54 @@ var _ = Describe("Validation", func() {
},
},
}),
Entry("Invalid EBS volume throughput", &data{
setup: setup{},
action: action{
spec: &awsapi.AWSProviderSpec{
AMI: "ami-123456789",
BlockDevices: []awsapi.AWSBlockDeviceMappingSpec{
{
Ebs: awsapi.AWSEbsBlockDeviceSpec{
VolumeSize: 50,
Iops: 100,
Throughput: aws.Int64(-200),
VolumeType: "gp3",
},
},
},
IAM: awsapi.AWSIAMProfileSpec{
Name: "test-iam",
},
Region: "eu-west-1",
MachineType: "m4.large",
KeyName: "test-ssh-publickey",
NetworkInterfaces: []awsapi.AWSNetworkInterfaceSpec{
{
SecurityGroupIDs: []string{
"sg-00002132323",
},
SubnetID: "subnet-123456",
},
},
Tags: map[string]string{
"kubernetes.io/cluster/shoot--test": "1",
"kubernetes.io/role/test": "1",
},
},
secret: providerSecret,
},
expect: expect{
errToHaveOccurred: true,
errList: field.ErrorList{
{
Type: "FieldValueInvalid",
Field: "providerSpec.blockDevices[0].ebs.throughput",
BadValue: int64(-200),
Detail: "Please mention a valid EBS volume iops",
},
},
},
}),
Entry("Network Interfaces are missing", &data{
setup: setup{},
action: action{
Expand Down
5 changes: 5 additions & 0 deletions pkg/aws/core_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ func (d *Driver) generateBlockDevices(blockDevices []api.AWSBlockDeviceMappingSp
blkDeviceMapping.Ebs.Iops = aws.Int64(disk.Ebs.Iops)
}

// adding throughput
if disk.Ebs.Throughput != nil {
blkDeviceMapping.Ebs.Throughput = disk.Ebs.Throughput
}

if snapshotID != nil {
blkDeviceMapping.Ebs.SnapshotId = snapshotID
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/aws/core_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ var _ = Describe("CoreUtils", func() {
Iops: 1000,
VolumeSize: 10,
VolumeType: "gp3",
Throughput: aws.Int64(200),
},
},
{
Expand Down Expand Up @@ -185,6 +186,7 @@ var _ = Describe("CoreUtils", func() {
Encrypted: aws.Bool(true),
VolumeSize: aws.Int64(10),
Iops: aws.Int64(1000),
Throughput: aws.Int64(200),
VolumeType: aws.String("gp3"),
},
},
Expand Down

0 comments on commit bc85436

Please sign in to comment.