Skip to content

Commit 6b84b2f

Browse files
authored
*: test aws sdk go v2 (#201)
* CHANGELOG: update Signed-off-by: Gyuho Lee <leegyuho@amazon.com> * go.mod: add aws sdk v2 Signed-off-by: Gyuho Lee <leegyuho@amazon.com> * CHANGELOG: update Signed-off-by: Gyuho Lee <leegyuho@amazon.com> * pkg/aws: test v2 Signed-off-by: Gyuho Lee <leegyuho@amazon.com> * vendor: add aws sdk v2 Signed-off-by: Gyuho Lee <leegyuho@amazon.com> * CHANGELOG: update Signed-off-by: Gyuho Lee <leegyuho@amazon.com>
1 parent facd175 commit 6b84b2f

File tree

1,527 files changed

+727899
-154
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,527 files changed

+727899
-154
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"git.ignoreLimitWarning": true
3+
}

CHANGELOG/CHANGELOG-1.5.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,39 @@
11

22

3+
<hr>
4+
5+
6+
## [v1.5.8](https://github.com/aws/aws-k8s-tester/releases/tag/v1.5.8) (2021-01)
7+
8+
See [code changes](https://github.com/aws/aws-k8s-tester/compare/v1.5.7...v1.5.8).
9+
### `eks`
10+
11+
- Fix [`eks/ng` CFN template](https://github.com/aws/aws-k8s-tester/pull/200).
12+
- Test [`aws-sdk-go-v2`](https://github.com/aws/aws-k8s-tester/pull/201).
13+
### Dependency
14+
15+
- Add [`github.com/aws/aws-sdk-go-v2`](https://github.com/aws/aws-sdk-go-v2/releases) [`v1.0.0`](https://github.com/aws/aws-sdk-go/releases/tag/v1.0.0).
16+
17+
### Go
18+
19+
- Compile with [*Go 1.16rc1*](https://golang.org/doc/devel/release.html#go1.16).
20+
21+
22+
<hr>
23+
24+
25+
## [v1.5.7](https://github.com/aws/aws-k8s-tester/releases/tag/v1.5.7) (2021-01-25)
26+
27+
See [code changes](https://github.com/aws/aws-k8s-tester/compare/v1.5.6...v1.5.7).
28+
### `eksconfig`
29+
30+
- Fix ["AddOnAmiSoftLockupIssue454" parsing](https://github.com/aws/aws-k8s-tester/pull/199).
31+
### Go
32+
33+
- Compile with [*Go 1.16beta1*](https://golang.org/doc/devel/release.html#go1.16).
34+
35+
36+
337
<hr>
438

539

eks/eks.go

Lines changed: 127 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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{

go.mod

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,29 @@ replace (
4444

4545
require (
4646
github.com/aws/aws-sdk-go v1.35.30
47+
github.com/aws/aws-sdk-go-v2 v1.0.0
48+
github.com/aws/aws-sdk-go-v2/config v1.0.0
49+
github.com/aws/aws-sdk-go-v2/service/autoscaling v1.0.0
50+
github.com/aws/aws-sdk-go-v2/service/cloudformation v1.0.0
51+
github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.0.0
52+
github.com/aws/aws-sdk-go-v2/service/ec2 v1.0.0
53+
github.com/aws/aws-sdk-go-v2/service/ecr v1.0.0
54+
github.com/aws/aws-sdk-go-v2/service/eks v1.0.0
55+
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.0.0
56+
github.com/aws/aws-sdk-go-v2/service/iam v1.0.0
57+
github.com/aws/aws-sdk-go-v2/service/kms v1.0.0
58+
github.com/aws/aws-sdk-go-v2/service/s3 v1.0.0
59+
github.com/aws/aws-sdk-go-v2/service/ssm v1.0.0
60+
github.com/aws/aws-sdk-go-v2/service/sts v1.0.0
61+
github.com/aws/smithy-go v1.0.0
4762
github.com/briandowns/spinner v1.11.1
4863
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575
4964
github.com/davecgh/go-spew v1.1.1
5065
github.com/dustin/go-humanize v1.0.0
5166
github.com/fatih/color v1.9.0 // indirect
5267
github.com/go-ini/ini v1.55.0
5368
github.com/gofrs/flock v0.7.1
54-
github.com/google/go-cmp v0.5.0
69+
github.com/google/go-cmp v0.5.4
5570
github.com/manifoldco/promptui v0.7.0
5671
github.com/mattn/go-runewidth v0.0.8 // indirect
5772
github.com/mholt/archiver/v3 v3.3.0

0 commit comments

Comments
 (0)