Skip to content

Commit

Permalink
Migrate Integration Tests to AWS SDK Go V4.
Browse files Browse the repository at this point in the history
  • Loading branch information
orsenthil committed Nov 23, 2024
1 parent 40e573e commit a7f6034
Show file tree
Hide file tree
Showing 45 changed files with 663 additions and 587 deletions.
2 changes: 1 addition & 1 deletion cmd/routed-eni-cni-plugin/cni_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/aws/amazon-vpc-cni-k8s/pkg/sgpp"
"github.com/aws/amazon-vpc-cni-k8s/pkg/utils/logger"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go-v2/aws"
current "github.com/containernetworking/cni/pkg/types/100"

"github.com/containernetworking/cni/pkg/skel"
Expand Down
22 changes: 12 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ require (
github.com/aws/amazon-vpc-cni-k8s/test/agent v0.0.0-20231212223725-21c4bd73015b
github.com/aws/amazon-vpc-resource-controller-k8s v1.5.0
github.com/aws/aws-sdk-go v1.55.5
github.com/aws/aws-sdk-go-v2 v1.32.5
github.com/aws/aws-sdk-go-v2/config v1.28.4
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.19
github.com/aws/aws-sdk-go-v2/service/autoscaling v1.50.0
github.com/aws/aws-sdk-go-v2/service/cloudformation v1.56.0
github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.43.0
github.com/aws/aws-sdk-go-v2/service/ec2 v1.189.0
github.com/aws/aws-sdk-go-v2/service/eks v1.52.1
github.com/aws/aws-sdk-go-v2/service/iam v1.38.1
github.com/aws/smithy-go v1.22.1
github.com/containernetworking/cni v1.2.3
github.com/containernetworking/plugins v1.5.1
github.com/coreos/go-iptables v0.8.0
Expand Down Expand Up @@ -50,21 +60,15 @@ require (
github.com/Masterminds/squirrel v1.5.4 // indirect
github.com/Microsoft/hcsshim v0.12.3 // indirect
github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 // indirect
github.com/aws/aws-sdk-go-v2 v1.32.4 // indirect
github.com/aws/aws-sdk-go-v2/config v1.28.4 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.45 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.19 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.23 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.23 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.24 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.24 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.43.0 // indirect
github.com/aws/aws-sdk-go-v2/service/ec2 v1.189.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.4 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.24.5 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.4 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.33.0 // indirect
github.com/aws/smithy-go v1.22.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
Expand Down Expand Up @@ -157,7 +161,6 @@ require (
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
github.com/yuin/goldmark v1.4.13 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
Expand All @@ -166,7 +169,6 @@ require (
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/term v0.21.0 // indirect
Expand Down
25 changes: 14 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,32 @@ github.com/aws/amazon-vpc-resource-controller-k8s v1.5.0 h1:utc5JzVlbORZ/4IFHb4y
github.com/aws/amazon-vpc-resource-controller-k8s v1.5.0/go.mod h1:3q5gDG44vGr9ERe0YMHItThKXxDkntAUrlfTgJkdgF8=
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.32.4 h1:S13INUiTxgrPueTmrm5DZ+MiAo99zYzHEFh1UNkOxNE=
github.com/aws/aws-sdk-go-v2 v1.32.4/go.mod h1:2SK5n0a2karNTv5tbP1SjsX0uhttou00v/HpXKM1ZUo=
github.com/aws/aws-sdk-go-v2 v1.32.5 h1:U8vdWJuY7ruAkzaOdD7guwJjD06YSKmnKCJs7s3IkIo=
github.com/aws/aws-sdk-go-v2 v1.32.5/go.mod h1:P5WJBrYqqbWVaOxgH0X/FYYD47/nooaPOZPlQdmiN2U=
github.com/aws/aws-sdk-go-v2/config v1.28.4 h1:qgD0MKmkIzZR2DrAjWJcI9UkndjR+8f6sjUQvXh0mb0=
github.com/aws/aws-sdk-go-v2/config v1.28.4/go.mod h1:LgnWnNzHZw4MLplSyEGia0WgJ/kCGD86zGCjvNpehJs=
github.com/aws/aws-sdk-go-v2/credentials v1.17.45 h1:DUgm5lFso57E7150RBgu1JpVQoF8fAPretiDStIuVjg=
github.com/aws/aws-sdk-go-v2/credentials v1.17.45/go.mod h1:dnBpENcPC1ekZrGpSWspX+ZRGzhkvqngT2Qp5xBR1dY=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.19 h1:woXadbf0c7enQ2UGCi8gW/WuKmE0xIzxBF/eD94jMKQ=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.19/go.mod h1:zminj5ucw7w0r65bP6nhyOd3xL6veAUMc3ElGMoLVb4=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.23 h1:A2w6m6Tmr+BNXjDsr7M90zkWjsu4JXHwrzPg235STs4=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.23/go.mod h1:35EVp9wyeANdujZruvHiQUAo9E3vbhnIO1mTCAxMlY0=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.23 h1:pgYW9FCabt2M25MoHYCfMrVY2ghiiBKYWUVXfwZs+sU=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.23/go.mod h1:c48kLgzO19wAu3CPkDWC28JbaJ+hfQlsdl7I2+oqIbk=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.24 h1:4usbeaes3yJnCFC7kfeyhkdkPtoRYPa/hTmCqMpKpLI=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.24/go.mod h1:5CI1JemjVwde8m2WG3cz23qHKPOxbpkq0HaoreEgLIY=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.24 h1:N1zsICrQglfzaBnrfM0Ys00860C+QFwu6u/5+LomP+o=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.24/go.mod h1:dCn9HbJ8+K31i8IQ8EWmWj0EiIk0+vKiHNMxTTYveAg=
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/autoscaling v1.50.0 h1:5tF6T8pAKna0TZ2g77jKdTCKoIRDsaYlYxz9OC1BraI=
github.com/aws/aws-sdk-go-v2/service/autoscaling v1.50.0/go.mod h1:I1+/2m+IhnK5qEbhS3CrzjeiVloo9sItE/2K+so0fkU=
github.com/aws/aws-sdk-go-v2/service/cloudformation v1.56.0 h1:zmXJiEm/fQYtFDLIUsZrcPIjTrL3R/noFICGlYBj3Ww=
github.com/aws/aws-sdk-go-v2/service/cloudformation v1.56.0/go.mod h1:9nOjXCDKE+QMK4JaCrLl36PU+VEfJmI7WVehYmojO8s=
github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.43.0 h1:r1sp92LSk4Gx8l0gScEjzSN+4iiImDvNayY9JYPNtNI=
github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.43.0/go.mod h1:fkETEwhdw2tOqu5m0Xa3wimV3PLDaiGqNrVZ3MJ7zOc=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.189.0 h1:eBriSsQa4r7aiKF2wv1EGYbK3X1VnjAYvdOlepBUi8s=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.189.0/go.mod h1:0A17IIeys01WfjDKehspGP+Cyo/YH/eNADIbEbRS9yM=
github.com/aws/aws-sdk-go-v2/service/eks v1.52.1 h1:XqyUdJbXQxY48CbBtN9a51HoTQy/kTIwrWiruRDsydk=
github.com/aws/aws-sdk-go-v2/service/eks v1.52.1/go.mod h1:WTfZ/+I7aSMEna6iYm1Kjne9A8f1MyxXNfp6hCa1+Bk=
github.com/aws/aws-sdk-go-v2/service/iam v1.38.1 h1:hfkzDZHBp9jAT4zcd5mtqckpU4E3Ax0LQaEWWk1VgN8=
github.com/aws/aws-sdk-go-v2/service/iam v1.38.1/go.mod h1:u36ahDtZcQHGmVm/r+0L1sfKX4fzLEMdCqiKRKkUMVM=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 h1:TToQNkvGguu209puTojY/ozlqy2d/SFNcoLIqTFi42g=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0/go.mod h1:0jp+ltwkf+SwG2fm/PKo8t4y8pJSgOCO4D8Lz3k0aHQ=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.4 h1:tHxQi/XHPK0ctd/wdOw0t7Xrc2OxcRCnVzv8lwWPu0c=
Expand All @@ -67,8 +75,6 @@ github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.4 h1:zcx9LiGWZ6i6pjdcoE9oXAB6
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.4/go.mod h1:Tp/ly1cTjRLGBBmNccFumbZ8oqpZlpdhFf80SrRh4is=
github.com/aws/aws-sdk-go-v2/service/sts v1.33.0 h1:s7LRgBqhwLaxcocnAniBJp7gaAB+4I4vHzqUqjH18yc=
github.com/aws/aws-sdk-go-v2/service/sts v1.33.0/go.mod h1:9XEUty5v5UAsMiFOBJrNibZgwCeOma73jgGwwhgffa8=
github.com/aws/smithy-go v1.22.0 h1:uunKnWlcoL3zO7q+gG2Pk53joueEOsnNB28QdMsmiMM=
github.com/aws/smithy-go v1.22.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
github.com/aws/smithy-go v1.22.1 h1:/HPHZQ0g7f4eUeK6HKglFz8uwVfZKgoI25rb/J+dnro=
github.com/aws/smithy-go v1.22.1/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
Expand Down Expand Up @@ -457,7 +463,6 @@ github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yvasiyarov/go-metrics v0.0.0-20140926110328-57bccd1ccd43 h1:+lm10QQTNSBd8DVTNGHx7o/IKu9HYDvLMffDhbyLccI=
github.com/yvasiyarov/go-metrics v0.0.0-20140926110328-57bccd1ccd43/go.mod h1:aX5oPXxHm3bOH+xeAttToC8pqch2ScQN/JoXYupl6xs=
Expand Down Expand Up @@ -496,8 +501,6 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand Down
3 changes: 1 addition & 2 deletions pkg/publisher/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ var (
}
)

// cloudWatchAPI is a custom interface that includes only the methods needed for your use case
// cloudWatchAPI is a custom interface that includes only the methods we need from the CloudWatch API
type cloudWatchAPI interface {
PutMetricData(ctx context.Context, params *cloudwatch.PutMetricDataInput, optFns ...func(*cloudwatch.Options)) (*cloudwatch.PutMetricDataOutput, error)
// Add other methods as needed
}

// Publisher defines the interface to publish one or more data points
Expand Down
107 changes: 56 additions & 51 deletions scripts/gen_vpc_ip_limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@
package main

import (
"context"
"fmt"
"os"
"reflect"
"sort"
"strconv"
"text/template"

"github.com/aws/aws-sdk-go-v2/aws"

"github.com/aws/aws-sdk-go-v2/config"

"github.com/aws/amazon-vpc-cni-k8s/pkg/utils/logger"
"github.com/aws/amazon-vpc-cni-k8s/pkg/vpc"

"github.com/aws/aws-sdk-go/aws"

"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/ec2"
)

const ipLimitFileName = "pkg/vpc/vpc_ip_resource_limit.go"
Expand All @@ -44,11 +46,20 @@ func printPodLimit(instanceType string, l vpc.InstanceTypeLimits) string {
}

func main() {
ctx := context.Background()

cfg, err := config.LoadDefaultConfig(ctx)

if err != nil {
log.Fatalf("Failed to load configuration: %v", err)
}

// Get instance types limits across all regions
regions := describeRegions()
regions := describeRegions(ctx, cfg)

eniLimitMap := make(map[string]vpc.InstanceTypeLimits)
for _, region := range regions {
describeInstanceTypes(region, eniLimitMap)
describeInstanceTypes(ctx, cfg, region, eniLimitMap)
}

// Override faulty values and add missing instance types
Expand Down Expand Up @@ -102,20 +113,14 @@ func main() {

// Helper function to call the EC2 DescribeRegions API, returning sorted region names
// Note that the credentials being used may not be opted-in to all regions
func describeRegions() []string {
// Get session
sess := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
}))
_, err := sess.Config.Credentials.Get()
if err != nil {
log.Fatalf("Failed to get session credentials: %v", err)
}
svc := ec2.New(sess)
output, err := svc.DescribeRegions(&ec2.DescribeRegionsInput{})
func describeRegions(ctx context.Context, cfg aws.Config) []string {
client := ec2.NewFromConfig(cfg)

output, err := client.DescribeRegions(ctx, &ec2.DescribeRegionsInput{})
if err != nil {
log.Fatalf("Failed to call EC2 DescribeRegions: %v", err)
}

var regionNames []string
for _, region := range output.Regions {
regionNames = append(regionNames, *region.RegionName)
Expand All @@ -125,68 +130,68 @@ func describeRegions() []string {
}

// Helper function to call the EC2 DescribeInstanceTypes API for a region and merge the respective instance-type limits into eniLimitMap
func describeInstanceTypes(region string, eniLimitMap map[string]vpc.InstanceTypeLimits) {
func describeInstanceTypes(ctx context.Context, cfg aws.Config, region string, eniLimitMap map[string]vpc.InstanceTypeLimits) {
log.Infof("Describing instance types in region=%s", region)

// Get session
sess := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
Config: *aws.NewConfig().WithRegion(region),
}))
_, err := sess.Config.Credentials.Get()
if err != nil {
log.Fatalf("Failed to get session credentials: %v", err)
}
svc := ec2.New(sess)
describeInstanceTypesInput := &ec2.DescribeInstanceTypesInput{}
cfg.Region = region
client := ec2.NewFromConfig(cfg)

for {
output, err := svc.DescribeInstanceTypes(describeInstanceTypesInput)
paginator := ec2.NewDescribeInstanceTypesPaginator(client, &ec2.DescribeInstanceTypesInput{})

// Iterate through all pages
for paginator.HasMorePages() {
output, err := paginator.NextPage(ctx)
if err != nil {
log.Fatalf("Failed to call EC2 DescribeInstanceTypes: %v", err)
}

// We just want the type name, ENI and IP limits
for _, info := range output.InstanceTypes {
// Ignore any missing values
instanceType := aws.StringValue(info.InstanceType)
instanceType := string(info.InstanceType)

// only one network card is supported, so use the MaximumNetworkInterfaces from the default card if more than one are present
var eniLimit int
if len(info.NetworkInfo.NetworkCards) > 1 {
eniLimit = int(aws.Int64Value(info.NetworkInfo.NetworkCards[*info.NetworkInfo.DefaultNetworkCardIndex].MaximumNetworkInterfaces))
eniLimit = int(*info.NetworkInfo.NetworkCards[*info.NetworkInfo.DefaultNetworkCardIndex].MaximumNetworkInterfaces)
} else {
eniLimit = int(aws.Int64Value(info.NetworkInfo.MaximumNetworkInterfaces))
eniLimit = int(*info.NetworkInfo.MaximumNetworkInterfaces)
}
ipv4Limit := int(aws.Int64Value(info.NetworkInfo.Ipv4AddressesPerInterface))
isBareMetalInstance := aws.BoolValue(info.BareMetal)
hypervisorType := aws.StringValue(info.Hypervisor)

ipv4Limit := int(*info.NetworkInfo.Ipv4AddressesPerInterface)
isBareMetalInstance := *info.BareMetal
hypervisorType := string(info.Hypervisor)
if hypervisorType == "" {
hypervisorType = "unknown"
}
networkCards := make([]vpc.NetworkCard, aws.Int64Value(info.NetworkInfo.MaximumNetworkCards))
defaultNetworkCardIndex := int(aws.Int64Value(info.NetworkInfo.DefaultNetworkCardIndex))
for idx := 0; idx < len(networkCards); idx += 1 {

networkCards := make([]vpc.NetworkCard, *info.NetworkInfo.MaximumNetworkCards)
defaultNetworkCardIndex := int(*info.NetworkInfo.DefaultNetworkCardIndex)

for idx := 0; idx < len(networkCards); idx++ {
networkCards[idx] = vpc.NetworkCard{
MaximumNetworkInterfaces: *info.NetworkInfo.NetworkCards[idx].MaximumNetworkInterfaces,
NetworkCardIndex: *info.NetworkInfo.NetworkCards[idx].NetworkCardIndex,
MaximumNetworkInterfaces: int64(*info.NetworkInfo.NetworkCards[idx].MaximumNetworkInterfaces),
NetworkCardIndex: int64(*info.NetworkInfo.NetworkCards[idx].NetworkCardIndex),
}
}

if instanceType != "" && eniLimit > 0 && ipv4Limit > 0 {
limits := vpc.InstanceTypeLimits{ENILimit: eniLimit, IPv4Limit: ipv4Limit, NetworkCards: networkCards, HypervisorType: strconv.Quote(hypervisorType),
IsBareMetal: isBareMetalInstance, DefaultNetworkCardIndex: defaultNetworkCardIndex}
limits := vpc.InstanceTypeLimits{
ENILimit: eniLimit,
IPv4Limit: ipv4Limit,
NetworkCards: networkCards,
HypervisorType: strconv.Quote(hypervisorType),
IsBareMetal: isBareMetalInstance,
DefaultNetworkCardIndex: defaultNetworkCardIndex,
}

if existingLimits, contains := eniLimitMap[instanceType]; contains && !reflect.DeepEqual(existingLimits, limits) {
// this should never happen
log.Fatalf("A previous region has different limits for instanceType=%s than region=%s", instanceType, region)
}
eniLimitMap[instanceType] = limits
}
}
// Paginate to the next request
if output.NextToken == nil {
break
}
describeInstanceTypesInput = &ec2.DescribeInstanceTypesInput{
NextToken: output.NextToken,
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion test/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,16 @@ func New(options Options) *Framework {
cloudConfig := aws.CloudConfig{Region: options.AWSRegion, VpcID: options.AWSVPCID,
EKSEndpoint: options.EKSEndpoint}

awsCloud, err := aws.NewCloud(cloudConfig)

if err != nil {
log.Fatalf("failed to create AWS cloud client: %v", err)
}

return &Framework{
Options: options,
K8sClient: k8sClient,
CloudServices: aws.NewCloud(cloudConfig),
CloudServices: awsCloud,
K8sResourceManagers: k8s.NewResourceManager(k8sClient, clientset, k8sSchema, config),
InstallationManager: controller.NewDefaultInstallationManager(
helm.NewDefaultReleaseManager(options.KubeConfig)),
Expand Down
36 changes: 24 additions & 12 deletions test/framework/resources/aws/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
package aws

import (
"context"
"fmt"

"github.com/aws/amazon-vpc-cni-k8s/test/framework/resources/aws/services"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
awsconfig "github.com/aws/aws-sdk-go-v2/config"
)

type CloudConfig struct {
Expand Down Expand Up @@ -44,19 +46,29 @@ type defaultCloud struct {
cloudWatch services.CloudWatch
}

func NewCloud(config CloudConfig) Cloud {
session := session.Must(session.NewSession(&aws.Config{
Region: aws.String(config.Region)}))
func NewCloud(config CloudConfig) (Cloud, error) {

cfg, err := awsconfig.LoadDefaultConfig(context.TODO(), awsconfig.WithRegion(config.Region))

if err != nil {
return nil, fmt.Errorf("unable to load SDK config, %v", err)
}

eksService, err := services.NewEKS(cfg, config.EKSEndpoint)

if err != nil {
return nil, fmt.Errorf("unable to create EKS service client, %v", err)
}

return &defaultCloud{
cfg: config,
ec2: services.NewEC2(session),
iam: services.NewIAM(session),
eks: services.NewEKS(session, config.EKSEndpoint),
autoScaling: services.NewAutoScaling(session),
cloudFormation: services.NewCloudFormation(session),
cloudWatch: services.NewCloudWatch(session),
}
ec2: services.NewEC2(cfg),
iam: services.NewIAM(cfg),
eks: eksService,
autoScaling: services.NewAutoScaling(cfg),
cloudFormation: services.NewCloudFormation(cfg),
cloudWatch: services.NewCloudWatch(cfg),
}, nil
}

func (c *defaultCloud) EC2() services.EC2 {
Expand Down
Loading

0 comments on commit a7f6034

Please sign in to comment.