diff --git a/go.mod b/go.mod index 6019653c..18c65588 100644 --- a/go.mod +++ b/go.mod @@ -39,6 +39,9 @@ require ( require ( github.com/Masterminds/sprig/v3 v3.2.3 + github.com/aws/aws-sdk-go-v2 v1.30.4 + github.com/aws/aws-sdk-go-v2/config v1.27.31 + github.com/aws/aws-sdk-go-v2/service/ec2 v1.177.0 github.com/luci/go-render v0.0.0-20160219211803-9a04cc21af0f github.com/samber/lo v1.46.0 sigs.k8s.io/aws-iam-authenticator v0.6.22 @@ -49,6 +52,17 @@ require ( github.com/Masterminds/semver/v3 v3.2.1 // indirect github.com/alecthomas/units v0.0.0-20240626203959-61d1e3462e30 // indirect github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect + github.com/aws/aws-sdk-go-v2/credentials v1.17.30 // indirect + github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.12 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.16 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.16 // indirect + github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.4 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.18 // indirect + github.com/aws/aws-sdk-go-v2/service/sso v1.22.5 // indirect + github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.5 // indirect + github.com/aws/aws-sdk-go-v2/service/sts v1.30.5 // indirect + github.com/aws/smithy-go v1.20.4 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/emicklei/go-restful/v3 v3.12.1 // indirect diff --git a/go.sum b/go.sum index 99f81a1e..dc9a66c6 100644 --- a/go.sum +++ b/go.sum @@ -13,6 +13,34 @@ github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3d github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU= github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU= +github.com/aws/aws-sdk-go-v2 v1.30.4 h1:frhcagrVNrzmT95RJImMHgabt99vkXGslubDaDagTk8= +github.com/aws/aws-sdk-go-v2 v1.30.4/go.mod h1:CT+ZPWXbYrci8chcARI3OmI/qgd+f6WtuLOoaIA8PR0= +github.com/aws/aws-sdk-go-v2/config v1.27.31 h1:kxBoRsjhT3pq0cKthgj6RU6bXTm/2SgdoUMyrVw0rAI= +github.com/aws/aws-sdk-go-v2/config v1.27.31/go.mod h1:z04nZdSWFPaDwK3DdJOG2r+scLQzMYuJeW0CujEm9FM= +github.com/aws/aws-sdk-go-v2/credentials v1.17.30 h1:aau/oYFtibVovr2rDt8FHlU17BTicFEMAi29V1U+L5Q= +github.com/aws/aws-sdk-go-v2/credentials v1.17.30/go.mod h1:BPJ/yXV92ZVq6G8uYvbU0gSl8q94UB63nMT5ctNO38g= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.12 h1:yjwoSyDZF8Jth+mUk5lSPJCkMC0lMy6FaCD51jm6ayE= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.12/go.mod h1:fuR57fAgMk7ot3WcNQfb6rSEn+SUffl7ri+aa8uKysI= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.16 h1:TNyt/+X43KJ9IJJMjKfa3bNTiZbUP7DeCxfbTROESwY= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.16/go.mod h1:2DwJF39FlNAUiX5pAc0UNeiz16lK2t7IaFcm0LFHEgc= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.16 h1:jYfy8UPmd+6kJW5YhY0L1/KftReOGxI/4NtVSTh9O/I= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.16/go.mod h1:7ZfEPZxkW42Afq4uQB8H2E2e6ebh6mXTueEpYzjCzcs= +github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 h1:VaRN3TlFdd6KxX1x3ILT5ynH6HvKgqdiXoTxAF4HQcQ= +github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1/go.mod h1:FbtygfRFze9usAadmnGJNc8KsP346kEe+y2/oyhGAGc= +github.com/aws/aws-sdk-go-v2/service/ec2 v1.177.0 h1:LAdDRIj5BEZM9fLDTUWUyPzWvv5A++nCEps/RGmZNOo= +github.com/aws/aws-sdk-go-v2/service/ec2 v1.177.0/go.mod h1:ISODge3zgdwOEa4Ou6WM9PKbxJWJ15DYKnr2bfmCAIA= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.4 h1:KypMCbLPPHEmf9DgMGw51jMj77VfGPAN2Kv4cfhlfgI= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.4/go.mod h1:Vz1JQXliGcQktFTN/LN6uGppAIRoLBR2bMvIMP0gOjc= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.18 h1:tJ5RnkHCiSH0jyd6gROjlJtNwov0eGYNz8s8nFcR0jQ= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.18/go.mod h1:++NHzT+nAF7ZPrHPsA+ENvsXkOO8wEu+C6RXltAG4/c= +github.com/aws/aws-sdk-go-v2/service/sso v1.22.5 h1:zCsFCKvbj25i7p1u94imVoO447I/sFv8qq+lGJhRN0c= +github.com/aws/aws-sdk-go-v2/service/sso v1.22.5/go.mod h1:ZeDX1SnKsVlejeuz41GiajjZpRSWR7/42q/EyA/QEiM= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.5 h1:SKvPgvdvmiTWoi0GAJ7AsJfOz3ngVkD/ERbs5pUnHNI= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.5/go.mod h1:20sz31hv/WsPa3HhU3hfrIet2kxM4Pe0r20eBZ20Tac= +github.com/aws/aws-sdk-go-v2/service/sts v1.30.5 h1:OMsEmCyz2i89XwRwPouAJvhj81wINh+4UK+k/0Yo/q8= +github.com/aws/aws-sdk-go-v2/service/sts v1.30.5/go.mod h1:vmSqFK+BVIwVpDAGZB3CoCXHzurt4qBE8lf+I/kRTh0= +github.com/aws/smithy-go v1.20.4 h1:2HK1zBdPgRbjFOHlfeQZfpC4r72MOb9bZkiFwggKO+4= +github.com/aws/smithy-go v1.20.4/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= diff --git a/pkg/aws/instance_info.go b/pkg/aws/instance_info.go index 948ea859..a19e752d 100644 --- a/pkg/aws/instance_info.go +++ b/pkg/aws/instance_info.go @@ -1,11 +1,12 @@ package aws import ( + "context" "fmt" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/aws/aws-sdk-go/service/ec2/ec2iface" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" + "github.com/aws/aws-sdk-go-v2/service/ec2/types" log "github.com/sirupsen/logrus" ) @@ -21,9 +22,9 @@ const ( type Instance struct { InstanceType string - VCPU int64 + VCPU int32 Memory int64 - InstanceStorageDevices int64 + InstanceStorageDevices int32 InstanceStorageDeviceSize int64 Architecture string } @@ -32,7 +33,7 @@ func (i Instance) AvailableStorage(instanceStorageScaleFactor float64, rootVolum if i.InstanceStorageDevices == 0 { return int64(float64(rootVolumeSize) * rootVolumeScaleFactor) } - return int64(instanceStorageScaleFactor * float64(i.InstanceStorageDevices*i.InstanceStorageDeviceSize)) + return int64(instanceStorageScaleFactor * float64(int64(i.InstanceStorageDevices)*i.InstanceStorageDeviceSize)) } func (i Instance) MemoryFraction(percent int64) int64 { @@ -51,14 +52,23 @@ func NewInstanceTypes(instanceData []Instance) *InstanceTypes { return &InstanceTypes{instances: result} } -func NewInstanceTypesFromAWS(ec2client ec2iface.EC2API) (*InstanceTypes, error) { +func NewInstanceTypesFromAWS(ec2client EC2API) (*InstanceTypes, error) { instances := make(map[string]Instance) var innerErr error - err := ec2client.DescribeInstanceTypesPages(&ec2.DescribeInstanceTypesInput{}, func(output *ec2.DescribeInstanceTypesOutput, _ bool) bool { + + paginator := ec2.NewDescribeInstanceTypesPaginator(ec2client, &ec2.DescribeInstanceTypesInput{}) + +pagination: + for paginator.HasMorePages() { + output, err := paginator.NextPage(context.TODO()) + if err != nil { + return nil, err + } for _, instanceType := range output.InstanceTypes { var ( - deviceCount, deviceSize int64 + deviceCount int32 + deviceSize int64 ) if instanceType.InstanceStorageInfo != nil { @@ -67,12 +77,12 @@ func NewInstanceTypesFromAWS(ec2client ec2iface.EC2API) (*InstanceTypes, error) case 0: // do nothing case 1: - deviceCount = aws.Int64Value(storageDisks[0].Count) - deviceSize = aws.Int64Value(storageDisks[0].SizeInGB) * gigabyte + deviceCount = aws.ToInt32(storageDisks[0].Count) + deviceSize = aws.ToInt64(storageDisks[0].SizeInGB) * gigabyte default: // doesn't happen at the moment, raise an error so we can decide how to handle this - innerErr = fmt.Errorf("invalid number of disk sets (%d) for %s, expecting 0 or 1", len(storageDisks), aws.StringValue(instanceType.InstanceType)) - return false + innerErr = fmt.Errorf("invalid number of disk sets (%d) for %s, expecting 0 or 1", len(storageDisks), string(instanceType.InstanceType)) + break pagination } } @@ -84,24 +94,20 @@ func NewInstanceTypesFromAWS(ec2client ec2iface.EC2API) (*InstanceTypes, error) } info := Instance{ - InstanceType: aws.StringValue(instanceType.InstanceType), - VCPU: aws.Int64Value(instanceType.VCpuInfo.DefaultVCpus), - Memory: aws.Int64Value(instanceType.MemoryInfo.SizeInMiB) * mebibyte, + InstanceType: string(instanceType.InstanceType), + VCPU: aws.ToInt32(instanceType.VCpuInfo.DefaultVCpus), + Memory: aws.ToInt64(instanceType.MemoryInfo.SizeInMiB) * mebibyte, InstanceStorageDevices: deviceCount, InstanceStorageDeviceSize: deviceSize, Architecture: cpuArch, } instances[info.InstanceType] = info } - return true - }) + + } if innerErr != nil { return nil, innerErr } - if err != nil { - return nil, err - } - log.Debugf("Loaded %d instance types from AWS", len(instances)) return &InstanceTypes{instances: instances}, nil } @@ -155,27 +161,27 @@ func (types *InstanceTypes) SyntheticInstanceInfo(instanceTypes []string) (Insta // getCompatibleCPUArchitecture returns a single compatible CPU architecture. It's either `amd64` or `arm64`. // Other intance types might return 32-bit or macos specific types which will be ignored. -func getCompatibleCPUArchitecture(instanceType *ec2.InstanceTypeInfo) (string, error) { - supportedArchitectures := aws.StringValueSlice(instanceType.ProcessorInfo.SupportedArchitectures) +func getCompatibleCPUArchitecture(instanceType types.InstanceTypeInfo) (string, error) { + supportedArchitectures := instanceType.ProcessorInfo.SupportedArchitectures - if contains(supportedArchitectures, archX86_64) { + if contains(supportedArchitectures, types.ArchitectureTypeX8664) { return archAMD64, nil } - if contains(supportedArchitectures, archARM64) { + if contains(supportedArchitectures, types.ArchitectureTypeArm64) { return archARM64, nil } return "", fmt.Errorf("didn't find compatible cpu architecture within '%v'", supportedArchitectures) } -func min(a int64, b int64) int64 { +func min[T int64 | int32](a T, b T) T { if a < b { return a } return b } -func contains(s []string, e string) bool { +func contains[T string | types.ArchitectureType](s []T, e T) bool { for _, a := range s { if a == e { return true diff --git a/pkg/aws/instance_info_test.go b/pkg/aws/instance_info_test.go index 70af18d1..782caca4 100644 --- a/pkg/aws/instance_info_test.go +++ b/pkg/aws/instance_info_test.go @@ -1,195 +1,191 @@ package aws import ( + "context" "testing" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/aws/aws-sdk-go/service/ec2/ec2iface" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" + "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/stretchr/testify/require" ) type mockEC2 struct { - ec2iface.EC2API + EC2API } -func (mock *mockEC2) DescribeInstanceTypesPages(_ *ec2.DescribeInstanceTypesInput, callback func(*ec2.DescribeInstanceTypesOutput, bool) bool) error { - if !callback(&ec2.DescribeInstanceTypesOutput{ - InstanceTypes: []*ec2.InstanceTypeInfo{ +func (mock *mockEC2) DescribeInstanceTypes(_ context.Context, _ *ec2.DescribeInstanceTypesInput, _ ...func(*ec2.Options)) (*ec2.DescribeInstanceTypesOutput, error) { + + output := &ec2.DescribeInstanceTypesOutput{ + InstanceTypes: []types.InstanceTypeInfo{ { - InstanceType: aws.String("m4.xlarge"), - VCpuInfo: &ec2.VCpuInfo{ - DefaultVCpus: aws.Int64(4), + InstanceType: "m4.xlarge", + VCpuInfo: &types.VCpuInfo{ + DefaultVCpus: aws.Int32(4), }, - MemoryInfo: &ec2.MemoryInfo{ + MemoryInfo: &types.MemoryInfo{ SizeInMiB: aws.Int64(16384), }, - InstanceStorageInfo: &ec2.InstanceStorageInfo{}, - ProcessorInfo: &ec2.ProcessorInfo{ + InstanceStorageInfo: &types.InstanceStorageInfo{}, + ProcessorInfo: &types.ProcessorInfo{ // Test that unsupported architectures are correctly ignored. - SupportedArchitectures: []*string{aws.String("x86_64_mac"), aws.String("i386"), aws.String("x86_64")}, + SupportedArchitectures: []types.ArchitectureType{"x86_64_mac", "i386", "x86_64"}, }, }, { - InstanceType: aws.String("i3.4xlarge"), - VCpuInfo: &ec2.VCpuInfo{ - DefaultVCpus: aws.Int64(16), + InstanceType: "i3.4xlarge", + VCpuInfo: &types.VCpuInfo{ + DefaultVCpus: aws.Int32(16), }, - MemoryInfo: &ec2.MemoryInfo{ + MemoryInfo: &types.MemoryInfo{ SizeInMiB: aws.Int64(124928), }, - InstanceStorageInfo: &ec2.InstanceStorageInfo{ - Disks: []*ec2.DiskInfo{ + InstanceStorageInfo: &types.InstanceStorageInfo{ + Disks: []types.DiskInfo{ { - Count: aws.Int64(2), + Count: aws.Int32(2), SizeInGB: aws.Int64(1900), }, }, }, - ProcessorInfo: &ec2.ProcessorInfo{ - SupportedArchitectures: []*string{aws.String("x86_64")}, + ProcessorInfo: &types.ProcessorInfo{ + SupportedArchitectures: []types.ArchitectureType{"x86_64"}, }, }, { - InstanceType: aws.String("m5.xlarge"), - VCpuInfo: &ec2.VCpuInfo{ - DefaultVCpus: aws.Int64(4), + InstanceType: "m5.xlarge", + VCpuInfo: &types.VCpuInfo{ + DefaultVCpus: aws.Int32(4), }, - MemoryInfo: &ec2.MemoryInfo{ + MemoryInfo: &types.MemoryInfo{ SizeInMiB: aws.Int64(16384), }, - InstanceStorageInfo: &ec2.InstanceStorageInfo{}, - ProcessorInfo: &ec2.ProcessorInfo{ - SupportedArchitectures: []*string{aws.String("x86_64")}, + InstanceStorageInfo: &types.InstanceStorageInfo{}, + ProcessorInfo: &types.ProcessorInfo{ + SupportedArchitectures: []types.ArchitectureType{"x86_64"}, }, }, { - InstanceType: aws.String("m5d.4xlarge"), - VCpuInfo: &ec2.VCpuInfo{ - DefaultVCpus: aws.Int64(16), + InstanceType: "m5d.4xlarge", + VCpuInfo: &types.VCpuInfo{ + DefaultVCpus: aws.Int32(16), }, - MemoryInfo: &ec2.MemoryInfo{ + MemoryInfo: &types.MemoryInfo{ SizeInMiB: aws.Int64(65536), }, - InstanceStorageInfo: &ec2.InstanceStorageInfo{ - Disks: []*ec2.DiskInfo{ + InstanceStorageInfo: &types.InstanceStorageInfo{ + Disks: []types.DiskInfo{ { - Count: aws.Int64(2), + Count: aws.Int32(2), SizeInGB: aws.Int64(300), }, }, }, - ProcessorInfo: &ec2.ProcessorInfo{ - SupportedArchitectures: []*string{aws.String("x86_64")}, + ProcessorInfo: &types.ProcessorInfo{ + SupportedArchitectures: []types.ArchitectureType{"x86_64"}, }, }, { - InstanceType: aws.String("m6g.xlarge"), - VCpuInfo: &ec2.VCpuInfo{ - DefaultVCpus: aws.Int64(4), + InstanceType: "m6g.xlarge", + VCpuInfo: &types.VCpuInfo{ + DefaultVCpus: aws.Int32(4), }, - MemoryInfo: &ec2.MemoryInfo{ + MemoryInfo: &types.MemoryInfo{ SizeInMiB: aws.Int64(16384), }, - ProcessorInfo: &ec2.ProcessorInfo{ - SupportedArchitectures: []*string{aws.String("arm64")}, + ProcessorInfo: &types.ProcessorInfo{ + SupportedArchitectures: []types.ArchitectureType{"arm64"}, }, }, - }, - }, false) { - return nil - } - callback(&ec2.DescribeInstanceTypesOutput{ - InstanceTypes: []*ec2.InstanceTypeInfo{ { - InstanceType: aws.String("c5d.xlarge"), - VCpuInfo: &ec2.VCpuInfo{ - DefaultVCpus: aws.Int64(4), + InstanceType: types.InstanceTypeC5dXlarge, + VCpuInfo: &types.VCpuInfo{ + DefaultVCpus: aws.Int32(4), }, - MemoryInfo: &ec2.MemoryInfo{ + MemoryInfo: &types.MemoryInfo{ SizeInMiB: aws.Int64(8192), }, - InstanceStorageInfo: &ec2.InstanceStorageInfo{ - Disks: []*ec2.DiskInfo{ + InstanceStorageInfo: &types.InstanceStorageInfo{ + Disks: []types.DiskInfo{ { - Count: aws.Int64(1), + Count: aws.Int32(1), SizeInGB: aws.Int64(100), }, }, }, - ProcessorInfo: &ec2.ProcessorInfo{ - SupportedArchitectures: []*string{aws.String("x86_64")}, + ProcessorInfo: &types.ProcessorInfo{ + SupportedArchitectures: []types.ArchitectureType{types.ArchitectureTypeX8664}, }, }, { - InstanceType: aws.String("r5d.xlarge"), - VCpuInfo: &ec2.VCpuInfo{ - DefaultVCpus: aws.Int64(4), + InstanceType: "r5d.xlarge", + VCpuInfo: &types.VCpuInfo{ + DefaultVCpus: aws.Int32(4), }, - MemoryInfo: &ec2.MemoryInfo{ + MemoryInfo: &types.MemoryInfo{ SizeInMiB: aws.Int64(32768), }, - InstanceStorageInfo: &ec2.InstanceStorageInfo{ - Disks: []*ec2.DiskInfo{ + InstanceStorageInfo: &types.InstanceStorageInfo{ + Disks: []types.DiskInfo{ { - Count: aws.Int64(1), + Count: aws.Int32(1), SizeInGB: aws.Int64(150), }, }, }, - ProcessorInfo: &ec2.ProcessorInfo{ - SupportedArchitectures: []*string{aws.String("x86_64")}, + ProcessorInfo: &types.ProcessorInfo{ + SupportedArchitectures: []types.ArchitectureType{"x86_64"}, }, }, { - InstanceType: aws.String("m5d.xlarge"), - VCpuInfo: &ec2.VCpuInfo{ - DefaultVCpus: aws.Int64(4), + InstanceType: "m5d.xlarge", + VCpuInfo: &types.VCpuInfo{ + DefaultVCpus: aws.Int32(4), }, - MemoryInfo: &ec2.MemoryInfo{ + MemoryInfo: &types.MemoryInfo{ SizeInMiB: aws.Int64(16384), }, - InstanceStorageInfo: &ec2.InstanceStorageInfo{ - Disks: []*ec2.DiskInfo{ + InstanceStorageInfo: &types.InstanceStorageInfo{ + Disks: []types.DiskInfo{ { - Count: aws.Int64(1), + Count: aws.Int32(1), SizeInGB: aws.Int64(150), }, }, }, - ProcessorInfo: &ec2.ProcessorInfo{ - SupportedArchitectures: []*string{aws.String("x86_64")}, + ProcessorInfo: &types.ProcessorInfo{ + SupportedArchitectures: []types.ArchitectureType{"x86_64"}, }, }, { - InstanceType: aws.String("r5d.large"), - VCpuInfo: &ec2.VCpuInfo{ - DefaultVCpus: aws.Int64(2), + InstanceType: "r5d.large", + VCpuInfo: &types.VCpuInfo{ + DefaultVCpus: aws.Int32(2), }, - MemoryInfo: &ec2.MemoryInfo{ + MemoryInfo: &types.MemoryInfo{ SizeInMiB: aws.Int64(16384), }, - InstanceStorageInfo: &ec2.InstanceStorageInfo{ - Disks: []*ec2.DiskInfo{ + InstanceStorageInfo: &types.InstanceStorageInfo{ + Disks: []types.DiskInfo{ { - Count: aws.Int64(1), + Count: aws.Int32(1), SizeInGB: aws.Int64(75), }, }, }, - ProcessorInfo: &ec2.ProcessorInfo{ - SupportedArchitectures: []*string{aws.String("x86_64")}, + ProcessorInfo: &types.ProcessorInfo{ + SupportedArchitectures: []types.ArchitectureType{"x86_64"}, }, }, }, - }, false) - return nil + } + return output, nil } func TestAvailableStorage(t *testing.T) { for _, tc := range []struct { name string - devices int64 + devices int32 deviceSize int64 expected int64 }{ @@ -247,7 +243,7 @@ func TestInstanceInfoFromAWS(t *testing.T) { Architecture: "arm64", }, } { - t.Run(tc.InstanceType, func(t *testing.T) { + t.Run(string(tc.InstanceType), func(t *testing.T) { info, err := instanceTypes.InstanceInfo(tc.InstanceType) require.NoError(t, err) require.Equal(t, tc.InstanceType, info.InstanceType) diff --git a/pkg/aws/interface.go b/pkg/aws/interface.go new file mode 100644 index 00000000..fc72518d --- /dev/null +++ b/pkg/aws/interface.go @@ -0,0 +1,18 @@ +package aws + +import ( + "context" + + "github.com/aws/aws-sdk-go-v2/service/ec2" +) + +type EC2API interface { + DescribeInstanceTypes(context.Context, *ec2.DescribeInstanceTypesInput, ...func(*ec2.Options)) (*ec2.DescribeInstanceTypesOutput, error) + DescribeVolumes(context.Context, *ec2.DescribeVolumesInput, ...func(*ec2.Options)) (*ec2.DescribeVolumesOutput, error) + DeleteVolume(context.Context, *ec2.DeleteVolumeInput, ...func(*ec2.Options)) (*ec2.DeleteVolumeOutput, error) + DescribeVpcs(context.Context, *ec2.DescribeVpcsInput, ...func(*ec2.Options)) (*ec2.DescribeVpcsOutput, error) + DescribeSubnets(context.Context, *ec2.DescribeSubnetsInput, ...func(*ec2.Options)) (*ec2.DescribeSubnetsOutput, error) + CreateTags(context.Context, *ec2.CreateTagsInput, ...func(*ec2.Options)) (*ec2.CreateTagsOutput, error) + DeleteTags(context.Context, *ec2.DeleteTagsInput, ...func(*ec2.Options)) (*ec2.DeleteTagsOutput, error) + DescribeImages(context.Context, *ec2.DescribeImagesInput, ...func(*ec2.Options)) (*ec2.DescribeImagesOutput, error) +} diff --git a/provisioner/aws.go b/provisioner/aws.go index 841605a4..d5e50bc7 100644 --- a/provisioner/aws.go +++ b/provisioner/aws.go @@ -10,6 +10,9 @@ import ( "strings" "time" + awsconfig "github.com/aws/aws-sdk-go-v2/config" + ec2v2 "github.com/aws/aws-sdk-go-v2/service/ec2" + ec2v2types "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/session" @@ -18,8 +21,6 @@ import ( "github.com/aws/aws-sdk-go/service/autoscaling" "github.com/aws/aws-sdk-go/service/cloudformation" "github.com/aws/aws-sdk-go/service/cloudformation/cloudformationiface" - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/aws/aws-sdk-go/service/ec2/ec2iface" "github.com/aws/aws-sdk-go/service/eks" "github.com/aws/aws-sdk-go/service/eks/eksiface" "github.com/aws/aws-sdk-go/service/iam" @@ -32,6 +33,7 @@ import ( "github.com/cenkalti/backoff" log "github.com/sirupsen/logrus" "github.com/zalando-incubator/cluster-lifecycle-manager/api" + zaws "github.com/zalando-incubator/cluster-lifecycle-manager/pkg/aws" awsutil "github.com/zalando-incubator/kube-ingress-aws-controller/aws" "github.com/zalando-incubator/kube-ingress-aws-controller/certs" yaml "gopkg.in/yaml.v2" @@ -111,7 +113,7 @@ type ( s3Uploader s3UploaderAPI autoscalingClient autoscalingAPI iamClient iamiface.IAMAPI - ec2Client ec2iface.EC2API + ec2Client zaws.EC2API acmClient acmiface.ACMAPI eksClient eksiface.EKSAPI region string @@ -131,6 +133,10 @@ type ( // newAWSAdapter initializes a new awsAdapter. func newAWSAdapter(logger *log.Entry, apiServer string, region string, sess *session.Session, dryRun bool) *awsAdapter { + cfg, err := awsconfig.LoadDefaultConfig(context.TODO()) + if err != nil { + logger.Fatalf("failed to load AWS config: %v", err) + } return &awsAdapter{ session: sess, cloudformationClient: cloudformation.New(sess), @@ -138,7 +144,7 @@ func newAWSAdapter(logger *log.Entry, apiServer string, region string, sess *ses s3Client: s3.New(sess), s3Uploader: s3manager.NewUploader(sess), autoscalingClient: autoscaling.New(sess), - ec2Client: ec2.New(sess), + ec2Client: ec2v2.NewFromConfig(cfg), acmClient: acm.New(sess), eksClient: eks.New(sess), region: region, @@ -557,17 +563,17 @@ func (a *awsAdapter) createS3Bucket(bucket string) error { backoff.WithMaxRetries(backoff.NewExponentialBackOff(), 10)) } -func (a *awsAdapter) GetVolumes(tags map[string]string) ([]*ec2.Volume, error) { - var filters []*ec2.Filter +func (a *awsAdapter) GetVolumes(tags map[string]string) ([]ec2v2types.Volume, error) { + var filters []ec2v2types.Filter for tagKey, tagValue := range tags { - filters = append(filters, &ec2.Filter{ + filters = append(filters, ec2v2types.Filter{ Name: aws.String(fmt.Sprintf("tag:%s", tagKey)), - Values: []*string{aws.String(tagValue)}, + Values: []string{tagValue}, }) } - result, err := a.ec2Client.DescribeVolumes(&ec2.DescribeVolumesInput{Filters: filters}) + result, err := a.ec2Client.DescribeVolumes(context.TODO(), &ec2v2.DescribeVolumesInput{Filters: filters}) if err != nil { return nil, err } @@ -575,7 +581,7 @@ func (a *awsAdapter) GetVolumes(tags map[string]string) ([]*ec2.Volume, error) { } func (a *awsAdapter) DeleteVolume(id string) error { - _, err := a.ec2Client.DeleteVolume(&ec2.DeleteVolumeInput{ + _, err := a.ec2Client.DeleteVolume(context.TODO(), &ec2v2.DeleteVolumeInput{ VolumeId: aws.String(id), }) return err @@ -632,21 +638,21 @@ func (a *awsAdapter) getCertificateSummaryFromACM(arn *string) (*certs.Certifica } // GetDefaultVPC gets the default VPC. -func (a *awsAdapter) GetDefaultVPC() (*ec2.Vpc, error) { +func (a *awsAdapter) GetDefaultVPC() (*ec2v2types.Vpc, error) { // find default VPC - vpcResp, err := a.ec2Client.DescribeVpcs(&ec2.DescribeVpcsInput{}) + vpcResp, err := a.ec2Client.DescribeVpcs(context.TODO(), &ec2v2.DescribeVpcsInput{}) if err != nil { return nil, err } if len(vpcResp.Vpcs) == 1 { - return vpcResp.Vpcs[0], nil + return &vpcResp.Vpcs[0], nil } - var defaultVpc *ec2.Vpc + var defaultVpc *ec2v2types.Vpc for _, vpc := range vpcResp.Vpcs { if aws.BoolValue(vpc.IsDefault) { - defaultVpc = vpc + defaultVpc = &vpc break } } @@ -659,10 +665,10 @@ func (a *awsAdapter) GetDefaultVPC() (*ec2.Vpc, error) { } // GetVPC gets VPC details for vpc specified by vpcID. -func (a *awsAdapter) GetVPC(vpcID string) (*ec2.Vpc, error) { +func (a *awsAdapter) GetVPC(vpcID string) (*ec2v2types.Vpc, error) { // find default VPC - vpcResp, err := a.ec2Client.DescribeVpcs(&ec2.DescribeVpcsInput{ - VpcIds: []*string{aws.String(vpcID)}, + vpcResp, err := a.ec2Client.DescribeVpcs(context.TODO(), &ec2v2.DescribeVpcsInput{ + VpcIds: []string{vpcID}, }) if err != nil { return nil, err @@ -672,21 +678,21 @@ func (a *awsAdapter) GetVPC(vpcID string) (*ec2.Vpc, error) { return nil, fmt.Errorf("found %d VPC for VPCID %s, expected 1", len(vpcResp.Vpcs), vpcID) } - return vpcResp.Vpcs[0], nil + return &vpcResp.Vpcs[0], nil } // GetSubnets gets all subnets of the default VPC in the target account. -func (a *awsAdapter) GetSubnets(vpcID string) ([]*ec2.Subnet, error) { - subnetParams := &ec2.DescribeSubnetsInput{ - Filters: []*ec2.Filter{ +func (a *awsAdapter) GetSubnets(vpcID string) ([]ec2v2types.Subnet, error) { + subnetParams := &ec2v2.DescribeSubnetsInput{ + Filters: []ec2v2types.Filter{ { Name: aws.String("vpc-id"), - Values: []*string{aws.String(vpcID)}, + Values: []string{vpcID}, }, }, } - subnetResp, err := a.ec2Client.DescribeSubnets(subnetParams) + subnetResp, err := a.ec2Client.DescribeSubnets(context.TODO(), subnetParams) if err != nil { return nil, err } @@ -695,24 +701,24 @@ func (a *awsAdapter) GetSubnets(vpcID string) ([]*ec2.Subnet, error) { } // CreateTags adds or updates tags of a kubernetes.Resource. -func (a *awsAdapter) CreateTags(resource string, tags []*ec2.Tag) error { - params := &ec2.CreateTagsInput{ - Resources: []*string{aws.String(resource)}, +func (a *awsAdapter) CreateTags(resource string, tags []ec2v2types.Tag) error { + params := &ec2v2.CreateTagsInput{ + Resources: []string{resource}, Tags: tags, } - _, err := a.ec2Client.CreateTags(params) + _, err := a.ec2Client.CreateTags(context.TODO(), params) return err } // DeleteTags deletes tags from a kubernetes.Resource. -func (a *awsAdapter) DeleteTags(resource string, tags []*ec2.Tag) error { - params := &ec2.DeleteTagsInput{ - Resources: []*string{aws.String(resource)}, +func (a *awsAdapter) DeleteTags(resource string, tags []ec2v2types.Tag) error { + params := &ec2v2.DeleteTagsInput{ + Resources: []string{resource}, Tags: tags, } - _, err := a.ec2Client.DeleteTags(params) + _, err := a.ec2Client.DeleteTags(context.TODO(), params) return err } @@ -760,7 +766,7 @@ func isStackUpdateInProgressErr(err error) bool { } // tagsToMap converts a list of ec2 tags to a map. -func tagsToMap(tags []*ec2.Tag) map[string]string { +func tagsToMap(tags []ec2v2types.Tag) map[string]string { tagMap := make(map[string]string, len(tags)) for _, tag := range tags { tagMap[aws.StringValue(tag.Key)] = aws.StringValue(tag.Value) diff --git a/provisioner/aws_test.go b/provisioner/aws_test.go index 2b3c3176..7a99ca34 100644 --- a/provisioner/aws_test.go +++ b/provisioner/aws_test.go @@ -10,14 +10,14 @@ import ( "testing" "time" + ec2v2 "github.com/aws/aws-sdk-go-v2/service/ec2" + ec2v2types "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/autoscaling" "github.com/aws/aws-sdk-go/service/cloudformation" "github.com/aws/aws-sdk-go/service/cloudformation/cloudformationiface" - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/aws/aws-sdk-go/service/ec2/ec2iface" "github.com/aws/aws-sdk-go/service/kms" "github.com/aws/aws-sdk-go/service/kms/kmsiface" "github.com/aws/aws-sdk-go/service/s3" @@ -25,20 +25,21 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/zalando-incubator/cluster-lifecycle-manager/api" + zaws "github.com/zalando-incubator/cluster-lifecycle-manager/pkg/aws" log "github.com/sirupsen/logrus" ) type ec2APIStub struct { - ec2iface.EC2API + zaws.EC2API } -func (e *ec2APIStub) DescribeVpcs(*ec2.DescribeVpcsInput) ( - *ec2.DescribeVpcsOutput, +func (e *ec2APIStub) DescribeVpcs(context.Context, *ec2v2.DescribeVpcsInput, ...func(*ec2v2.Options)) ( + *ec2v2.DescribeVpcsOutput, error, ) { - return &ec2.DescribeVpcsOutput{ - Vpcs: []*ec2.Vpc{{IsDefault: aws.Bool(false)}}, + return &ec2v2.DescribeVpcsOutput{ + Vpcs: []ec2v2types.Vpc{{IsDefault: aws.Bool(false)}}, }, nil } diff --git a/provisioner/clusterpy.go b/provisioner/clusterpy.go index 8bca9506..0400a88e 100644 --- a/provisioner/clusterpy.go +++ b/provisioner/clusterpy.go @@ -10,6 +10,7 @@ import ( "strings" "time" + ec2v2types "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/cloudformation" "github.com/aws/aws-sdk-go/service/ec2" @@ -174,7 +175,7 @@ func (p *clusterpyProvisioner) provision( } // get VPC information - var vpc *ec2.Vpc + var vpc *ec2v2types.Vpc vpcID, ok := cluster.ConfigItems[vpcIDConfigItemKey] if !ok { // if vpcID is not defined, autodiscover it vpc, err = awsAdapter.GetDefaultVPC() @@ -572,8 +573,8 @@ func createOrUpdateClusterStack(ctx context.Context, config channel.Config, clus return outputs, nil } -func filterSubnets(subnets []*ec2.Subnet, filter func(*ec2.Subnet) bool) []*ec2.Subnet { - var filtered []*ec2.Subnet +func filterSubnets(subnets []ec2v2types.Subnet, filter func(ec2v2types.Subnet) bool) []ec2v2types.Subnet { + var filtered []ec2v2types.Subnet for _, subnet := range subnets { if filter(subnet) { filtered = append(filtered, subnet) @@ -583,8 +584,8 @@ func filterSubnets(subnets []*ec2.Subnet, filter func(*ec2.Subnet) bool) []*ec2. return filtered } -func subnetIDIncluded(ids []string) func(*ec2.Subnet) bool { - return func(subnet *ec2.Subnet) bool { +func subnetIDIncluded(ids []string) func(ec2v2types.Subnet) bool { + return func(subnet ec2v2types.Subnet) bool { for _, id := range ids { if aws.StringValue(subnet.SubnetId) == id { return true @@ -595,7 +596,7 @@ func subnetIDIncluded(ids []string) func(*ec2.Subnet) bool { } } -func isCustomSubnet(subnet *ec2.Subnet) bool { +func isCustomSubnet(subnet ec2v2types.Subnet) bool { for _, tag := range subnet.Tags { if aws.StringValue(tag.Key) == customSubnetTag { return true @@ -605,8 +606,8 @@ func isCustomSubnet(subnet *ec2.Subnet) bool { return false } -func subnetNot(predicate func(*ec2.Subnet) bool) func(*ec2.Subnet) bool { - return func(s *ec2.Subnet) bool { +func subnetNot(predicate func(ec2v2types.Subnet) bool) func(ec2v2types.Subnet) bool { + return func(s ec2v2types.Subnet) bool { return !predicate(s) } } @@ -617,8 +618,8 @@ func subnetNot(predicate func(*ec2.Subnet) bool) func(*ec2.Subnet) bool { // kube-controller-manager when finding subnets for ELBs used for services of // type LoadBalancer. // https://github.com/kubernetes/kubernetes/blob/65efeee64f772e0f38037e91a677138a335a7570/pkg/cloudprovider/providers/aws/aws.go#L2949-L3027 -func selectSubnetIDs(subnets []*ec2.Subnet) *AZInfo { - subnetsByAZ := make(map[string]*ec2.Subnet) +func selectSubnetIDs(subnets []ec2v2types.Subnet) *AZInfo { + subnetsByAZ := make(map[string]ec2v2types.Subnet) for _, subnet := range subnets { az := aws.StringValue(subnet.AvailabilityZone) @@ -758,16 +759,16 @@ func (p *clusterpyProvisioner) removeEBSVolumes(awsAdapter *awsAdapter, cluster } for _, volume := range volumes { - switch aws.StringValue(volume.State) { - case ec2.VolumeStateDeleted, ec2.VolumeStateDeleting: + switch volume.State { + case ec2v2types.VolumeStateDeleted, ec2v2types.VolumeStateDeleting: // skip - case ec2.VolumeStateAvailable: + case ec2v2types.VolumeStateAvailable: err := awsAdapter.DeleteVolume(aws.StringValue(volume.VolumeId)) if err != nil { return fmt.Errorf("failed to delete EBS volume %s: %s", aws.StringValue(volume.VolumeId), err) } default: - return fmt.Errorf("unable to delete EBS volume %s: volume in state %s", aws.StringValue(volume.VolumeId), aws.StringValue(volume.State)) + return fmt.Errorf("unable to delete EBS volume %s: volume in state %s", aws.StringValue(volume.VolumeId), string(volume.State)) } } diff --git a/provisioner/clusterpy_test.go b/provisioner/clusterpy_test.go index 1eab4968..31f9d37b 100644 --- a/provisioner/clusterpy_test.go +++ b/provisioner/clusterpy_test.go @@ -10,6 +10,7 @@ import ( "testing" "time" + ec2v2types "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" log "github.com/sirupsen/logrus" @@ -146,14 +147,14 @@ func TestFilterSubnets(tt *testing.T) { tt.Run("configured IDs", func(tt *testing.T) { for _, tc := range []struct { msg string - subnets []*ec2.Subnet + subnets []ec2v2types.Subnet subnetIDs []string - expectedSubnets []*ec2.Subnet + expectedSubnets []ec2v2types.Subnet }{ { msg: "test filtering out a single subnet", - subnets: []*ec2.Subnet{ + subnets: []ec2v2types.Subnet{ { SubnetId: aws.String("id-1"), }, @@ -162,7 +163,7 @@ func TestFilterSubnets(tt *testing.T) { }, }, subnetIDs: []string{"id-1"}, - expectedSubnets: []*ec2.Subnet{ + expectedSubnets: []ec2v2types.Subnet{ { SubnetId: aws.String("id-1"), }, @@ -170,7 +171,7 @@ func TestFilterSubnets(tt *testing.T) { }, { msg: "test filtering invalid subnets", - subnets: []*ec2.Subnet{ + subnets: []ec2v2types.Subnet{ { SubnetId: aws.String("id-1"), }, @@ -189,17 +190,17 @@ func TestFilterSubnets(tt *testing.T) { tt.Run("ignore custom", func(tt *testing.T) { for _, test := range []struct { msg string - subnets, expectedSubnets []*ec2.Subnet + subnets, expectedSubnets []ec2v2types.Subnet }{{ msg: "has no custom", - subnets: []*ec2.Subnet{{ + subnets: []ec2v2types.Subnet{{ SubnetId: aws.String("id-1"), }, { SubnetId: aws.String("id-2"), }, { SubnetId: aws.String("id-3"), }}, - expectedSubnets: []*ec2.Subnet{{ + expectedSubnets: []ec2v2types.Subnet{{ SubnetId: aws.String("id-1"), }, { SubnetId: aws.String("id-2"), @@ -208,18 +209,18 @@ func TestFilterSubnets(tt *testing.T) { }}, }, { msg: "has custom", - subnets: []*ec2.Subnet{{ + subnets: []ec2v2types.Subnet{{ SubnetId: aws.String("id-1"), }, { SubnetId: aws.String("id-2"), - Tags: []*ec2.Tag{{ + Tags: []ec2v2types.Tag{{ Key: aws.String(customSubnetTag), Value: aws.String("foo"), }}, }, { SubnetId: aws.String("id-3"), }}, - expectedSubnets: []*ec2.Subnet{{ + expectedSubnets: []ec2v2types.Subnet{{ SubnetId: aws.String("id-1"), }, { SubnetId: aws.String("id-3"), diff --git a/provisioner/template.go b/provisioner/template.go index 1699e332..b611c512 100644 --- a/provisioner/template.go +++ b/provisioner/template.go @@ -2,6 +2,7 @@ package provisioner import ( "bytes" + "context" "crypto/sha256" "crypto/x509" "encoding/base64" @@ -20,8 +21,9 @@ import ( "time" "github.com/Masterminds/sprig/v3" + ec2v2 "github.com/aws/aws-sdk-go-v2/service/ec2" + ec2v2types "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" "github.com/zalando-incubator/cluster-lifecycle-manager/api" "github.com/zalando-incubator/cluster-lifecycle-manager/channel" awsUtils "github.com/zalando-incubator/cluster-lifecycle-manager/pkg/aws" @@ -526,11 +528,11 @@ func amiID(adapter *awsAdapter, imageName, imageOwner string) (string, error) { return "", fmt.Errorf("the ec2 client is not available") } - input := ec2.DescribeImagesInput{Filters: []*ec2.Filter{ - {Name: aws.String(describeImageFilterNameName), Values: aws.StringSlice([]string{imageName})}, - {Name: aws.String(describeImageFilterNameOwner), Values: aws.StringSlice([]string{imageOwner})}, + input := ec2v2.DescribeImagesInput{Filters: []ec2v2types.Filter{ + {Name: aws.String(describeImageFilterNameName), Values: []string{imageName}}, + {Name: aws.String(describeImageFilterNameOwner), Values: []string{imageOwner}}, }} - output, err := adapter.ec2Client.DescribeImages(&input) + output, err := adapter.ec2Client.DescribeImages(context.TODO(), &input) if err != nil { return "", fmt.Errorf("failed to describe image with name %s and owner %s: %v", imageName, imageOwner, err) } diff --git a/provisioner/template_test.go b/provisioner/template_test.go index 334d3a66..c5b81bcf 100644 --- a/provisioner/template_test.go +++ b/provisioner/template_test.go @@ -1,13 +1,14 @@ package provisioner import ( + "context" "fmt" "strconv" "testing" + ec2v2 "github.com/aws/aws-sdk-go-v2/service/ec2" + ec2v2types "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/aws/aws-sdk-go/service/ec2/ec2iface" "github.com/stretchr/testify/require" "github.com/zalando-incubator/cluster-lifecycle-manager/api" awsUtils "github.com/zalando-incubator/cluster-lifecycle-manager/pkg/aws" @@ -486,22 +487,22 @@ func TestStupsNATSubnetsErrors(t *testing.T) { } type mockEC2Client struct { - ec2iface.EC2API + awsUtils.EC2API t *testing.T kubernetesImage string ownerID string - output []*ec2.Image + output []ec2v2types.Image } -func (c mockEC2Client) DescribeImages(input *ec2.DescribeImagesInput) (*ec2.DescribeImagesOutput, error) { +func (c mockEC2Client) DescribeImages(_ context.Context, input *ec2v2.DescribeImagesInput, _ ...func(*ec2v2.Options)) (*ec2v2.DescribeImagesOutput, error) { require.Len(c.t, input.Filters, 2) require.Equal(c.t, describeImageFilterNameName, *input.Filters[0].Name) require.Len(c.t, input.Filters[0].Values, 1) - require.Equal(c.t, c.kubernetesImage, *input.Filters[0].Values[0]) + require.Equal(c.t, c.kubernetesImage, input.Filters[0].Values[0]) require.Equal(c.t, describeImageFilterNameOwner, *input.Filters[1].Name) require.Len(c.t, input.Filters[1].Values, 1) - require.Equal(c.t, c.ownerID, *input.Filters[1].Values[0]) - return &ec2.DescribeImagesOutput{Images: c.output}, nil + require.Equal(c.t, c.ownerID, input.Filters[1].Values[0]) + return &ec2v2.DescribeImagesOutput{Images: c.output}, nil } func TestAmiID(t *testing.T) { @@ -510,7 +511,7 @@ func TestAmiID(t *testing.T) { imageName string ownerID string imageID string - output []*ec2.Image + output []ec2v2types.Image expectErr bool }{ { @@ -518,14 +519,14 @@ func TestAmiID(t *testing.T) { imageName: "kubernetes-image-ami", ownerID: "8085", imageID: "ami-0001dsf", - output: []*ec2.Image{{ImageId: aws.String("ami-0001dsf")}}, + output: []ec2v2types.Image{{ImageId: aws.String("ami-0001dsf")}}, expectErr: false, }, { name: "multiple images", imageName: "kubernetes-image-ami", ownerID: "8085", - output: []*ec2.Image{{ImageId: aws.String("ami-00232ccd")}, {ImageId: aws.String("ami-0001dsf")}}, + output: []ec2v2types.Image{{ImageId: aws.String("ami-00232ccd")}, {ImageId: aws.String("ami-0001dsf")}}, expectErr: true, }, } {