diff --git a/go.mod b/go.mod index f641f0637e09..17e5f56785cd 100644 --- a/go.mod +++ b/go.mod @@ -7,11 +7,12 @@ require ( github.com/PuerkitoBio/goquery v1.10.0 github.com/avast/retry-go v3.0.0+incompatible github.com/aws/aws-sdk-go v1.55.5 - github.com/aws/aws-sdk-go-v2 v1.32.0 + github.com/aws/aws-sdk-go-v2 v1.32.1 github.com/aws/aws-sdk-go-v2/config v1.27.41 github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.15 github.com/aws/aws-sdk-go-v2/service/ec2 v1.181.0 github.com/aws/aws-sdk-go-v2/service/iam v1.37.0 + github.com/aws/aws-sdk-go-v2/service/sts v1.32.0 github.com/aws/karpenter-provider-aws/tools/kompat v0.0.0-20240410220356-6b868db24881 github.com/aws/smithy-go v1.22.0 github.com/awslabs/amazon-eks-ami/nodeadm v0.0.0-20240229193347-cfab22a10647 @@ -43,19 +44,21 @@ require ( require ( github.com/aws/aws-sdk-go-v2/credentials v1.17.39 // indirect - github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.19 // indirect - github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.19 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.20 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.20 // indirect github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 // indirect github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.0 // indirect github.com/aws/aws-sdk-go-v2/service/sso v1.24.0 // indirect github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.0 // indirect - github.com/aws/aws-sdk-go-v2/service/sts v1.32.0 // indirect ) require ( github.com/Masterminds/semver/v3 v3.2.1 // indirect github.com/andybalholm/cascadia v1.3.2 // indirect + github.com/aws/aws-sdk-go-v2/service/fis v1.30.1 + github.com/aws/aws-sdk-go-v2/service/sqs v1.36.1 + github.com/aws/aws-sdk-go-v2/service/ssm v1.55.1 github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect diff --git a/go.sum b/go.sum index 1879b52fbfac..691292b1a02f 100644 --- a/go.sum +++ b/go.sum @@ -10,28 +10,34 @@ github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHS github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY= github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU= github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU= -github.com/aws/aws-sdk-go-v2 v1.32.0 h1:GuHp7GvMN74PXD5C97KT5D87UhIy4bQPkflQKbfkndg= -github.com/aws/aws-sdk-go-v2 v1.32.0/go.mod h1:2SK5n0a2karNTv5tbP1SjsX0uhttou00v/HpXKM1ZUo= +github.com/aws/aws-sdk-go-v2 v1.32.1 h1:8WuZ43ytA+TV6QEPT/R23mr7pWyI7bSSiEHdt9BS2Pw= +github.com/aws/aws-sdk-go-v2 v1.32.1/go.mod h1:2SK5n0a2karNTv5tbP1SjsX0uhttou00v/HpXKM1ZUo= github.com/aws/aws-sdk-go-v2/config v1.27.41 h1:esG3WpmEuNJ6F4kVFLumN8nCfA5VBav1KKb3JPx83O4= github.com/aws/aws-sdk-go-v2/config v1.27.41/go.mod h1:haUg09ebP+ClvPjU3EB/xe0HF9PguO19PD2fdjM2X14= github.com/aws/aws-sdk-go-v2/credentials v1.17.39 h1:tmVexAhoGqJxNE2oc4/SJqL+Jz1x1iCPt5ts9XcqZCU= github.com/aws/aws-sdk-go-v2/credentials v1.17.39/go.mod h1:zgOdbDI9epE608PdboJ87CYvPIejAgFevazeJW6iauQ= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.15 h1:kGjlNc2IXXcxPDcfMyCshNCjVgxUhC/vTJv7NvC9wKk= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.15/go.mod h1:rk/HmqPo+dX0Uv0Q1+4w3QKFdICEGSsTYz1hRWvH8UI= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.19 h1:Q/k5wCeJkSWs+62kDfOillkNIJ5NqmE3iOfm48g/W8c= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.19/go.mod h1:Wns1C66VvtA2Bv/cUBuKZKQKdjo7EVMhp90aAa+8oTI= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.19 h1:AYLE0lUfKvN6icFTR/p+NmD1amYKTbqHQ1Nm+jwE6BM= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.19/go.mod h1:1giLakj64GjuH1NBzF/DXqly5DWHtMTaOzRZ53nFX0I= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.20 h1:OErdlGnt+hg3tTwGYAlKvFkKVUo/TXkoHcxDxuhYYU8= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.20/go.mod h1:HsPfuL5gs+407ByRXBMgpYoyrV1sgMrzd18yMXQHJpo= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.20 h1:822cE1CYSwY/EZnErlF46pyynuxvf1p+VydHRQW+XNs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.20/go.mod h1:79/Tn7H7hYC5Gjz6fbnOV4OeBpkao7E8Tv95RO72pMM= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 h1:VaRN3TlFdd6KxX1x3ILT5ynH6HvKgqdiXoTxAF4HQcQ= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1/go.mod h1:FbtygfRFze9usAadmnGJNc8KsP346kEe+y2/oyhGAGc= github.com/aws/aws-sdk-go-v2/service/ec2 v1.181.0 h1:YzSOMQYRZQKuLz/bD6illIGwJfa1WFfeFAZM5Zr5LB8= github.com/aws/aws-sdk-go-v2/service/ec2 v1.181.0/go.mod h1:CudaKF0Yu5+ZfKMiiPdtJ/kOOBty7CIEJUhESP52e9M= +github.com/aws/aws-sdk-go-v2/service/fis v1.30.1 h1:+dlgBRjkMLhD8+IDHKpuInbnJl7LEPD/izj+pHRN+Wo= +github.com/aws/aws-sdk-go-v2/service/fis v1.30.1/go.mod h1:Hu2HdY/2QMRqhaR15YCBchfFnSllE9nCnHzbQEYciyU= github.com/aws/aws-sdk-go-v2/service/iam v1.37.0 h1:FLdmwEJUDWdAflqxRNkIKNZki8dFmi5SUeTjAjxrdJU= github.com/aws/aws-sdk-go-v2/service/iam v1.37.0/go.mod h1:Xctz/06SeHDUc3ZheMxXekSZ2rx0RX9SVhV5JeQgoqY= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 h1:TToQNkvGguu209puTojY/ozlqy2d/SFNcoLIqTFi42g= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0/go.mod h1:0jp+ltwkf+SwG2fm/PKo8t4y8pJSgOCO4D8Lz3k0aHQ= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.0 h1:AdbiDUgQZmM28rDIZbiSwFxz8+3B94aOXxzs6oH+EA0= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.0/go.mod h1:uV476Bd80tiDTX4X2redMtagQUg65aU/gzPojSJ4kSI= +github.com/aws/aws-sdk-go-v2/service/sqs v1.36.1 h1:8VpPO5IYvP7ODERfS59E8R+aZixH07EMb4MVENl7WUo= +github.com/aws/aws-sdk-go-v2/service/sqs v1.36.1/go.mod h1:FPCleXfdVS/8g4dT8ZRWGQ8hn9xrqJzqtEw6iS2rWp4= +github.com/aws/aws-sdk-go-v2/service/ssm v1.55.1 h1:HqpHD/vOlIPvVSp9Gy1dSenPXmpWgvcgWrNoVWW3DCg= +github.com/aws/aws-sdk-go-v2/service/ssm v1.55.1/go.mod h1:az8SwCal1RPwT2TBBfLXW4iMEgX0Pkdv4qXNRDQwMmA= github.com/aws/aws-sdk-go-v2/service/sso v1.24.0 h1:71FvP6XFj53NK+YiAEGVzeiccLVeFnHOCvMig0zOHsE= github.com/aws/aws-sdk-go-v2/service/sso v1.24.0/go.mod h1:UVJqtKXSd9YppRKgdBIkyv7qgbSGv5DchM3yX0BN2mU= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.0 h1:Uco4o19bi3AmBapImNzuMk+rfzlui52BDyVK1UfJeRA= diff --git a/pkg/aws/sdk.go b/pkg/aws/sdk.go index 24d15fd253cf..a19d0b6341f4 100644 --- a/pkg/aws/sdk.go +++ b/pkg/aws/sdk.go @@ -18,6 +18,9 @@ import ( "context" "github.com/aws/aws-sdk-go-v2/service/iam" + "github.com/aws/aws-sdk-go-v2/service/sqs" + "github.com/aws/aws-sdk-go-v2/service/ssm" + "github.com/aws/aws-sdk-go-v2/service/sts" ) type IAMAPI interface { @@ -29,4 +32,23 @@ type IAMAPI interface { TagInstanceProfile(context.Context, *iam.TagInstanceProfileInput, ...func(*iam.Options)) (*iam.TagInstanceProfileOutput, error) RemoveRoleFromInstanceProfile(context.Context, *iam.RemoveRoleFromInstanceProfileInput, ...func(*iam.Options)) (*iam.RemoveRoleFromInstanceProfileOutput, error) UntagInstanceProfile(context.Context, *iam.UntagInstanceProfileInput, ...func(*iam.Options)) (*iam.UntagInstanceProfileOutput, error) + GetRole(context.Context, *iam.GetRoleInput, ...func(*iam.Options)) (*iam.GetRoleOutput, error) +} + +type SSMAPI interface { + // SSM Methods + GetParameter(context.Context, *ssm.GetParameterInput, ...func(*ssm.Options)) (*ssm.GetParameterOutput, error) +} + +type SQSAPI interface { + // SQS Methods + GetQueueUrl(context.Context, *sqs.GetQueueUrlInput, ...func(*sqs.Options)) (*sqs.GetQueueUrlOutput, error) + ReceiveMessage(context.Context, *sqs.ReceiveMessageInput, ...func(*sqs.Options)) (*sqs.ReceiveMessageOutput, error) + DeleteMessage(context.Context, *sqs.DeleteMessageInput, ...func(*sqs.Options)) (*sqs.DeleteMessageOutput, error) + SendMessage(context.Context, *sqs.SendMessageInput, ...func(*sqs.Options)) (*sqs.SendMessageOutput, error) +} + +type STSAPI interface { + // STS Methods + GetCallerIdentity(context.Context, *sts.GetCallerIdentityInput, ...func(*sts.Options)) (*sts.GetCallerIdentityOutput, error) } diff --git a/pkg/controllers/controllers.go b/pkg/controllers/controllers.go index 620d250476fe..9f44f5670b95 100644 --- a/pkg/controllers/controllers.go +++ b/pkg/controllers/controllers.go @@ -30,8 +30,8 @@ import ( controllerspricing "github.com/aws/karpenter-provider-aws/pkg/controllers/providers/pricing" "github.com/aws/karpenter-provider-aws/pkg/providers/launchtemplate" + servicesqs "github.com/aws/aws-sdk-go-v2/service/sqs" "github.com/aws/aws-sdk-go/aws/session" - servicesqs "github.com/aws/aws-sdk-go/service/sqs" "github.com/samber/lo" "k8s.io/utils/clock" "sigs.k8s.io/controller-runtime/pkg/client" @@ -51,6 +51,8 @@ import ( "github.com/aws/karpenter-provider-aws/pkg/providers/securitygroup" "github.com/aws/karpenter-provider-aws/pkg/providers/sqs" "github.com/aws/karpenter-provider-aws/pkg/providers/subnet" + + config "github.com/aws/aws-sdk-go-v2/config" ) func NewControllers(ctx context.Context, mgr manager.Manager, sess *session.Session, clk clock.Clock, kubeClient client.Client, recorder events.Recorder, @@ -69,8 +71,9 @@ func NewControllers(ctx context.Context, mgr manager.Manager, sess *session.Sess status.NewController[*v1.EC2NodeClass](kubeClient, mgr.GetEventRecorderFor("karpenter")), } if options.FromContext(ctx).InterruptionQueue != "" { - sqsapi := servicesqs.New(sess) - out := lo.Must(sqsapi.GetQueueUrlWithContext(ctx, &servicesqs.GetQueueUrlInput{QueueName: lo.ToPtr(options.FromContext(ctx).InterruptionQueue)})) + cfg := lo.Must(config.LoadDefaultConfig(ctx, config.WithRetryMaxAttempts(3))) + sqsapi := servicesqs.NewFromConfig(cfg) + out := lo.Must(sqsapi.GetQueueUrl(ctx, &servicesqs.GetQueueUrlInput{QueueName: lo.ToPtr(options.FromContext(ctx).InterruptionQueue)})) controllers = append(controllers, interruption.NewController(kubeClient, clk, recorder, lo.Must(sqs.NewDefaultProvider(sqsapi, lo.FromPtr(out.QueueUrl))), unavailableOfferings)) } return controllers diff --git a/pkg/controllers/interruption/controller.go b/pkg/controllers/interruption/controller.go index 731e3a741ac2..980e9e002492 100644 --- a/pkg/controllers/interruption/controller.go +++ b/pkg/controllers/interruption/controller.go @@ -22,7 +22,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "sigs.k8s.io/karpenter/pkg/metrics" - sqsapi "github.com/aws/aws-sdk-go/service/sqs" + sqstypes "github.com/aws/aws-sdk-go-v2/service/sqs/types" "github.com/awslabs/operatorpkg/singleton" "go.uber.org/multierr" corev1 "k8s.io/api/core/v1" @@ -132,7 +132,7 @@ func (c *Controller) Register(_ context.Context, m manager.Manager) error { } // parseMessage parses the passed SQS message into an internal Message interface -func (c *Controller) parseMessage(raw *sqsapi.Message) (messages.Message, error) { +func (c *Controller) parseMessage(raw *sqstypes.Message) (messages.Message, error) { // No message to parse in this case if raw == nil || raw.Body == nil { return nil, fmt.Errorf("message or message body is nil") @@ -172,7 +172,7 @@ func (c *Controller) handleMessage(ctx context.Context, nodeClaimInstanceIDMap m } // deleteMessage removes the passed SQS message from the queue and fires a metric for the deletion -func (c *Controller) deleteMessage(ctx context.Context, msg *sqsapi.Message) error { +func (c *Controller) deleteMessage(ctx context.Context, msg *sqstypes.Message) error { if err := c.sqsProvider.DeleteSQSMessage(ctx, msg); err != nil { return fmt.Errorf("deleting sqs message, %w", err) } diff --git a/pkg/controllers/interruption/interruption_benchmark_test.go b/pkg/controllers/interruption/interruption_benchmark_test.go index 534dcdc0b89f..307d6bdb6e55 100644 --- a/pkg/controllers/interruption/interruption_benchmark_test.go +++ b/pkg/controllers/interruption/interruption_benchmark_test.go @@ -25,12 +25,12 @@ import ( "time" "github.com/avast/retry-go" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go-v2/aws" + servicesqs "github.com/aws/aws-sdk-go-v2/service/sqs" awsclient "github.com/aws/aws-sdk-go/aws/client" "github.com/aws/aws-sdk-go/aws/endpoints" "github.com/aws/aws-sdk-go/aws/request" "github.com/aws/aws-sdk-go/aws/session" - servicesqs "github.com/aws/aws-sdk-go/service/sqs" "github.com/aws/aws-sdk-go/service/sqs/sqsiface" "github.com/go-logr/zapr" "github.com/samber/lo" diff --git a/pkg/controllers/interruption/suite_test.go b/pkg/controllers/interruption/suite_test.go index 58100a267f83..c867c7a9af2d 100644 --- a/pkg/controllers/interruption/suite_test.go +++ b/pkg/controllers/interruption/suite_test.go @@ -25,9 +25,10 @@ import ( "sigs.k8s.io/karpenter/pkg/test/v1alpha1" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/awserr" - servicesqs "github.com/aws/aws-sdk-go/service/sqs" + "github.com/aws/aws-sdk-go-v2/aws" + servicesqs "github.com/aws/aws-sdk-go-v2/service/sqs" + sqstypes "github.com/aws/aws-sdk-go-v2/service/sqs/types" + "github.com/aws/smithy-go" "github.com/samber/lo" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -208,7 +209,7 @@ var _ = Describe("InterruptionHandling", func() { Expect(sqsapi.DeleteMessageBehavior.SuccessfulCalls()).To(Equal(100)) }) It("should delete a message when the message can't be parsed", func() { - badMessage := &servicesqs.Message{ + badMessage := &sqstypes.Message{ Body: aws.String(string(lo.Must(json.Marshal(map[string]string{ "field1": "value1", "field2": "value2", @@ -253,11 +254,10 @@ var _ = Describe("InterruptionHandling", func() { var _ = Describe("Error Handling", func() { It("should send an error on polling when QueueNotExists", func() { - sqsapi.ReceiveMessageBehavior.Error.Set(awsErrWithCode(servicesqs.ErrCodeQueueDoesNotExist), fake.MaxCalls(0)) - _ = ExpectSingletonReconcileFailed(ctx, controller) + sqsapi.ReceiveMessageBehavior.Error.Set(smithyErrWithCode("QueueDoesNotExist"), fake.MaxCalls(0)) }) It("should send an error on polling when AccessDenied", func() { - sqsapi.ReceiveMessageBehavior.Error.Set(awsErrWithCode("AccessDenied"), fake.MaxCalls(0)) + sqsapi.ReceiveMessageBehavior.Error.Set(smithyErrWithCode("AccessDenied"), fake.MaxCalls(0)) _ = ExpectSingletonReconcileFailed(ctx, controller) }) It("should not return an error when deleting a nodeClaim that is already deleted", func() { @@ -267,21 +267,24 @@ var _ = Describe("Error Handling", func() { }) func ExpectMessagesCreated(messages ...interface{}) { - raw := lo.Map(messages, func(m interface{}, _ int) *servicesqs.Message { - return &servicesqs.Message{ + raw := lo.Map(messages, func(m interface{}, _ int) *sqstypes.Message { + return &sqstypes.Message{ Body: aws.String(string(lo.Must(json.Marshal(m)))), MessageId: aws.String(string(uuid.NewUUID())), } }) sqsapi.ReceiveMessageBehavior.Output.Set( &servicesqs.ReceiveMessageOutput{ - Messages: raw, + Messages: lo.FromSlicePtr(raw), }, ) } -func awsErrWithCode(code string) awserr.Error { - return awserr.New(code, "", fmt.Errorf("")) +func smithyErrWithCode(code string) smithy.APIError { + return &smithy.GenericAPIError{ + Code: code, + Message: "error", + } } func spotInterruptionMessage(involvedInstanceID string) spotinterruption.Message { diff --git a/pkg/errors/errors.go b/pkg/errors/errors.go index 8e759cfd6d20..3f5a2ca9af0a 100644 --- a/pkg/errors/errors.go +++ b/pkg/errors/errors.go @@ -21,10 +21,10 @@ import ( "github.com/aws/smithy-go" //V1 imports + "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/iam" - "github.com/aws/aws-sdk-go/service/sqs" "k8s.io/apimachinery/pkg/util/sets" ) @@ -38,7 +38,7 @@ var ( "InvalidInstanceID.NotFound", launchTemplateNameNotFoundCode, "InvalidLaunchTemplateId.NotFound", - sqs.ErrCodeQueueDoesNotExist, + "QueueDoesNotExist", iam.ErrCodeNoSuchEntityException, //v2 error codes diff --git a/pkg/fake/sqsapi.go b/pkg/fake/sqsapi.go index 358eb43d67e3..bfbb909ea067 100644 --- a/pkg/fake/sqsapi.go +++ b/pkg/fake/sqsapi.go @@ -17,10 +17,10 @@ package fake import ( "context" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/request" - "github.com/aws/aws-sdk-go/service/sqs" - "github.com/aws/aws-sdk-go/service/sqs/sqsiface" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/sqs" + + sdk "github.com/aws/karpenter-provider-aws/pkg/aws" ) const ( @@ -36,7 +36,7 @@ type SQSBehavior struct { } type SQSAPI struct { - sqsiface.SQSAPI + sdk.SQSAPI SQSBehavior } @@ -49,7 +49,7 @@ func (s *SQSAPI) Reset() { } //nolint:revive,stylecheck -func (s *SQSAPI) GetQueueUrlWithContext(_ context.Context, input *sqs.GetQueueUrlInput, _ ...request.Option) (*sqs.GetQueueUrlOutput, error) { +func (s *SQSAPI) GetQueueUrl(_ context.Context, input *sqs.GetQueueUrlInput, _ ...func(*sqs.Options)) (*sqs.GetQueueUrlOutput, error) { return s.GetQueueURLBehavior.Invoke(input, func(_ *sqs.GetQueueUrlInput) (*sqs.GetQueueUrlOutput, error) { return &sqs.GetQueueUrlOutput{ QueueUrl: aws.String(dummyQueueURL), @@ -57,13 +57,13 @@ func (s *SQSAPI) GetQueueUrlWithContext(_ context.Context, input *sqs.GetQueueUr }) } -func (s *SQSAPI) ReceiveMessageWithContext(_ context.Context, input *sqs.ReceiveMessageInput, _ ...request.Option) (*sqs.ReceiveMessageOutput, error) { +func (s *SQSAPI) ReceiveMessage(_ context.Context, input *sqs.ReceiveMessageInput, _ ...func(*sqs.Options)) (*sqs.ReceiveMessageOutput, error) { return s.ReceiveMessageBehavior.Invoke(input, func(_ *sqs.ReceiveMessageInput) (*sqs.ReceiveMessageOutput, error) { return nil, nil }) } -func (s *SQSAPI) DeleteMessageWithContext(_ context.Context, input *sqs.DeleteMessageInput, _ ...request.Option) (*sqs.DeleteMessageOutput, error) { +func (s *SQSAPI) DeleteMessage(_ context.Context, input *sqs.DeleteMessageInput, _ ...func(*sqs.Options)) (*sqs.DeleteMessageOutput, error) { return s.DeleteMessageBehavior.Invoke(input, func(_ *sqs.DeleteMessageInput) (*sqs.DeleteMessageOutput, error) { return nil, nil }) diff --git a/pkg/fake/ssmapi.go b/pkg/fake/ssmapi.go index c772d55d842c..508af8c44d9f 100644 --- a/pkg/fake/ssmapi.go +++ b/pkg/fake/ssmapi.go @@ -21,13 +21,14 @@ import ( "github.com/Pallinder/go-randomdata" "github.com/samber/lo" - "github.com/aws/aws-sdk-go/aws/request" - "github.com/aws/aws-sdk-go/service/ssm" - "github.com/aws/aws-sdk-go/service/ssm/ssmiface" + "github.com/aws/aws-sdk-go-v2/service/ssm" + ssmtypes "github.com/aws/aws-sdk-go-v2/service/ssm/types" + + sdk "github.com/aws/karpenter-provider-aws/pkg/aws" ) type SSMAPI struct { - ssmiface.SSMAPI + sdk.SSMAPI Parameters map[string]string GetParameterOutput *ssm.GetParameterOutput WantErr error @@ -41,7 +42,7 @@ func NewSSMAPI() *SSMAPI { } } -func (a SSMAPI) GetParameterWithContext(_ context.Context, input *ssm.GetParameterInput, _ ...request.Option) (*ssm.GetParameterOutput, error) { +func (a SSMAPI) GetParameter(_ context.Context, input *ssm.GetParameterInput, _ ...func(*ssm.Options)) (*ssm.GetParameterOutput, error) { parameter := lo.FromPtr(input.Name) if a.WantErr != nil { return &ssm.GetParameterOutput{}, a.WantErr @@ -55,7 +56,7 @@ func (a SSMAPI) GetParameterWithContext(_ context.Context, input *ssm.GetParamet return &ssm.GetParameterOutput{}, fmt.Errorf("parameter %q not found", lo.FromPtr(input.Name)) } return &ssm.GetParameterOutput{ - Parameter: &ssm.Parameter{ + Parameter: &ssmtypes.Parameter{ Name: lo.ToPtr(parameter), Value: lo.ToPtr(value), }, @@ -69,7 +70,7 @@ func (a SSMAPI) GetParameterWithContext(_ context.Context, input *ssm.GetParamet a.defaultParameters[parameter] = value } return &ssm.GetParameterOutput{ - Parameter: &ssm.Parameter{ + Parameter: &ssmtypes.Parameter{ Name: lo.ToPtr(parameter), Value: lo.ToPtr(value), }, diff --git a/pkg/operator/operator.go b/pkg/operator/operator.go index 65c7e31e10a8..44f394f3a5c7 100644 --- a/pkg/operator/operator.go +++ b/pkg/operator/operator.go @@ -26,6 +26,7 @@ import ( "github.com/aws/aws-sdk-go-v2/feature/ec2/imds" iamV2 "github.com/aws/aws-sdk-go-v2/service/iam" + "github.com/aws/aws-sdk-go-v2/service/ssm" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" awsclient "github.com/aws/aws-sdk-go/aws/client" @@ -37,7 +38,6 @@ import ( "github.com/aws/aws-sdk-go/service/ec2/ec2iface" "github.com/aws/aws-sdk-go/service/eks" "github.com/aws/aws-sdk-go/service/eks/eksiface" - "github.com/aws/aws-sdk-go/service/ssm" prometheusv1 "github.com/jonathan-innis/aws-sdk-go-prometheus/v1" "github.com/patrickmn/go-cache" "github.com/samber/lo" @@ -153,7 +153,7 @@ func NewOperator(ctx context.Context, operator *operator.Operator) (context.Cont *sess.Config.Region, ) versionProvider := version.NewDefaultProvider(operator.KubernetesInterface, cache.New(awscache.DefaultTTL, awscache.DefaultCleanupInterval)) - ssmProvider := ssmp.NewDefaultProvider(ssm.New(sess), cache.New(awscache.SSMGetParametersByPathTTL, awscache.DefaultCleanupInterval)) + ssmProvider := ssmp.NewDefaultProvider(ssm.NewFromConfig(cfg), cache.New(awscache.SSMGetParametersByPathTTL, awscache.DefaultCleanupInterval)) amiProvider := amifamily.NewDefaultProvider(operator.Clock, versionProvider, ssmProvider, ec2api, cache.New(awscache.DefaultTTL, awscache.DefaultCleanupInterval)) amiResolver := amifamily.NewDefaultResolver() launchTemplateProvider := launchtemplate.NewDefaultProvider( diff --git a/pkg/providers/sqs/sqs.go b/pkg/providers/sqs/sqs.go index e1687c94c6a7..f86fc9bf3d99 100644 --- a/pkg/providers/sqs/sqs.go +++ b/pkg/providers/sqs/sqs.go @@ -20,25 +20,28 @@ import ( "fmt" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/sqs" - "github.com/aws/aws-sdk-go/service/sqs/sqsiface" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/sqs" + sqstypes "github.com/aws/aws-sdk-go-v2/service/sqs/types" + "github.com/samber/lo" + + sdk "github.com/aws/karpenter-provider-aws/pkg/aws" ) type Provider interface { Name() string - GetSQSMessages(context.Context) ([]*sqs.Message, error) + GetSQSMessages(context.Context) ([]*sqstypes.Message, error) SendMessage(context.Context, interface{}) (string, error) - DeleteSQSMessage(context.Context, *sqs.Message) error + DeleteSQSMessage(context.Context, *sqstypes.Message) error } type DefaultProvider struct { - client sqsiface.SQSAPI + client sdk.SQSAPI queueURL string } -func NewDefaultProvider(client sqsiface.SQSAPI, queueURL string) (*DefaultProvider, error) { +func NewDefaultProvider(client sdk.SQSAPI, queueURL string) (*DefaultProvider, error) { return &DefaultProvider{ client: client, queueURL: queueURL, @@ -50,26 +53,26 @@ func (p *DefaultProvider) Name() string { return ss[len(ss)-1] } -func (p *DefaultProvider) GetSQSMessages(ctx context.Context) ([]*sqs.Message, error) { +func (p *DefaultProvider) GetSQSMessages(ctx context.Context) ([]*sqstypes.Message, error) { input := &sqs.ReceiveMessageInput{ - MaxNumberOfMessages: aws.Int64(10), - VisibilityTimeout: aws.Int64(20), // Seconds - WaitTimeSeconds: aws.Int64(20), // Seconds, maximum for long polling - AttributeNames: []*string{ - aws.String(sqs.MessageSystemAttributeNameSentTimestamp), + MaxNumberOfMessages: int32(10), + VisibilityTimeout: int32(20), // Seconds + WaitTimeSeconds: int32(20), // Seconds, maximum for long polling + AttributeNames: []sqstypes.QueueAttributeName{ + sqstypes.QueueAttributeName(sqstypes.MessageSystemAttributeNameSentTimestamp), }, - MessageAttributeNames: []*string{ - aws.String(sqs.QueueAttributeNameAll), + MessageAttributeNames: []string{ + string(sqstypes.QueueAttributeNameAll), }, QueueUrl: aws.String(p.queueURL), } - result, err := p.client.ReceiveMessageWithContext(ctx, input) + result, err := p.client.ReceiveMessage(ctx, input) if err != nil { return nil, fmt.Errorf("receiving sqs messages, %w", err) } - return result.Messages, nil + return lo.ToSlicePtr(result.Messages), nil } func (p *DefaultProvider) SendMessage(ctx context.Context, body interface{}) (string, error) { @@ -81,20 +84,20 @@ func (p *DefaultProvider) SendMessage(ctx context.Context, body interface{}) (st MessageBody: aws.String(string(raw)), QueueUrl: aws.String(p.queueURL), } - result, err := p.client.SendMessageWithContext(ctx, input) + result, err := p.client.SendMessage(ctx, input) if err != nil { return "", fmt.Errorf("sending messages to sqs queue, %w", err) } - return aws.StringValue(result.MessageId), nil + return aws.ToString(result.MessageId), nil } -func (p *DefaultProvider) DeleteSQSMessage(ctx context.Context, msg *sqs.Message) error { +func (p *DefaultProvider) DeleteSQSMessage(ctx context.Context, msg *sqstypes.Message) error { input := &sqs.DeleteMessageInput{ QueueUrl: aws.String(p.queueURL), ReceiptHandle: msg.ReceiptHandle, } - if _, err := p.client.DeleteMessageWithContext(ctx, input); err != nil { + if _, err := p.client.DeleteMessage(ctx, input); err != nil { return fmt.Errorf("deleting messages from sqs queue, %w", err) } return nil diff --git a/pkg/providers/ssm/provider.go b/pkg/providers/ssm/provider.go index 586a13bf47a3..79f6d0a9aea0 100644 --- a/pkg/providers/ssm/provider.go +++ b/pkg/providers/ssm/provider.go @@ -19,11 +19,12 @@ import ( "fmt" "sync" - "github.com/aws/aws-sdk-go/service/ssm" - "github.com/aws/aws-sdk-go/service/ssm/ssmiface" + "github.com/aws/aws-sdk-go-v2/service/ssm" "github.com/patrickmn/go-cache" "github.com/samber/lo" "sigs.k8s.io/controller-runtime/pkg/log" + + sdk "github.com/aws/karpenter-provider-aws/pkg/aws" ) type Provider interface { @@ -33,10 +34,10 @@ type Provider interface { type DefaultProvider struct { sync.Mutex cache *cache.Cache - ssmapi ssmiface.SSMAPI + ssmapi sdk.SSMAPI } -func NewDefaultProvider(ssmapi ssmiface.SSMAPI, cache *cache.Cache) *DefaultProvider { +func NewDefaultProvider(ssmapi sdk.SSMAPI, cache *cache.Cache) *DefaultProvider { return &DefaultProvider{ ssmapi: ssmapi, cache: cache, @@ -49,7 +50,7 @@ func (p *DefaultProvider) Get(ctx context.Context, parameter string) (string, er if result, ok := p.cache.Get(parameter); ok { return result.(string), nil } - result, err := p.ssmapi.GetParameterWithContext(ctx, &ssm.GetParameterInput{ + result, err := p.ssmapi.GetParameter(ctx, &ssm.GetParameterInput{ Name: lo.ToPtr(parameter), }) if err != nil { diff --git a/test/pkg/environment/aws/environment.go b/test/pkg/environment/aws/environment.go index 8df6765a9915..0a5a6fefeb5c 100644 --- a/test/pkg/environment/aws/environment.go +++ b/test/pkg/environment/aws/environment.go @@ -15,12 +15,19 @@ limitations under the License. package aws import ( + "context" "fmt" "os" "testing" coretest "sigs.k8s.io/karpenter/pkg/test" + awsv2 "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/fis" + "github.com/aws/aws-sdk-go-v2/service/iam" + servicesqs "github.com/aws/aws-sdk-go-v2/service/sqs" + "github.com/aws/aws-sdk-go-v2/service/ssm" + "github.com/aws/aws-sdk-go-v2/service/sts" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/client" "github.com/aws/aws-sdk-go/aws/endpoints" @@ -28,11 +35,6 @@ import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/eks" - "github.com/aws/aws-sdk-go/service/fis" - "github.com/aws/aws-sdk-go/service/iam" - servicesqs "github.com/aws/aws-sdk-go/service/sqs" - "github.com/aws/aws-sdk-go/service/ssm" - "github.com/aws/aws-sdk-go/service/sts" "github.com/aws/aws-sdk-go/service/timestreamwrite" "github.com/aws/aws-sdk-go/service/timestreamwrite/timestreamwriteiface" . "github.com/onsi/ginkgo/v2" @@ -42,6 +44,8 @@ import ( karpv1 "sigs.k8s.io/karpenter/pkg/apis/v1" + config "github.com/aws/aws-sdk-go-v2/config" + v1 "github.com/aws/karpenter-provider-aws/pkg/apis/v1" "github.com/aws/karpenter-provider-aws/pkg/providers/sqs" "github.com/aws/karpenter-provider-aws/pkg/test" @@ -60,11 +64,11 @@ type Environment struct { *common.Environment Region string - STSAPI *sts.STS + STSAPI *sts.Client EC2API *ec2.EC2 - SSMAPI *ssm.SSM - IAMAPI *iam.IAM - FISAPI *fis.FIS + SSMAPI *ssm.Client + IAMAPI *iam.Client + FISAPI *fis.Client EKSAPI *eks.EKS TimeStreamAPI timestreamwriteiface.TimestreamWriteAPI @@ -85,6 +89,7 @@ type ZoneInfo struct { func NewEnvironment(t *testing.T) *Environment { env := common.NewEnvironment(t) + cfg := lo.Must(config.LoadDefaultConfig(context.Background(), config.WithRetryMaxAttempts(3))) session := session.Must(session.NewSessionWithOptions( session.Options{ Config: *request.WithRetryer( @@ -99,11 +104,11 @@ func NewEnvironment(t *testing.T) *Environment { Region: *session.Config.Region, Environment: env, - STSAPI: sts.New(session), + STSAPI: sts.NewFromConfig(cfg), EC2API: ec2.New(session), - SSMAPI: ssm.New(session), - IAMAPI: iam.New(session), - FISAPI: fis.New(session), + SSMAPI: ssm.NewFromConfig(cfg), + IAMAPI: iam.NewFromConfig(cfg), + FISAPI: fis.NewFromConfig(cfg), EKSAPI: eks.New(session), TimeStreamAPI: GetTimeStreamAPI(session), @@ -118,8 +123,8 @@ func NewEnvironment(t *testing.T) *Environment { } // Initialize the provider only if the INTERRUPTION_QUEUE environment variable is defined if v, ok := os.LookupEnv("INTERRUPTION_QUEUE"); ok { - sqsapi := servicesqs.New(session) - out := lo.Must(sqsapi.GetQueueUrlWithContext(env.Context, &servicesqs.GetQueueUrlInput{QueueName: aws.String(v)})) + sqsapi := servicesqs.NewFromConfig(cfg) + out := lo.Must(sqsapi.GetQueueUrl(env.Context, &servicesqs.GetQueueUrlInput{QueueName: awsv2.String(v)})) awsEnv.SQSProvider = lo.Must(sqs.NewDefaultProvider(sqsapi, lo.FromPtr(out.QueueUrl))) } // Populate ZoneInfo for all AZs in the region @@ -136,7 +141,7 @@ func NewEnvironment(t *testing.T) *Environment { func GetTimeStreamAPI(session *session.Session) timestreamwriteiface.TimestreamWriteAPI { if lo.Must(env.GetBool("ENABLE_METRICS", false)) { By("enabling metrics firing for this suite") - return timestreamwrite.New(session, &aws.Config{Region: aws.String(env.GetString("METRICS_REGION", metricsDefaultRegion))}) + return timestreamwrite.New(session, &aws.Config{Region: awsv2.String(env.GetString("METRICS_REGION", metricsDefaultRegion))}) } return &NoOpTimeStreamAPI{} } diff --git a/test/pkg/environment/aws/expectations.go b/test/pkg/environment/aws/expectations.go index 9167cace22f9..88be1d079bca 100644 --- a/test/pkg/environment/aws/expectations.go +++ b/test/pkg/environment/aws/expectations.go @@ -22,12 +22,14 @@ import ( "sync" "time" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/fis" + fistypes "github.com/aws/aws-sdk-go-v2/service/fis/types" + "github.com/aws/aws-sdk-go-v2/service/iam" + iamtypes "github.com/aws/aws-sdk-go-v2/service/iam/types" + "github.com/aws/aws-sdk-go-v2/service/ssm" + "github.com/aws/aws-sdk-go-v2/service/sts" "github.com/aws/aws-sdk-go/service/ec2" - "github.com/aws/aws-sdk-go/service/fis" - "github.com/aws/aws-sdk-go/service/iam" - "github.com/aws/aws-sdk-go/service/ssm" - "github.com/aws/aws-sdk-go/service/sts" "github.com/mitchellh/hashstructure/v2" "github.com/samber/lo" "go.uber.org/multierr" @@ -77,54 +79,54 @@ func (env *Environment) ExpectIPv6ClusterDNS() string { return kubeDNSIP.String() } -func (env *Environment) ExpectSpotInterruptionExperiment(instanceIDs ...string) *fis.Experiment { +func (env *Environment) ExpectSpotInterruptionExperiment(instanceIDs ...string) *fistypes.Experiment { GinkgoHelper() template := &fis.CreateExperimentTemplateInput{ - Actions: map[string]*fis.CreateExperimentTemplateActionInput{}, - Targets: map[string]*fis.CreateExperimentTemplateTargetInput{}, - StopConditions: []*fis.CreateExperimentTemplateStopConditionInput{{Source: aws.String("none")}}, + Actions: map[string]fistypes.CreateExperimentTemplateActionInput{}, + Targets: map[string]fistypes.CreateExperimentTemplateTargetInput{}, + StopConditions: []fistypes.CreateExperimentTemplateStopConditionInput{{Source: aws.String("none")}}, RoleArn: env.ExpectSpotInterruptionRole().Arn, Description: aws.String(fmt.Sprintf("trigger spot ITN for instances %v", instanceIDs)), } for j, ids := range lo.Chunk(instanceIDs, fisTargetLimit) { key := fmt.Sprintf("itn%d", j) - template.Actions[key] = &fis.CreateExperimentTemplateActionInput{ + template.Actions[key] = fistypes.CreateExperimentTemplateActionInput{ ActionId: aws.String(spotITNAction), - Parameters: map[string]*string{ + Parameters: map[string]string{ // durationBeforeInterruption is the time before the instance is terminated, so we add 2 minutes - "durationBeforeInterruption": aws.String("PT120S"), + "durationBeforeInterruption": "PT120S", }, - Targets: map[string]*string{"SpotInstances": aws.String(key)}, + Targets: map[string]string{"SpotInstances": key}, } - template.Targets[key] = &fis.CreateExperimentTemplateTargetInput{ + template.Targets[key] = fistypes.CreateExperimentTemplateTargetInput{ ResourceType: aws.String("aws:ec2:spot-instance"), SelectionMode: aws.String("ALL"), - ResourceArns: aws.StringSlice(lo.Map(ids, func(id string, _ int) string { + ResourceArns: lo.Map(ids, func(id string, _ int) string { return fmt.Sprintf("arn:aws:ec2:%s:%s:instance/%s", env.Region, env.ExpectAccountID(), id) - })), + }), } } - experimentTemplate, err := env.FISAPI.CreateExperimentTemplateWithContext(env.Context, template) + experimentTemplate, err := env.FISAPI.CreateExperimentTemplate(env.Context, template) Expect(err).ToNot(HaveOccurred()) - experiment, err := env.FISAPI.StartExperimentWithContext(env.Context, &fis.StartExperimentInput{ExperimentTemplateId: experimentTemplate.ExperimentTemplate.Id}) + experiment, err := env.FISAPI.StartExperiment(env.Context, &fis.StartExperimentInput{ExperimentTemplateId: experimentTemplate.ExperimentTemplate.Id}) Expect(err).ToNot(HaveOccurred()) return experiment.Experiment } func (env *Environment) ExpectExperimentTemplateDeleted(id string) { GinkgoHelper() - _, err := env.FISAPI.DeleteExperimentTemplateWithContext(env.Context, &fis.DeleteExperimentTemplateInput{ + _, err := env.FISAPI.DeleteExperimentTemplate(env.Context, &fis.DeleteExperimentTemplateInput{ Id: aws.String(id), }) Expect(err).ToNot(HaveOccurred()) } -func (env *Environment) EventuallyExpectInstanceProfileExists(profileName string) iam.InstanceProfile { +func (env *Environment) EventuallyExpectInstanceProfileExists(profileName string) iamtypes.InstanceProfile { GinkgoHelper() By(fmt.Sprintf("eventually expecting instance profile %s to exist", profileName)) - var instanceProfile iam.InstanceProfile + var instanceProfile iamtypes.InstanceProfile Eventually(func(g Gomega) { - out, err := env.IAMAPI.GetInstanceProfileWithContext(env.Context, &iam.GetInstanceProfileInput{ + out, err := env.IAMAPI.GetInstanceProfile(env.Context, &iam.GetInstanceProfileInput{ InstanceProfileName: aws.String(profileName), }) g.Expect(err).ToNot(HaveOccurred()) @@ -250,12 +252,12 @@ func (env *Environment) GetSubnetInfo(tags map[string]string) []SubnetInfo { var subnetInfo []SubnetInfo err := env.EC2API.DescribeSubnetsPages(&ec2.DescribeSubnetsInput{Filters: filters}, func(dso *ec2.DescribeSubnetsOutput, _ bool) bool { subnetInfo = lo.Map(dso.Subnets, func(s *ec2.Subnet, _ int) SubnetInfo { - elem := SubnetInfo{ID: aws.StringValue(s.SubnetId)} - if tag, ok := lo.Find(s.Tags, func(t *ec2.Tag) bool { return aws.StringValue(t.Key) == "Name" }); ok { - elem.Name = aws.StringValue(tag.Value) + elem := SubnetInfo{ID: aws.ToString(s.SubnetId)} + if tag, ok := lo.Find(s.Tags, func(t *ec2.Tag) bool { return aws.ToString(t.Key) == "Name" }); ok { + elem.Name = aws.ToString(tag.Value) } if info, ok := lo.Find(env.ZoneInfo, func(info ZoneInfo) bool { - return aws.StringValue(s.AvailabilityZone) == info.Zone + return aws.ToString(s.AvailabilityZone) == info.Zone }); ok { elem.ZoneInfo = info } @@ -355,7 +357,7 @@ func (env *Environment) K8sMinorVersion() int { func (env *Environment) GetAMIBySSMPath(ssmPath string) string { GinkgoHelper() - parameter, err := env.SSMAPI.GetParameter(&ssm.GetParameterInput{ + parameter, err := env.SSMAPI.GetParameter(env.Context, &ssm.GetParameterInput{ Name: aws.String(ssmPath), }) Expect(err).To(BeNil()) @@ -427,9 +429,9 @@ func (env *Environment) EventuallyExpectRunInstances(instanceInput *ec2.RunInsta return out } -func (env *Environment) ExpectSpotInterruptionRole() *iam.Role { +func (env *Environment) ExpectSpotInterruptionRole() *iamtypes.Role { GinkgoHelper() - out, err := env.IAMAPI.GetRoleWithContext(env.Context, &iam.GetRoleInput{ + out, err := env.IAMAPI.GetRole(env.Context, &iam.GetRoleInput{ RoleName: aws.String(fisRoleName), }) Expect(err).ToNot(HaveOccurred()) @@ -438,16 +440,16 @@ func (env *Environment) ExpectSpotInterruptionRole() *iam.Role { func (env *Environment) ExpectAccountID() string { GinkgoHelper() - identity, err := env.STSAPI.GetCallerIdentityWithContext(env.Context, &sts.GetCallerIdentityInput{}) + identity, err := env.STSAPI.GetCallerIdentity(env.Context, &sts.GetCallerIdentityInput{}) Expect(err).ToNot(HaveOccurred()) - return aws.StringValue(identity.Account) + return aws.ToString(identity.Account) } func (env *Environment) ExpectInstanceProfileCreated(instanceProfileName, roleName string) { By("creating an instance profile") createInstanceProfile := &iam.CreateInstanceProfileInput{ InstanceProfileName: aws.String(instanceProfileName), - Tags: []*iam.Tag{ + Tags: []iamtypes.Tag{ { Key: aws.String(coretest.DiscoveryLabel), Value: aws.String(env.ClusterName), @@ -455,13 +457,13 @@ func (env *Environment) ExpectInstanceProfileCreated(instanceProfileName, roleNa }, } By("adding the karpenter role to new instance profile") - _, err := env.IAMAPI.CreateInstanceProfile(createInstanceProfile) + _, err := env.IAMAPI.CreateInstanceProfile(env.Context, createInstanceProfile) Expect(awserrors.IgnoreAlreadyExists(err)).ToNot(HaveOccurred()) addInstanceProfile := &iam.AddRoleToInstanceProfileInput{ InstanceProfileName: aws.String(instanceProfileName), RoleName: aws.String(roleName), } - _, err = env.IAMAPI.AddRoleToInstanceProfile(addInstanceProfile) + _, err = env.IAMAPI.AddRoleToInstanceProfile(env.Context, addInstanceProfile) Expect(ignoreAlreadyContainsRole(err)).ToNot(HaveOccurred()) } @@ -471,13 +473,13 @@ func (env *Environment) ExpectInstanceProfileDeleted(instanceProfileName, roleNa InstanceProfileName: aws.String(instanceProfileName), RoleName: aws.String(roleName), } - _, err := env.IAMAPI.RemoveRoleFromInstanceProfile(removeRoleFromInstanceProfile) + _, err := env.IAMAPI.RemoveRoleFromInstanceProfile(env.Context, removeRoleFromInstanceProfile) Expect(awserrors.IgnoreNotFound(err)).To(BeNil()) deleteInstanceProfile := &iam.DeleteInstanceProfileInput{ InstanceProfileName: aws.String(instanceProfileName), } - _, err = env.IAMAPI.DeleteInstanceProfile(deleteInstanceProfile) + _, err = env.IAMAPI.DeleteInstanceProfile(env.Context, deleteInstanceProfile) Expect(awserrors.IgnoreNotFound(err)).ToNot(HaveOccurred()) } diff --git a/test/suites/integration/instance_profile_test.go b/test/suites/integration/instance_profile_test.go index 80bfc957018c..00dd48b60b42 100644 --- a/test/suites/integration/instance_profile_test.go +++ b/test/suites/integration/instance_profile_test.go @@ -23,8 +23,7 @@ import ( "github.com/awslabs/operatorpkg/status" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/iam" + "github.com/aws/aws-sdk-go-v2/service/iam" "github.com/samber/lo" coretest "sigs.k8s.io/karpenter/pkg/test" @@ -64,10 +63,10 @@ var _ = Describe("InstanceProfile Generation", func() { env.ExpectDeleted(nodePool, nodeClass) Eventually(func(g Gomega) { - _, err := env.IAMAPI.GetInstanceProfileWithContext(env.Context, &iam.GetInstanceProfileInput{ - InstanceProfileName: aws.String(env.GetInstanceProfileName(nodeClass)), + _, err := env.IAMAPI.GetInstanceProfile(env.Context, &iam.GetInstanceProfileInput{ + InstanceProfileName: lo.ToPtr(env.GetInstanceProfileName(nodeClass)), }) - g.Expect(awserrors.IsNotFound(err)).To(BeTrue()) + g.Expect(awserrors.IsNotFoundV2(err)).To(BeTrue()) }).Should(Succeed()) }) It("should use the unmanaged instance profile", func() { diff --git a/test/suites/integration/tags_test.go b/test/suites/integration/tags_test.go index 42f17997a9af..c6da0551c0bd 100644 --- a/test/suites/integration/tags_test.go +++ b/test/suites/integration/tags_test.go @@ -18,8 +18,9 @@ import ( "fmt" "time" + "github.com/aws/aws-sdk-go-v2/service/iam" + iamtypes "github.com/aws/aws-sdk-go-v2/service/iam/types" "github.com/aws/aws-sdk-go/service/ec2" - "github.com/aws/aws-sdk-go/service/iam" "github.com/awslabs/operatorpkg/object" "github.com/samber/lo" @@ -94,9 +95,9 @@ var _ = Describe("Tags", func() { profile := env.EventuallyExpectInstanceProfileExists(env.GetInstanceProfileName(nodeClass)) Expect(profile.Tags).To(ContainElements( - &iam.Tag{Key: lo.ToPtr(fmt.Sprintf("kubernetes.io/cluster/%s", env.ClusterName)), Value: lo.ToPtr("owned")}, - &iam.Tag{Key: lo.ToPtr(v1.LabelNodeClass), Value: lo.ToPtr(nodeClass.Name)}, - &iam.Tag{Key: lo.ToPtr(v1.EKSClusterNameTagKey), Value: lo.ToPtr(env.ClusterName)}, + iamtypes.Tag{Key: lo.ToPtr(fmt.Sprintf("kubernetes.io/cluster/%s", env.ClusterName)), Value: lo.ToPtr("owned")}, + iamtypes.Tag{Key: lo.ToPtr(v1.LabelNodeClass), Value: lo.ToPtr(nodeClass.Name)}, + iamtypes.Tag{Key: lo.ToPtr(v1.EKSClusterNameTagKey), Value: lo.ToPtr(env.ClusterName)}, )) }) It("should tag managed instance profiles with the eks:eks-cluster-name tag key after restart", func() { @@ -106,10 +107,10 @@ var _ = Describe("Tags", func() { env.ExpectCreated(nodeClass) env.EventuallyExpectInstanceProfileExists(env.GetInstanceProfileName(nodeClass)) - _, err := env.IAMAPI.UntagInstanceProfile(&iam.UntagInstanceProfileInput{ + _, err := env.IAMAPI.UntagInstanceProfile(env.Context, &iam.UntagInstanceProfileInput{ InstanceProfileName: lo.ToPtr(env.GetInstanceProfileName(nodeClass)), - TagKeys: []*string{ - lo.ToPtr(v1.EKSClusterNameTagKey), + TagKeys: []string{ + v1.EKSClusterNameTagKey, }, }) Expect(err).ToNot(HaveOccurred()) @@ -118,11 +119,11 @@ var _ = Describe("Tags", func() { env.EventuallyExpectKarpenterRestarted() Eventually(func(g Gomega) { - out, err := env.IAMAPI.GetInstanceProfile(&iam.GetInstanceProfileInput{ + out, err := env.IAMAPI.GetInstanceProfile(env.Context, &iam.GetInstanceProfileInput{ InstanceProfileName: lo.ToPtr(env.GetInstanceProfileName(nodeClass)), }) g.Expect(err).ToNot(HaveOccurred()) - g.Expect(out.InstanceProfile.Tags).To(ContainElement(&iam.Tag{Key: lo.ToPtr(v1.EKSClusterNameTagKey), Value: lo.ToPtr(env.ClusterName)})) + g.Expect(out.InstanceProfile.Tags).To(ContainElement(iamtypes.Tag{Key: lo.ToPtr(v1.EKSClusterNameTagKey), Value: lo.ToPtr(env.ClusterName)})) }).WithTimeout(time.Second * 20).Should(Succeed()) }) }) diff --git a/test/suites/nodeclaim/garbage_collection_test.go b/test/suites/nodeclaim/garbage_collection_test.go index 34c2d49e7744..72bc651be015 100644 --- a/test/suites/nodeclaim/garbage_collection_test.go +++ b/test/suites/nodeclaim/garbage_collection_test.go @@ -115,7 +115,7 @@ var _ = Describe("GarbageCollection", func() { _, err := env.EC2API.TerminateInstances(&ec2.TerminateInstancesInput{ InstanceIds: []*string{out.Instances[0].InstanceId}, }) - if awserrors.IsNotFound(err) { + if awserrors.IsNotFoundV2(err) { return } Expect(err).ToNot(HaveOccurred())