@@ -77,6 +77,18 @@ import (
7777 "github.com/aws/aws-k8s-tester/pkg/terminal"
7878 "github.com/aws/aws-k8s-tester/pkg/user"
7979 "github.com/aws/aws-k8s-tester/version"
80+ aws_v2 "github.com/aws/aws-sdk-go-v2/aws"
81+ aws_asg_v2 "github.com/aws/aws-sdk-go-v2/service/autoscaling"
82+ aws_cfn_v2 "github.com/aws/aws-sdk-go-v2/service/cloudformation"
83+ aws_cw_v2 "github.com/aws/aws-sdk-go-v2/service/cloudwatch"
84+ aws_ec2_v2 "github.com/aws/aws-sdk-go-v2/service/ec2"
85+ aws_ecr_v2 "github.com/aws/aws-sdk-go-v2/service/ecr"
86+ aws_eks_v2 "github.com/aws/aws-sdk-go-v2/service/eks"
87+ aws_elbv2_v2 "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2"
88+ aws_iam_v2 "github.com/aws/aws-sdk-go-v2/service/iam"
89+ aws_kms_v2 "github.com/aws/aws-sdk-go-v2/service/kms"
90+ aws_s3_v2 "github.com/aws/aws-sdk-go-v2/service/s3"
91+ aws_ssm_v2 "github.com/aws/aws-sdk-go-v2/service/ssm"
8092 "github.com/aws/aws-sdk-go/aws"
8193 "github.com/aws/aws-sdk-go/aws/session"
8294 "github.com/aws/aws-sdk-go/service/autoscaling"
@@ -131,20 +143,39 @@ type Tester struct {
131143 awsSession * session.Session
132144
133145 iamAPI iamiface.IAMAPI
146+ iamAPIV2 * aws_iam_v2.Client
147+
134148 kmsAPI kmsiface.KMSAPI
149+ kmsAPIV2 * aws_kms_v2.Client
150+
135151 ssmAPI ssmiface.SSMAPI
152+ ssmAPIV2 * aws_ssm_v2.Client
153+
136154 cfnAPI cloudformationiface.CloudFormationAPI
155+ cfnAPIV2 * aws_cfn_v2.Client
156+
137157 ec2API ec2iface.EC2API
138- s3API s3iface.S3API
139- cwAPI cloudwatchiface.CloudWatchAPI
158+ ec2APIV2 * aws_ec2_v2.Client
159+
160+ s3API s3iface.S3API
161+ s3APIV2 * aws_s3_v2.Client
162+
163+ cwAPI cloudwatchiface.CloudWatchAPI
164+ cwAPIV2 * aws_cw_v2.Client
165+
140166 asgAPI autoscalingiface.AutoScalingAPI
141- elbv2API elbv2iface.ELBV2API
167+ asgAPIV2 * aws_asg_v2.Client
168+
169+ elbv2API elbv2iface.ELBV2API
170+ elbv2APIV2 * aws_elbv2_v2.Client
142171
143172 ecrAPISameRegion ecriface.ECRAPI
173+ ecrAPIV2 * aws_ecr_v2.Client
144174
145175 // used for EKS + EKS MNG API calls
146176 eksSession * session.Session
147177 eksAPI eksiface.EKSAPI
178+ eksAPIV2 * aws_eks_v2.Client
148179
149180 s3Uploaded bool
150181
@@ -310,14 +341,14 @@ func New(cfg *eksconfig.Config) (ts *Tester, err error) {
310341
311342 defer ts .cfg .Sync ()
312343
313- awsCfg := & pkg_aws.Config {
344+ awsCfg := pkg_aws.Config {
314345 Logger : ts .lg ,
315346 DebugAPICalls : ts .cfg .LogLevel == "debug" ,
316347 Partition : ts .cfg .Partition ,
317348 Region : ts .cfg .Region ,
318349 }
319350 var stsOutput * sts.GetCallerIdentityOutput
320- ts .awsSession , stsOutput , ts .cfg .Status .AWSCredentialPath , err = pkg_aws .New (awsCfg )
351+ ts .awsSession , stsOutput , ts .cfg .Status .AWSCredentialPath , err = pkg_aws .New (& awsCfg )
321352 if err != nil {
322353 return nil , err
323354 }
@@ -326,35 +357,79 @@ func New(cfg *eksconfig.Config) (ts *Tester, err error) {
326357 ts .cfg .Status .AWSIAMRoleARN = aws .StringValue (stsOutput .Arn )
327358 ts .cfg .Sync ()
328359
360+ ts .lg .Info ("checking AWS SDK Go v2" )
361+ awsCfgV2 , _ , err := pkg_aws .NewV2 (& awsCfg )
362+ if err != nil {
363+ return nil , err
364+ }
365+
329366 ts .iamAPI = iam .New (ts .awsSession )
367+ ts .iamAPIV2 = aws_iam_v2 .NewFromConfig (awsCfgV2 )
368+
330369 ts .kmsAPI = kms .New (ts .awsSession )
370+ ts .kmsAPIV2 = aws_kms_v2 .NewFromConfig (awsCfgV2 )
371+
331372 ts .ssmAPI = ssm .New (ts .awsSession )
373+ ts .ssmAPIV2 = aws_ssm_v2 .NewFromConfig (awsCfgV2 )
374+
332375 ts .cfnAPI = cloudformation .New (ts .awsSession )
376+ ts .cfnAPIV2 = aws_cfn_v2 .NewFromConfig (awsCfgV2 )
333377
334378 ts .ec2API = ec2 .New (ts .awsSession )
335379 if _ , err = ts .ec2API .DescribeInstances (& ec2.DescribeInstancesInput {MaxResults : aws .Int64 (5 )}); err != nil {
336- return nil , fmt .Errorf ("failed to describe instances using EC2 API (%v)" , err )
380+ return nil , fmt .Errorf ("failed to describe instances using EC2 API v1 (%v)" , err )
381+ }
382+ fmt .Fprintln (ts .logWriter , "EC2 API v1 available!" )
383+
384+ ts .ec2APIV2 = aws_ec2_v2 .NewFromConfig (awsCfgV2 )
385+ ctx , cancel = context .WithTimeout (context .Background (), 15 * time .Second )
386+ _ , err = ts .ec2APIV2 .DescribeInstances (ctx , & aws_ec2_v2.DescribeInstancesInput {MaxResults : 5 })
387+ cancel ()
388+ if err != nil {
389+ return nil , fmt .Errorf ("failed to describe instances using EC2 API v2 (%v)" , err )
337390 }
338- fmt .Fprintln (ts .logWriter , "EC2 API available!" )
391+ fmt .Fprintln (ts .logWriter , "EC2 API v2 available!" )
339392
340393 ts .s3API = s3 .New (ts .awsSession )
394+ ts .s3APIV2 = aws_s3_v2 .NewFromConfig (awsCfgV2 )
395+
341396 ts .cwAPI = cloudwatch .New (ts .awsSession )
397+ ts .cwAPIV2 = aws_cw_v2 .NewFromConfig (awsCfgV2 )
398+
342399 ts .asgAPI = autoscaling .New (ts .awsSession )
400+ ts .asgAPIV2 = aws_asg_v2 .NewFromConfig (awsCfgV2 )
401+
343402 ts .elbv2API = elbv2 .New (ts .awsSession )
403+ ts .elbv2APIV2 = aws_elbv2_v2 .NewFromConfig (awsCfgV2 )
344404
405+ ts .lg .Info ("checking ECR API v1 availability; listing repositories" )
345406 ts .ecrAPISameRegion = ecr .New (ts .awsSession , aws .NewConfig ().WithRegion (ts .cfg .Region ))
346-
347- ts .lg .Info ("checking ECR API availability; listing repositories" )
348407 var ecrResp * ecr.DescribeRepositoriesOutput
349408 ecrResp , err = ts .ecrAPISameRegion .DescribeRepositories (& ecr.DescribeRepositoriesInput {
350- MaxResults : aws .Int64 (20 ),
409+ MaxResults : aws .Int64 (5 ),
351410 })
352411 if err != nil {
353412 return nil , fmt .Errorf ("failed to describe repositories using ECR API (%v)" , err )
354413 }
355- ts .lg .Info ("listed repositories with limit 20 " , zap .Int ("repositories" , len (ecrResp .Repositories )))
414+ ts .lg .Info ("listed repositories with limit 5 " , zap .Int ("repositories" , len (ecrResp .Repositories )))
356415 for _ , v := range ecrResp .Repositories {
357- ts .lg .Info ("EKS repository" , zap .String ("repository-uri" , aws .StringValue (v .RepositoryUri )))
416+ ts .lg .Info ("ECR repository" , zap .String ("repository-uri" , aws .StringValue (v .RepositoryUri )))
417+ }
418+
419+ ts .lg .Info ("checking ECR API v2 availability; listing repositories" )
420+ ts .ecrAPIV2 = aws_ecr_v2 .NewFromConfig (awsCfgV2 )
421+ var ecrRespV2 * aws_ecr_v2.DescribeRepositoriesOutput
422+ ctx , cancel = context .WithTimeout (context .Background (), 15 * time .Second )
423+ ecrRespV2 , err = ts .ecrAPIV2 .DescribeRepositories (ctx , & aws_ecr_v2.DescribeRepositoriesInput {
424+ MaxResults : aws .Int32 (5 ),
425+ })
426+ cancel ()
427+ if err != nil {
428+ return nil , fmt .Errorf ("failed to describe repositories using ECR API (%v)" , err )
429+ }
430+ ts .lg .Info ("listed repositories with limit 5" , zap .Int ("repositories" , len (ecrRespV2 .Repositories )))
431+ for _ , v := range ecrRespV2 .Repositories {
432+ ts .lg .Info ("ECR repository" , zap .String ("repository-uri" , aws .StringValue (v .RepositoryUri )))
358433 }
359434
360435 // create a separate session for EKS (for resolver endpoint)
@@ -371,19 +446,56 @@ func New(cfg *eksconfig.Config) (ts *Tester, err error) {
371446 }
372447 ts .eksAPI = aws_eks .New (ts .eksSession )
373448
374- ts .lg .Info ("checking EKS API availability; listing clusters" )
449+ ts .lg .Info ("checking AWS SDK Go v2 for EKS" )
450+ optFns := []func (o * aws_eks_v2.Options ){}
451+ if ts .cfg .Parameters .ResolverURL != "" {
452+ ts .lg .Info (
453+ "setting EKS endpoint resolver" ,
454+ zap .String ("resolver-url" , ts .cfg .Parameters .ResolverURL ),
455+ zap .String ("signing-name" , ts .cfg .Parameters .SigningName ),
456+ )
457+ rsFn := aws_eks_v2 .EndpointResolverFunc (func (region string , option aws_eks_v2.EndpointResolverOptions ) (aws_v2.Endpoint , error ) {
458+ return aws_v2.Endpoint {
459+ URL : ts .cfg .Parameters .ResolverURL ,
460+ SigningName : ts .cfg .Parameters .SigningName ,
461+ }, nil
462+ })
463+ optFns = append (optFns , func (o * aws_eks_v2.Options ) {
464+ o .EndpointResolver = rsFn
465+ })
466+ }
467+ ts .eksAPIV2 = aws_eks_v2 .NewFromConfig (awsCfgV2 , optFns ... )
468+
469+ ts .lg .Info ("checking EKS API v1 availability; listing clusters" )
375470 var eksListResp * aws_eks.ListClustersOutput
376471 eksListResp , err = ts .eksAPI .ListClusters (& aws_eks.ListClustersInput {
377472 MaxResults : aws .Int64 (20 ),
378473 })
379474 if err != nil {
380- return nil , fmt .Errorf ("failed to list clusters using EKS API (%v)" , err )
475+ return nil , fmt .Errorf ("failed to list clusters using EKS API v1 (%v)" , err )
381476 }
382- ts .lg .Info ("listed clusters with limit 20" , zap .Int ("clusters" , len (eksListResp .Clusters )))
477+ ts .lg .Info ("listed clusters with limit 20 with v1 " , zap .Int ("clusters" , len (eksListResp .Clusters )))
383478 for _ , v := range eksListResp .Clusters {
384479 ts .lg .Info ("EKS cluster" , zap .String ("name" , aws .StringValue (v )))
385480 }
386481
482+ ts .lg .Info ("checking EKS API v2 availability; listing clusters" )
483+ var eksListRespV2 * aws_eks_v2.ListClustersOutput
484+ cctx , ccancel := context .WithTimeout (context .Background (), 10 * time .Second )
485+ eksListRespV2 , err = ts .eksAPIV2 .ListClusters (cctx , & aws_eks_v2.ListClustersInput {
486+ MaxResults : aws .Int32 (20 ),
487+ })
488+ ccancel ()
489+ if err != nil {
490+ // return nil, fmt.Errorf("failed to list clusters using EKS API v2 (%v)", err)
491+ ts .lg .Warn ("failed to list clusters using EKS API v2" , zap .Error (err ))
492+ } else {
493+ ts .lg .Info ("listed clusters with limit 20 with v2" , zap .Int ("clusters" , len (eksListResp .Clusters )))
494+ for _ , v := range eksListRespV2 .Clusters {
495+ ts .lg .Info ("EKS cluster" , zap .String ("name" , v ))
496+ }
497+ }
498+
387499 // update k8s client if cluster has already been created
388500 ts .lg .Info ("creating k8s client from previous states if any" )
389501 kcfg := & k8s_client.EKSConfig {
0 commit comments