Skip to content

🌱 Migrate gc to aws sdk v2 #5518

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 1 commit 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
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ require (
github.com/apparentlymart/go-cidr v1.1.0
github.com/aws/amazon-vpc-cni-k8s v1.15.5
github.com/aws/aws-lambda-go v1.41.0
github.com/aws/aws-sdk-go v1.55.5
github.com/aws/aws-sdk-go v1.55.7
github.com/aws/aws-sdk-go-v2 v1.36.5
github.com/aws/aws-sdk-go-v2/config v1.27.11
github.com/aws/aws-sdk-go-v2/credentials v1.17.11
github.com/aws/aws-sdk-go-v2/service/autoscaling v1.52.4
github.com/aws/aws-sdk-go-v2/service/ec2 v1.159.0
github.com/aws/aws-sdk-go-v2/service/eks v1.64.0
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.29.6
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.34.0
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.45.2
github.com/aws/aws-sdk-go-v2/service/iam v1.32.0
github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.26.6
github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.28.6
github.com/aws/aws-sdk-go-v2/service/ssm v1.59.1
github.com/aws/aws-sdk-go-v2/service/sts v1.28.6
github.com/aws/smithy-go v1.22.4
Expand Down Expand Up @@ -89,14 +91,12 @@ require (
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.36 // indirect
github.com/aws/aws-sdk-go-v2/service/cloudformation v1.50.0 // indirect
github.com/aws/aws-sdk-go-v2/service/ec2 v1.159.0
github.com/aws/aws-sdk-go-v2/service/eventbridge v1.39.3
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.7 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.5 // indirect
github.com/aws/aws-sdk-go-v2/service/organizations v1.27.3 // indirect
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.28.6
github.com/aws/aws-sdk-go-v2/service/servicequotas v1.21.4 // indirect
github.com/aws/aws-sdk-go-v2/service/sqs v1.38.8
github.com/aws/aws-sdk-go-v2/service/sso v1.20.5 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ github.com/aws/amazon-vpc-cni-k8s v1.15.5 h1:/mqTXB4HoGYg4CiU4Gco9iEvZ+V/309Na4H
github.com/aws/amazon-vpc-cni-k8s v1.15.5/go.mod h1:jV4wNtmgT2Ra1/oZU99DPOFsCUKnf0mYfIyzDyAUVAY=
github.com/aws/aws-lambda-go v1.41.0 h1:l/5fyVb6Ud9uYd411xdHZzSf2n86TakxzpvIoz7l+3Y=
github.com/aws/aws-lambda-go v1.41.0/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM=
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 v1.55.7 h1:UJrkFq7es5CShfBwlWAC8DA077vp8PyVbQd3lqLiztE=
github.com/aws/aws-sdk-go v1.55.7/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
github.com/aws/aws-sdk-go-v2 v1.36.5 h1:0OF9RiEMEdDdZEMqF9MRjevyxAQcf6gY+E7vwBILFj0=
github.com/aws/aws-sdk-go-v2 v1.36.5/go.mod h1:EYrzvCCN9CMUTa5+6lf6MM4tq3Zjp8UhSGR/cBsjai0=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 h1:x6xsQXGSmW6frevwDA+vi/wqhp1ct18mVXYN08/93to=
Expand Down Expand Up @@ -76,8 +76,8 @@ github.com/aws/aws-sdk-go-v2/service/eks v1.64.0 h1:EYeOThTRysemFtC6J6h6b7dNg3jN
github.com/aws/aws-sdk-go-v2/service/eks v1.64.0/go.mod h1:v1xXy6ea0PHtWkjFUvAUh6B/5wv7UF909Nru0dOIJDk=
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.29.6 h1:9grU/+HRwLXJV8XUjEPThJj/H+0oHkeNBFpSSfZekeg=
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.29.6/go.mod h1:N4fs285CsnBHlAkzBpQapefR/noggTyF09fWs72EzB4=
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.34.0 h1:8rDRtPOu3ax8jEctw7G926JQlnFdhZZA4KJzQ+4ks3Q=
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.34.0/go.mod h1:L5bVuO4PeXuDuMYZfL3IW69E6mz6PDCYpp6IKDlcLMA=
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.45.2 h1:vX70Z4lNSr7XsioU0uJq5yvxgI50sB66MvD+V/3buS4=
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.45.2/go.mod h1:xnCC3vFBfOKpU6PcsCKL2ktgBTZfOwTGxj6V8/X3IS4=
github.com/aws/aws-sdk-go-v2/service/eventbridge v1.39.3 h1:T6L7fsONflMeXuvsT8qZ247hA8ShBB0jF9yUEhW4JqI=
github.com/aws/aws-sdk-go-v2/service/eventbridge v1.39.3/go.mod h1:sIrUII6Z+hAVAgcpmsc2e9HvEr++m/v8aBPT7s4ZYUk=
github.com/aws/aws-sdk-go-v2/service/iam v1.32.0 h1:ZNlfPdw849gBo/lvLFbEEvpTJMij0LXqiNWZ+lIamlU=
Expand Down
202 changes: 202 additions & 0 deletions pkg/cloud/convertersv2/tags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
/*
Copyright 2025 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package convertersv2 provides conversion functions for AWS SDK V2 types to CAPA types.
package convertersv2

import (
"sort"

"github.com/aws/aws-sdk-go-v2/aws"
autoscalingtypes "github.com/aws/aws-sdk-go-v2/service/autoscaling/types"
v2ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
elbv1types "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/types"
elbv2types "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types"
iamtypes "github.com/aws/aws-sdk-go-v2/service/iam/types"
secretsmanagertypes "github.com/aws/aws-sdk-go-v2/service/secretsmanager/types"
ssmtypes "github.com/aws/aws-sdk-go-v2/service/ssm/types"

infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
)

// TagsToMap converts a []v2ec2types.Tag into a infrav1.Tags.
func TagsToMap(src []v2ec2types.Tag) infrav1.Tags {
tags := make(infrav1.Tags, len(src))

for _, t := range src {
tags[*t.Key] = *t.Value
}

return tags
}

// MapPtrToMap converts a [string]*string into a infrav1.Tags.
func MapPtrToMap(src map[string]*string) infrav1.Tags {
tags := make(infrav1.Tags, len(src))

for k, v := range src {
tags[k] = *v
}

return tags
}

// MapToTags converts a infrav1.Tags to a []v2ec2types.Tag.
func MapToTags(src infrav1.Tags) []v2ec2types.Tag {
tags := make([]v2ec2types.Tag, 0, len(src))

for k, v := range src {
tag := v2ec2types.Tag{
Key: aws.String(k),
Value: aws.String(v),
}

tags = append(tags, tag)
}

// Sort so that unit tests can expect a stable order
sort.Slice(tags, func(i, j int) bool { return *tags[i].Key < *tags[j].Key })

return tags
}

// ELBTagsToMap converts a []elbv1types.Tag into a infrav1.Tags.
func ELBTagsToMap(src []elbv1types.Tag) infrav1.Tags {
tags := make(infrav1.Tags, len(src))

for _, t := range src {
tags[*t.Key] = *t.Value
}

return tags
}

// V2TagsToMap converts a []elbv2types.Tag into a infrav1.Tags.
func V2TagsToMap(src []elbv2types.Tag) infrav1.Tags {
tags := make(infrav1.Tags, len(src))

for _, t := range src {
tags[*t.Key] = *t.Value
}

return tags
}

// MapToELBTags converts a infrav1.Tags to a []elbv1types.Tag.
func MapToELBTags(src infrav1.Tags) []elbv1types.Tag {
tags := make([]elbv1types.Tag, 0, len(src))

for k, v := range src {
tag := elbv1types.Tag{
Key: aws.String(k),
Value: aws.String(v),
}

tags = append(tags, tag)
}

// Sort so that unit tests can expect a stable order
sort.Slice(tags, func(i, j int) bool { return *tags[i].Key < *tags[j].Key })

return tags
}

// MapToV2Tags converts a infrav1.Tags to a []elbv2types.Tag.
func MapToV2Tags(src infrav1.Tags) []elbv2types.Tag {
tags := make([]elbv2types.Tag, 0, len(src))

for k, v := range src {
tag := elbv2types.Tag{
Key: aws.String(k),
Value: aws.String(v),
}

tags = append(tags, tag)
}

// Sort so that unit tests can expect a stable order
sort.Slice(tags, func(i, j int) bool { return *tags[i].Key < *tags[j].Key })

return tags
}

// MapToSecretsManagerTags converts a infrav1.Tags to a []secretsmanagertypes.Tag.
func MapToSecretsManagerTags(src infrav1.Tags) []secretsmanagertypes.Tag {
tags := make([]secretsmanagertypes.Tag, 0, len(src))

for k, v := range src {
tag := secretsmanagertypes.Tag{
Key: aws.String(k),
Value: aws.String(v),
}

tags = append(tags, tag)
}

// Sort so that unit tests can expect a stable order
sort.Slice(tags, func(i, j int) bool { return *tags[i].Key < *tags[j].Key })

return tags
}

// MapToSSMTags converts a infrav1.Tags to a []ssm.Tag.
func MapToSSMTags(src infrav1.Tags) []ssmtypes.Tag {
tags := make([]ssmtypes.Tag, 0, len(src))

for k, v := range src {
tag := ssmtypes.Tag{
Key: aws.String(k),
Value: aws.String(v),
}

tags = append(tags, tag)
}

// Sort so that unit tests can expect a stable order
sort.Slice(tags, func(i, j int) bool { return *tags[i].Key < *tags[j].Key })

return tags
}

// MapToIAMTags converts a infrav1.Tags to a []iamtypes.Tag.
func MapToIAMTags(src infrav1.Tags) []iamtypes.Tag {
tags := make([]iamtypes.Tag, 0, len(src))

for k, v := range src {
tag := iamtypes.Tag{
Key: aws.String(k),
Value: aws.String(v),
}

tags = append(tags, tag)
}

// Sort so that unit tests can expect a stable order
sort.Slice(tags, func(i, j int) bool { return *tags[i].Key < *tags[j].Key })

return tags
}

// ASGTagsToMap converts a []autoscalingtypes.TagDescription into a infrav1.Tags.
func ASGTagsToMap(src []autoscalingtypes.TagDescription) infrav1.Tags {
tags := make(infrav1.Tags, len(src))

for _, t := range src {
tags[*t.Key] = *t.Value
}

return tags
}
23 changes: 23 additions & 0 deletions pkg/cloud/endpointsv2/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"net/url"
"strings"

"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/eks"
elb "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing"
elbv2 "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2"
Expand Down Expand Up @@ -171,6 +172,28 @@ func (s *ELBV2EndpointResolver) ResolveEndpoint(ctx context.Context, params elbv
return elbv2.NewDefaultEndpointResolverV2().ResolveEndpoint(ctx, params)
}

// EC2EndpointResolver implements EndpointResolverV2 interface for EC2.
type EC2EndpointResolver struct {
*MultiServiceEndpointResolver
}

// ResolveEndpoint for ELBV2.
func (s *EC2EndpointResolver) ResolveEndpoint(ctx context.Context, params ec2.EndpointParameters) (smithyendpoints.Endpoint, error) {
// If custom endpoint not found, return default endpoint for the service
log := logger.FromContext(ctx)
endpoint, ok := s.endpoints[ec2.ServiceID]

if !ok {
log.Debug("Custom endpoint not found, using default endpoint")
return ec2.NewDefaultEndpointResolverV2().ResolveEndpoint(ctx, params)
}

log.Debug("Custom endpoint found, using custom endpoint", "endpoint", endpoint.URL)
params.Endpoint = &endpoint.URL
params.Region = &endpoint.SigningRegion
return ec2.NewDefaultEndpointResolverV2().ResolveEndpoint(ctx, params)
}

// RGAPIEndpointResolver implements EndpointResolverV2 interface for RGAPI.
type RGAPIEndpointResolver struct {
*MultiServiceEndpointResolver
Expand Down
Loading