@@ -34,7 +34,10 @@ import (
34
34
35
35
awsv2 "github.com/aws/aws-sdk-go-v2/aws"
36
36
"github.com/aws/aws-sdk-go-v2/config"
37
- iam "github.com/aws/aws-sdk-go-v2/service/iam"
37
+ awscredsv2 "github.com/aws/aws-sdk-go-v2/credentials"
38
+ "github.com/aws/aws-sdk-go-v2/service/eks"
39
+ ekstypes "github.com/aws/aws-sdk-go-v2/service/eks/types"
40
+ "github.com/aws/aws-sdk-go-v2/service/iam"
38
41
iamtypes "github.com/aws/aws-sdk-go-v2/service/iam/types"
39
42
"github.com/aws/aws-sdk-go/aws"
40
43
"github.com/aws/aws-sdk-go/aws/client"
@@ -46,7 +49,6 @@ import (
46
49
"github.com/aws/aws-sdk-go/service/ec2"
47
50
"github.com/aws/aws-sdk-go/service/ecrpublic"
48
51
"github.com/aws/aws-sdk-go/service/efs"
49
- "github.com/aws/aws-sdk-go/service/eks"
50
52
"github.com/aws/aws-sdk-go/service/elb"
51
53
"github.com/aws/aws-sdk-go/service/servicequotas"
52
54
"github.com/aws/aws-sdk-go/service/sts"
@@ -434,6 +436,55 @@ func NewAWSSessionWithKey(accessKey *iamtypes.AccessKey) client.ConfigProvider {
434
436
return sess
435
437
}
436
438
439
+ func NewAWSSessionV2 () * awsv2.Config {
440
+ By ("Getting an AWS IAM session - from environment" )
441
+ region , err := credentials .ResolveRegion ("" )
442
+ Expect (err ).NotTo (HaveOccurred ())
443
+ optFns := []func (* config.LoadOptions ) error {
444
+ config .WithRegion (region ),
445
+ config .WithClientLogMode (awsv2 .LogSigning ),
446
+ }
447
+ cfg , err := config .LoadDefaultConfig (context .Background (), optFns ... )
448
+ Expect (err ).NotTo (HaveOccurred ())
449
+ _ , err = cfg .Credentials .Retrieve (context .Background ())
450
+ Expect (err ).NotTo (HaveOccurred ())
451
+ return & cfg
452
+ }
453
+
454
+ func NewAWSSessionRepoWithKeyV2 (accessKey * iamtypes.AccessKey ) * awsv2.Config {
455
+ By ("Getting an AWS IAM session - from access key" )
456
+ region , err := credentials .ResolveRegion ("us-east-1" )
457
+ Expect (err ).NotTo (HaveOccurred ())
458
+ staticCredProvider := awscredsv2 .NewStaticCredentialsProvider (awsv2 .ToString (accessKey .AccessKeyId ), awsv2 .ToString (accessKey .SecretAccessKey ), "" )
459
+ optFns := []func (* config.LoadOptions ) error {
460
+ config .WithRegion (region ),
461
+ config .WithClientLogMode (awsv2 .LogSigning ),
462
+ config .WithCredentialsProvider (staticCredProvider ),
463
+ }
464
+ cfg , err := config .LoadDefaultConfig (context .Background (), optFns ... )
465
+ Expect (err ).NotTo (HaveOccurred ())
466
+ _ , err = cfg .Credentials .Retrieve (context .Background ())
467
+ Expect (err ).NotTo (HaveOccurred ())
468
+ return & cfg
469
+ }
470
+
471
+ func NewAWSSessionWithKeyV2 (accessKey * iamtypes.AccessKey ) * awsv2.Config {
472
+ By ("Getting an AWS IAM session - from access key" )
473
+ region , err := credentials .ResolveRegion ("" )
474
+ Expect (err ).NotTo (HaveOccurred ())
475
+ staticCredProvider := awscredsv2 .NewStaticCredentialsProvider (awsv2 .ToString (accessKey .AccessKeyId ), awsv2 .ToString (accessKey .SecretAccessKey ), "" )
476
+ optFns := []func (* config.LoadOptions ) error {
477
+ config .WithRegion (region ),
478
+ config .WithClientLogMode (awsv2 .LogSigning ),
479
+ config .WithCredentialsProvider (staticCredProvider ),
480
+ }
481
+ cfg , err := config .LoadDefaultConfig (context .Background (), optFns ... )
482
+ Expect (err ).NotTo (HaveOccurred ())
483
+ _ , err = cfg .Credentials .Retrieve (context .Background ())
484
+ Expect (err ).NotTo (HaveOccurred ())
485
+ return & cfg
486
+ }
487
+
437
488
// createCloudFormationStack ensures the cloudformation stack is up to date.
438
489
func createCloudFormationStack (ctx context.Context , cfg awsv2.Config , prov client.ConfigProvider , t * cfn_bootstrap.Template , tags map [string ]string ) error {
439
490
By (fmt .Sprintf ("Creating AWS CloudFormation stack for AWS IAM resources: stack-name=%s" , t .Spec .StackName ))
@@ -1051,7 +1102,7 @@ func (s *ServiceQuota) updateServiceQuotaRequestStatus(serviceQuotasClient *serv
1051
1102
}
1052
1103
1053
1104
// DumpEKSClusters dumps the EKS clusters in the environment.
1054
- func DumpEKSClusters (_ context.Context , e2eCtx * E2EContext ) {
1105
+ func DumpEKSClusters (ctx context.Context , e2eCtx * E2EContext ) {
1055
1106
name := "no-bootstrap-cluster"
1056
1107
if e2eCtx .Environment .BootstrapClusterProxy != nil {
1057
1108
name = e2eCtx .Environment .BootstrapClusterProxy .GetName ()
@@ -1063,36 +1114,36 @@ func DumpEKSClusters(_ context.Context, e2eCtx *E2EContext) {
1063
1114
fmt .Fprintf (GinkgoWriter , "Folder created for eks clusters: %q\n " , logPath )
1064
1115
1065
1116
input := & eks.ListClustersInput {}
1066
- var eksClient * eks.EKS
1067
- if e2eCtx .BootstrapUserAWSSession == nil && e2eCtx .AWSSession != nil {
1068
- eksClient = eks .New ( e2eCtx .AWSSession )
1069
- } else if e2eCtx .BootstrapUserAWSSession != nil {
1070
- eksClient = eks .New ( e2eCtx .BootstrapUserAWSSession )
1117
+ var eksClient * eks.Client
1118
+ if e2eCtx .BootstrapUserAWSSessionV2 == nil && e2eCtx .AWSSessionV2 != nil {
1119
+ eksClient = eks .NewFromConfig ( * e2eCtx .AWSSessionV2 )
1120
+ } else if e2eCtx .BootstrapUserAWSSessionV2 != nil {
1121
+ eksClient = eks .NewFromConfig ( * e2eCtx .BootstrapUserAWSSessionV2 )
1071
1122
} else {
1072
1123
Fail ("Couldn't list EKS clusters: no AWS client was set up (please look at previous errors)" )
1073
1124
return
1074
1125
}
1075
1126
1076
- output , err := eksClient .ListClusters (input )
1127
+ output , err := eksClient .ListClusters (ctx , input )
1077
1128
if err != nil {
1078
1129
fmt .Fprintf (GinkgoWriter , "Couldn't list EKS clusters: err=%s\n " , err )
1079
1130
return
1080
1131
}
1081
1132
1082
1133
for _ , clusterName := range output .Clusters {
1083
1134
describeInput := & eks.DescribeClusterInput {
1084
- Name : clusterName ,
1135
+ Name : aws . String ( clusterName ) ,
1085
1136
}
1086
- describeOutput , err := eksClient .DescribeCluster (describeInput )
1137
+ describeOutput , err := eksClient .DescribeCluster (ctx , describeInput )
1087
1138
if err != nil {
1088
- fmt .Fprintf (GinkgoWriter , "Couldn't describe EKS clusters: name=%q err=%s\n " , * clusterName , err )
1139
+ fmt .Fprintf (GinkgoWriter , "Couldn't describe EKS clusters: name=%q err=%s\n " , clusterName , err )
1089
1140
continue
1090
1141
}
1091
1142
dumpEKSCluster (describeOutput .Cluster , logPath )
1092
1143
}
1093
1144
}
1094
1145
1095
- func dumpEKSCluster (cluster * eks .Cluster , logPath string ) {
1146
+ func dumpEKSCluster (cluster * ekstypes .Cluster , logPath string ) {
1096
1147
clusterYAML , err := yaml .Marshal (cluster )
1097
1148
if err != nil {
1098
1149
fmt .Fprintf (GinkgoWriter , "Couldn't marshal cluster to yaml: name=%q err=%s\n " , * cluster .Name , err )
0 commit comments