@@ -32,6 +32,12 @@ import (
3232	"strings" 
3333	"time" 
3434
35+ 	awsv2 "github.com/aws/aws-sdk-go-v2/aws" 
36+ 	"github.com/aws/aws-sdk-go-v2/config" 
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+ 	iamtypes "github.com/aws/aws-sdk-go-v2/service/iam/types" 
3541	"github.com/aws/aws-sdk-go/aws" 
3642	"github.com/aws/aws-sdk-go/aws/client" 
3743	awscreds "github.com/aws/aws-sdk-go/aws/credentials" 
@@ -42,7 +48,6 @@ import (
4248	"github.com/aws/aws-sdk-go/service/ec2" 
4349	"github.com/aws/aws-sdk-go/service/ecrpublic" 
4450	"github.com/aws/aws-sdk-go/service/efs" 
45- 	"github.com/aws/aws-sdk-go/service/eks" 
4651	"github.com/aws/aws-sdk-go/service/elb" 
4752	"github.com/aws/aws-sdk-go/service/iam" 
4853	"github.com/aws/aws-sdk-go/service/servicequotas" 
@@ -408,6 +413,55 @@ func NewAWSSessionWithKey(accessKey *iam.AccessKey) client.ConfigProvider {
408413	return  sess 
409414}
410415
416+ func  NewAWSSessionV2 () * awsv2.Config  {
417+ 	By ("Getting an AWS IAM session - from environment" )
418+ 	region , err  :=  credentials .ResolveRegion ("" )
419+ 	Expect (err ).NotTo (HaveOccurred ())
420+ 	optFns  :=  []func (* config.LoadOptions ) error {
421+ 		config .WithRegion (region ),
422+ 		config .WithClientLogMode (awsv2 .LogSigning ),
423+ 	}
424+ 	cfg , err  :=  config .LoadDefaultConfig (context .Background (), optFns ... )
425+ 	Expect (err ).NotTo (HaveOccurred ())
426+ 	_ , err  =  cfg .Credentials .Retrieve (context .Background ())
427+ 	Expect (err ).NotTo (HaveOccurred ())
428+ 	return  & cfg 
429+ }
430+ 
431+ func  NewAWSSessionRepoWithKeyV2 (accessKey  * iamtypes.AccessKey ) * awsv2.Config  {
432+ 	By ("Getting an AWS IAM session - from access key" )
433+ 	region , err  :=  credentials .ResolveRegion ("us-east-1" )
434+ 	Expect (err ).NotTo (HaveOccurred ())
435+ 	staticCredProvider  :=  awscredsv2 .NewStaticCredentialsProvider (awsv2 .ToString (accessKey .AccessKeyId ), awsv2 .ToString (accessKey .SecretAccessKey ), "" )
436+ 	optFns  :=  []func (* config.LoadOptions ) error {
437+ 		config .WithRegion (region ),
438+ 		config .WithClientLogMode (awsv2 .LogSigning ),
439+ 		config .WithCredentialsProvider (staticCredProvider ),
440+ 	}
441+ 	cfg , err  :=  config .LoadDefaultConfig (context .Background (), optFns ... )
442+ 	Expect (err ).NotTo (HaveOccurred ())
443+ 	_ , err  =  cfg .Credentials .Retrieve (context .Background ())
444+ 	Expect (err ).NotTo (HaveOccurred ())
445+ 	return  & cfg 
446+ }
447+ 
448+ func  NewAWSSessionWithKeyV2 (accessKey  * iamtypes.AccessKey ) * awsv2.Config  {
449+ 	By ("Getting an AWS IAM session - from access key" )
450+ 	region , err  :=  credentials .ResolveRegion ("" )
451+ 	Expect (err ).NotTo (HaveOccurred ())
452+ 	staticCredProvider  :=  awscredsv2 .NewStaticCredentialsProvider (awsv2 .ToString (accessKey .AccessKeyId ), awsv2 .ToString (accessKey .SecretAccessKey ), "" )
453+ 	optFns  :=  []func (* config.LoadOptions ) error {
454+ 		config .WithRegion (region ),
455+ 		config .WithClientLogMode (awsv2 .LogSigning ),
456+ 		config .WithCredentialsProvider (staticCredProvider ),
457+ 	}
458+ 	cfg , err  :=  config .LoadDefaultConfig (context .Background (), optFns ... )
459+ 	Expect (err ).NotTo (HaveOccurred ())
460+ 	_ , err  =  cfg .Credentials .Retrieve (context .Background ())
461+ 	Expect (err ).NotTo (HaveOccurred ())
462+ 	return  & cfg 
463+ }
464+ 
411465// createCloudFormationStack ensures the cloudformation stack is up to date. 
412466func  createCloudFormationStack (prov  client.ConfigProvider , t  * cfn_bootstrap.Template , tags  map [string ]string ) error  {
413467	By (fmt .Sprintf ("Creating AWS CloudFormation stack for AWS IAM resources: stack-name=%s" , t .Spec .StackName ))
@@ -1011,7 +1065,7 @@ func (s *ServiceQuota) updateServiceQuotaRequestStatus(serviceQuotasClient *serv
10111065}
10121066
10131067// DumpEKSClusters dumps the EKS clusters in the environment. 
1014- func  DumpEKSClusters (_  context.Context , e2eCtx  * E2EContext ) {
1068+ func  DumpEKSClusters (ctx  context.Context , e2eCtx  * E2EContext ) {
10151069	name  :=  "no-bootstrap-cluster" 
10161070	if  e2eCtx .Environment .BootstrapClusterProxy  !=  nil  {
10171071		name  =  e2eCtx .Environment .BootstrapClusterProxy .GetName ()
@@ -1023,36 +1077,36 @@ func DumpEKSClusters(_ context.Context, e2eCtx *E2EContext) {
10231077	fmt .Fprintf (GinkgoWriter , "Folder created for eks clusters: %q\n " , logPath )
10241078
10251079	input  :=  & eks.ListClustersInput {}
1026- 	var  eksClient  * eks.EKS 
1027- 	if  e2eCtx .BootstrapUserAWSSession  ==  nil  &&  e2eCtx .AWSSession  !=  nil  {
1028- 		eksClient  =  eks .New ( e2eCtx .AWSSession )
1029- 	} else  if  e2eCtx .BootstrapUserAWSSession  !=  nil  {
1030- 		eksClient  =  eks .New ( e2eCtx .BootstrapUserAWSSession )
1080+ 	var  eksClient  * eks.Client 
1081+ 	if  e2eCtx .BootstrapUserAWSSessionV2  ==  nil  &&  e2eCtx .AWSSessionV2  !=  nil  {
1082+ 		eksClient  =  eks .NewFromConfig ( * e2eCtx .NewAWSSessionV2 )
1083+ 	} else  if  e2eCtx .BootstrapUserAWSSessionV2  !=  nil  {
1084+ 		eksClient  =  eks .NewFromConfig ( * e2eCtx .BootstrapUserAWSSessionV2 )
10311085	} else  {
10321086		Fail ("Couldn't list EKS clusters: no AWS client was set up (please look at previous errors)" )
10331087		return 
10341088	}
10351089
1036- 	output , err  :=  eksClient .ListClusters (input )
1090+ 	output , err  :=  eksClient .ListClusters (ctx ,  input )
10371091	if  err  !=  nil  {
10381092		fmt .Fprintf (GinkgoWriter , "Couldn't list EKS clusters: err=%s\n " , err )
10391093		return 
10401094	}
10411095
10421096	for  _ , clusterName  :=  range  output .Clusters  {
10431097		describeInput  :=  & eks.DescribeClusterInput {
1044- 			Name : clusterName ,
1098+ 			Name : aws . String ( clusterName ) ,
10451099		}
1046- 		describeOutput , err  :=  eksClient .DescribeCluster (describeInput )
1100+ 		describeOutput , err  :=  eksClient .DescribeCluster (ctx ,  describeInput )
10471101		if  err  !=  nil  {
1048- 			fmt .Fprintf (GinkgoWriter , "Couldn't describe EKS clusters: name=%q err=%s\n " , * clusterName , err )
1102+ 			fmt .Fprintf (GinkgoWriter , "Couldn't describe EKS clusters: name=%q err=%s\n " , clusterName , err )
10491103			continue 
10501104		}
10511105		dumpEKSCluster (describeOutput .Cluster , logPath )
10521106	}
10531107}
10541108
1055- func  dumpEKSCluster (cluster  * eks .Cluster , logPath  string ) {
1109+ func  dumpEKSCluster (cluster  * ekstypes .Cluster , logPath  string ) {
10561110	clusterYAML , err  :=  yaml .Marshal (cluster )
10571111	if  err  !=  nil  {
10581112		fmt .Fprintf (GinkgoWriter , "Couldn't marshal cluster to yaml: name=%q err=%s\n " , * cluster .Name , err )
0 commit comments