Skip to content

✨ Migrate Node packages to AWS SDK v2 #5584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bootstrap/eks/internal/userdata/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package userdata
import (
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go-v2/aws"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/format"
"k8s.io/utils/ptr"
Expand Down
4 changes: 1 addition & 3 deletions pkg/cloud/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package cloud

import (
awsv2 "github.com/aws/aws-sdk-go-v2/aws"
awsclient "github.com/aws/aws-sdk-go/aws/client"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand All @@ -32,8 +31,7 @@ import (

// Session represents an AWS session.
type Session interface {
Session() awsclient.ConfigProvider
SessionV2() awsv2.Config
Session() awsv2.Config
ServiceLimiter(service string) *throttle.ServiceLimiter
}

Expand Down
17 changes: 5 additions & 12 deletions pkg/cloud/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func NewClusterScope(params ClusterScopeParams) (*ClusterScope, error) {
tagUnmanagedNetworkResources: params.TagUnmanagedNetworkResources,
}

session, serviceLimiters, err := sessionForClusterWithRegion(params.Client, clusterScope, params.AWSCluster.Spec.Region, params.Endpoints, params.Logger)
_, serviceLimiters, err := sessionForClusterWithRegion(params.Client, clusterScope, params.AWSCluster.Spec.Region, params.Endpoints, params.Logger)
if err != nil {
return nil, errors.Errorf("failed to create aws session: %v", err)
}
Expand All @@ -90,8 +90,7 @@ func NewClusterScope(params ClusterScopeParams) (*ClusterScope, error) {
}

clusterScope.patchHelper = helper
clusterScope.session = session
clusterScope.sessionV2 = *sessionv2
clusterScope.session = *sessionv2
clusterScope.serviceLimiters = serviceLimiters
clusterScope.serviceLimitersV2 = serviceLimitersv2

Expand All @@ -107,8 +106,7 @@ type ClusterScope struct {
Cluster *clusterv1.Cluster
AWSCluster *infrav1.AWSCluster

session awsclient.ConfigProvider
sessionV2 awsv2.Config
session awsv2.Config
serviceLimiters throttle.ServiceLimiters
serviceLimitersV2 throttle.ServiceLimiters
controllerName string
Expand Down Expand Up @@ -357,16 +355,11 @@ func (s *ClusterScope) ClusterObj() cloud.ClusterObject {
return s.Cluster
}

// Session returns the AWS SDK session. Used for creating clients.
func (s *ClusterScope) Session() awsclient.ConfigProvider {
// Session returns the AWS SDK V2 session. Used for creating clients.
func (s *ClusterScope) Session() awsv2.Config {
return s.session
}

// SessionV2 returns the AWS SDK V2 session. Used for creating clients.
func (s *ClusterScope) SessionV2() awsv2.Config {
return s.sessionV2
}

// ServiceLimiter returns the AWS SDK session. Used for creating clients.
func (s *ClusterScope) ServiceLimiter(service string) *throttle.ServiceLimiter {
if sl, ok := s.serviceLimiters[service]; ok {
Expand Down
17 changes: 5 additions & 12 deletions pkg/cloud/scope/fargate.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func NewFargateProfileScope(params FargateProfileScopeParams) (*FargateProfileSc
controllerName: params.ControllerName,
}

session, serviceLimiters, err := sessionForClusterWithRegion(params.Client, managedScope, params.ControlPlane.Spec.Region, params.Endpoints, params.Logger)
_, serviceLimiters, err := sessionForClusterWithRegion(params.Client, managedScope, params.ControlPlane.Spec.Region, params.Endpoints, params.Logger)
if err != nil {
return nil, errors.Errorf("failed to create aws session: %v", err)
}
Expand All @@ -92,8 +92,7 @@ func NewFargateProfileScope(params FargateProfileScopeParams) (*FargateProfileSc
ControlPlane: params.ControlPlane,
FargateProfile: params.FargateProfile,
patchHelper: helper,
session: session,
sessionV2: *sessionv2,
session: *sessionv2,
serviceLimiters: serviceLimiters,
serviceLimitersV2: serviceLimitersv2,
controllerName: params.ControllerName,
Expand All @@ -111,8 +110,7 @@ type FargateProfileScope struct {
ControlPlane *ekscontrolplanev1.AWSManagedControlPlane
FargateProfile *expinfrav1.AWSFargateProfile

session awsclient.ConfigProvider
sessionV2 awsv2.Config
session awsv2.Config
serviceLimiters throttle.ServiceLimiters
serviceLimitersV2 throttle.ServiceLimiters
controllerName string
Expand Down Expand Up @@ -225,16 +223,11 @@ func (s *FargateProfileScope) ClusterObj() cloud.ClusterObject {
return s.Cluster
}

// Session returns the AWS SDK session. Used for creating clients.
func (s *FargateProfileScope) Session() awsclient.ConfigProvider {
// Session returns the AWS SDK V2 session. Used for creating clients.
func (s *FargateProfileScope) Session() awsv2.Config {
return s.session
}

// SessionV2 returns the AWS SDK session. Used for creating clients.
func (s *FargateProfileScope) SessionV2() awsv2.Config {
return s.sessionV2
}

// ControllerName returns the name of the controller that
// created the FargateProfile.
func (s *FargateProfileScope) ControllerName() string {
Expand Down
18 changes: 5 additions & 13 deletions pkg/cloud/scope/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package scope

import (
awsv2 "github.com/aws/aws-sdk-go-v2/aws"
awsclient "github.com/aws/aws-sdk-go/aws/client"
"github.com/pkg/errors"

"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/throttle"
Expand All @@ -33,7 +32,7 @@ func NewGlobalScope(params GlobalScopeParams) (*GlobalScope, error) {
if params.ControllerName == "" {
return nil, errors.New("controller name required to generate global scope")
}
ns, limiters, err := sessionForRegion(params.Region, params.Endpoints)
_, limiters, err := sessionForRegion(params.Region, params.Endpoints)
if err != nil {
return nil, errors.Wrap(err, "failed to create aws session")
}
Expand All @@ -43,8 +42,7 @@ func NewGlobalScope(params GlobalScopeParams) (*GlobalScope, error) {
return nil, errors.Wrap(err, "failed to create aws V2 session")
}
return &GlobalScope{
session: ns,
sessionV2: *ns2,
session: *ns2,
serviceLimiters: limiters,
controllerName: params.ControllerName,
}, nil
Expand All @@ -59,22 +57,16 @@ type GlobalScopeParams struct {

// GlobalScope defines the specs for the GlobalScope.
type GlobalScope struct {
session awsclient.ConfigProvider
sessionV2 awsv2.Config
session awsv2.Config
serviceLimiters throttle.ServiceLimiters
controllerName string
}

// Session returns the AWS SDK session. Used for creating clients.
func (s *GlobalScope) Session() awsclient.ConfigProvider {
// Session returns the AWS SDK V2 config. Used for creating clients.
func (s *GlobalScope) Session() awsv2.Config {
return s.session
}

// SessionV2 returns the AWS SDK V2 config. Used for creating clients.
func (s *GlobalScope) SessionV2() awsv2.Config {
return s.sessionV2
}

// ServiceLimiter returns the AWS SDK session. Used for creating clients.
func (s *GlobalScope) ServiceLimiter(service string) *throttle.ServiceLimiter {
if sl, ok := s.serviceLimiters[service]; ok {
Expand Down
17 changes: 7 additions & 10 deletions pkg/cloud/scope/managedcontrolplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,13 @@ func NewManagedControlPlaneScope(params ManagedControlPlaneScopeParams) (*Manage
ControlPlane: params.ControlPlane,
MaxWaitActiveUpdateDelete: params.MaxWaitActiveUpdateDelete,
patchHelper: nil,
session: nil,
serviceLimiters: nil,
controllerName: params.ControllerName,
allowAdditionalRoles: params.AllowAdditionalRoles,
enableIAM: params.EnableIAM,
tagUnmanagedNetworkResources: params.TagUnmanagedNetworkResources,
}
session, serviceLimiters, err := sessionForClusterWithRegion(params.Client, managedScope, params.ControlPlane.Spec.Region, params.Endpoints, params.Logger)
_, serviceLimiters, err := sessionForClusterWithRegion(params.Client, managedScope, params.ControlPlane.Spec.Region, params.Endpoints, params.Logger)
if err != nil {
return nil, errors.Errorf("failed to create aws session: %v", err)
}
Expand All @@ -109,8 +108,7 @@ func NewManagedControlPlaneScope(params ManagedControlPlaneScopeParams) (*Manage
return nil, errors.Errorf("failed to create aws V2 session: %v", err)
}

managedScope.session = session
managedScope.sessionV2 = *sessionv2
managedScope.session = *sessionv2
managedScope.serviceLimiters = serviceLimiters
managedScope.serviceLimitersV2 = serviceLimitersv2

Expand All @@ -133,8 +131,7 @@ type ManagedControlPlaneScope struct {
ControlPlane *ekscontrolplanev1.AWSManagedControlPlane
MaxWaitActiveUpdateDelete time.Duration

session awsclient.ConfigProvider
sessionV2 awsv2.Config
session awsv2.Config
serviceLimiters throttle.ServiceLimiters
serviceLimitersV2 throttle.ServiceLimiters
controllerName string
Expand Down Expand Up @@ -334,14 +331,14 @@ func (s *ManagedControlPlaneScope) ClusterObj() cloud.ClusterObject {
return s.Cluster
}

// Session returns the AWS SDK session. Used for creating clients.
func (s *ManagedControlPlaneScope) Session() awsclient.ConfigProvider {
// Session returns the AWS SDK V2 config. Used for creating clients.
func (s *ManagedControlPlaneScope) Session() awsv2.Config {
return s.session
}

// SessionV2 returns the AWS SDK config. Used for creating clients.
// SessionV2 returns the AWS SDK V2 config. Used for creating clients.
func (s *ManagedControlPlaneScope) SessionV2() awsv2.Config {
return s.sessionV2
return s.session
}

// Bastion returns the bastion details.
Expand Down
28 changes: 7 additions & 21 deletions pkg/cloud/scope/managednodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"time"

awsv2 "github.com/aws/aws-sdk-go-v2/aws"
awsclient "github.com/aws/aws-sdk-go/aws/client"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -54,7 +53,7 @@ type ManagedMachinePoolScopeParams struct {
MachinePool *expclusterv1.MachinePool
ControllerName string
Endpoints []ServiceEndpoint
Session awsclient.ConfigProvider
Session awsv2.Config
MaxWaitActiveUpdateDelete time.Duration

EnableIAM bool
Expand Down Expand Up @@ -88,10 +87,6 @@ func NewManagedMachinePoolScope(params ManagedMachinePoolScopeParams) (*ManagedM
ControlPlane: params.ControlPlane,
controllerName: params.ControllerName,
}
session, serviceLimiters, err := sessionForClusterWithRegion(params.Client, managedScope, params.ControlPlane.Spec.Region, params.Endpoints, params.Logger)
if err != nil {
return nil, errors.Errorf("failed to create aws session: %v", err)
}

sessionv2, serviceLimitersv2, err := sessionForClusterWithRegionV2(params.Client, managedScope, params.ControlPlane.Spec.Region, params.Endpoints, params.Logger)
if err != nil {
Expand Down Expand Up @@ -119,10 +114,8 @@ func NewManagedMachinePoolScope(params ManagedMachinePoolScopeParams) (*ManagedM
MachinePool: params.MachinePool,
MaxWaitActiveUpdateDelete: params.MaxWaitActiveUpdateDelete,
EC2Scope: params.InfraCluster,
session: session,
sessionV2: *sessionv2,
serviceLimiters: serviceLimiters,
serviceLimitersV2: serviceLimitersv2,
session: *sessionv2,
serviceLimiters: serviceLimitersv2,
controllerName: params.ControllerName,
enableIAM: params.EnableIAM,
allowAdditionalRoles: params.AllowAdditionalRoles,
Expand All @@ -143,11 +136,9 @@ type ManagedMachinePoolScope struct {
EC2Scope EC2Scope
MaxWaitActiveUpdateDelete time.Duration

session awsclient.ConfigProvider
sessionV2 awsv2.Config
serviceLimiters throttle.ServiceLimiters
serviceLimitersV2 throttle.ServiceLimiters
controllerName string
session awsv2.Config
serviceLimiters throttle.ServiceLimiters
controllerName string

enableIAM bool
allowAdditionalRoles bool
Expand Down Expand Up @@ -311,14 +302,9 @@ func (s *ManagedMachinePoolScope) ClusterObj() cloud.ClusterObject {
return s.Cluster
}

// Session returns the AWS SDK session. Used for creating clients.
func (s *ManagedMachinePoolScope) Session() awsclient.ConfigProvider {
return s.session
}

// SessionV2 returns the AWS SDK V2 config. Used for creating clients.
func (s *ManagedMachinePoolScope) SessionV2() awsv2.Config {
return s.sessionV2
return s.session
}

// ControllerName returns the name of the controller that
Expand Down
18 changes: 5 additions & 13 deletions pkg/cloud/scope/rosacontrolplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"

awsv2 "github.com/aws/aws-sdk-go-v2/aws"
awsclient "github.com/aws/aws-sdk-go/aws/client"
"github.com/aws/aws-sdk-go/service/sts"
"github.com/aws/aws-sdk-go/service/sts/stsiface"
"github.com/pkg/errors"
Expand Down Expand Up @@ -73,7 +72,7 @@ func NewROSAControlPlaneScope(params ROSAControlPlaneScopeParams) (*ROSAControlP
controllerName: params.ControllerName,
}

session, serviceLimiters, err := sessionForClusterWithRegion(params.Client, managedScope, params.ControlPlane.Spec.Region, params.Endpoints, params.Logger)
_, serviceLimiters, err := sessionForClusterWithRegion(params.Client, managedScope, params.ControlPlane.Spec.Region, params.Endpoints, params.Logger)
if err != nil {
return nil, errors.Errorf("failed to create aws session: %v", err)
}
Expand All @@ -89,8 +88,7 @@ func NewROSAControlPlaneScope(params ROSAControlPlaneScopeParams) (*ROSAControlP
}

managedScope.patchHelper = helper
managedScope.session = session
managedScope.sessionV2 = *sessionv2
managedScope.session = *sessionv2
managedScope.serviceLimiters = serviceLimiters
managedScope.serviceLimitersV2 = serviceLimitersv2

Expand All @@ -113,8 +111,7 @@ type ROSAControlPlaneScope struct {
Cluster *clusterv1.Cluster
ControlPlane *rosacontrolplanev1.ROSAControlPlane

session awsclient.ConfigProvider
sessionV2 awsv2.Config
session awsv2.Config
serviceLimiters throttle.ServiceLimiters
serviceLimitersV2 throttle.ServiceLimiters
controllerName string
Expand All @@ -131,16 +128,11 @@ func (s *ROSAControlPlaneScope) IdentityRef() *infrav1.AWSIdentityReference {
return s.ControlPlane.Spec.IdentityRef
}

// Session returns the AWS SDK session. Used for creating clients.
func (s *ROSAControlPlaneScope) Session() awsclient.ConfigProvider {
// Session returns the AWS SDK V2 session. Used for creating clients.
func (s *ROSAControlPlaneScope) Session() awsv2.Config {
return s.session
}

// SessionV2 returns the AWS SDK V2 Config. Used for creating clients.
func (s *ROSAControlPlaneScope) SessionV2() awsv2.Config {
return s.sessionV2
}

// ServiceLimiter returns the AWS SDK session. Used for creating clients.
func (s *ROSAControlPlaneScope) ServiceLimiter(service string) *throttle.ServiceLimiter {
if sl, ok := s.serviceLimiters[service]; ok {
Expand Down
Loading
Loading