From bc85436bbfc16f042a61d17a5f6d0e85c0d4da07 Mon Sep 17 00:00:00 2001 From: Rishabh Patel Date: Tue, 16 Aug 2022 16:32:38 +0530 Subject: [PATCH] adding throughput field in provider spec --- pkg/aws/apis/aws_provider_spec.go | 7 ++ pkg/aws/apis/validation/validation.go | 5 ++ pkg/aws/apis/validation/validation_test.go | 91 +++++++++++++++++++++- pkg/aws/core_util.go | 5 ++ pkg/aws/core_util_test.go | 2 + 5 files changed, 109 insertions(+), 1 deletion(-) diff --git a/pkg/aws/apis/aws_provider_spec.go b/pkg/aws/apis/aws_provider_spec.go index faf7ddc8..d6694dd3 100644 --- a/pkg/aws/apis/aws_provider_spec.go +++ b/pkg/aws/apis/aws_provider_spec.go @@ -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. // diff --git a/pkg/aws/apis/validation/validation.go b/pkg/aws/apis/validation/validation.go index 23a0c607..471e1d94 100644 --- a/pkg/aws/apis/validation/validation.go +++ b/pkg/aws/apis/validation/validation.go @@ -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 { diff --git a/pkg/aws/apis/validation/validation_test.go b/pkg/aws/apis/validation/validation_test.go index 3cc49725..2fd8772b 100644 --- a/pkg/aws/apis/validation/validation_test.go +++ b/pkg/aws/apis/validation/validation_test.go @@ -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" @@ -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{ @@ -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{ @@ -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{ diff --git a/pkg/aws/core_util.go b/pkg/aws/core_util.go index 16be38c3..7e3a8709 100644 --- a/pkg/aws/core_util.go +++ b/pkg/aws/core_util.go @@ -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 } diff --git a/pkg/aws/core_util_test.go b/pkg/aws/core_util_test.go index e509bef1..cf64105d 100644 --- a/pkg/aws/core_util_test.go +++ b/pkg/aws/core_util_test.go @@ -132,6 +132,7 @@ var _ = Describe("CoreUtils", func() { Iops: 1000, VolumeSize: 10, VolumeType: "gp3", + Throughput: aws.Int64(200), }, }, { @@ -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"), }, },