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 3 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 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ promote-images: $(KPROMO) $(YQ)

.PHONY: release-binaries
release-binaries: $(GORELEASER) ## Builds only the binaries, not a release.
$(GORELEASER) build --config $(GORELEASER_CONFIG) --snapshot --clean
GOMAXPROCS=2 $(GORELEASER) build --config $(GORELEASER_CONFIG) --snapshot --clean
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change is unrelated – can we take this out?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think so, this change fixes stuck goreleaser build in CI: #5518 (comment) I was able to reproduce it locally, and this change fixes it. Some other AWS SDK v2 rewrite PRs are affected by this too.


.PHONY: release-staging
release-staging: ## Builds and push container images and manifests to the staging bucket.
Expand Down
10 changes: 7 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ 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.3
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.3
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.0
github.com/aws/aws-sdk-go-v2/service/sts v1.28.6
github.com/aws/smithy-go v1.22.4
github.com/awslabs/goformation/v4 v4.19.5
Expand Down Expand Up @@ -85,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 // indirect
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 // indirect
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
12 changes: 10 additions & 2 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 All @@ -74,6 +74,10 @@ github.com/aws/aws-sdk-go-v2/service/ec2 v1.159.0 h1:DmmVmiLPlcntOcjWMRwDPMNx/wi
github.com/aws/aws-sdk-go-v2/service/ec2 v1.159.0/go.mod h1:xejKuuRDjz6z5OqyeLsz01MlOqqW7CqpAB4PabNvpu8=
github.com/aws/aws-sdk-go-v2/service/eks v1.64.0 h1:EYeOThTRysemFtC6J6h6b7dNg3jN03QuO5cg92ojIQE=
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.3 h1:DpyV8LeDf0y7iDaGZ3h1Y+Nh5IaBOR+xj44vVgEEegY=
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.29.3/go.mod h1:H232HdqVlSUoqy0cMJYW1TKjcxvGFGFZ20xQG8fOAPw=
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 All @@ -88,6 +92,8 @@ github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.5 h1:f9RyWNtS8oH7cZ
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.5/go.mod h1:h5CoMZV2VF297/VLhRhO1WF+XYWOzXo+4HsObA4HjBQ=
github.com/aws/aws-sdk-go-v2/service/organizations v1.27.3 h1:CnPWlONzFX9/yO6IGuKg9sWUE8WhKztYRFbhmOHXjJI=
github.com/aws/aws-sdk-go-v2/service/organizations v1.27.3/go.mod h1:hUHSXe9HFEmLfHrXndAX5e69rv0nBsg22VuNQYl0JLM=
github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.26.3 h1:P87jejqS8WvQvRWyXlHUylt99VXt0y/WUIFuU6gBU7A=
github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.26.3/go.mod h1:cgPfPTC/V3JqwCKed7Q6d0FrgarV7ltz4Bz6S4Q+Dqk=
github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1 h1:6cnno47Me9bRykw9AEv9zkXE+5or7jz8TsskTTccbgc=
github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1/go.mod h1:qmdkIIAC+GCLASF7R2whgNrJADz0QZPX+Seiw/i4S3o=
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.28.6 h1:TIOEjw0i2yyhmhRry3Oeu9YtiiHWISZ6j/irS1W3gX4=
Expand All @@ -96,6 +102,8 @@ github.com/aws/aws-sdk-go-v2/service/servicequotas v1.21.4 h1:SSDkZRAO8Ok5SoQ4BJ
github.com/aws/aws-sdk-go-v2/service/servicequotas v1.21.4/go.mod h1:plXue/Zg49kU3uU6WwfCWgRR5SRINNiJf03Y/UhYOhU=
github.com/aws/aws-sdk-go-v2/service/sqs v1.38.8 h1:80dpSqWMwx2dAm30Ib7J6ucz1ZHfiv5OCRwN/EnCOXQ=
github.com/aws/aws-sdk-go-v2/service/sqs v1.38.8/go.mod h1:IzNt/udsXlETCdvBOL0nmyMe2t9cGmXmZgsdoZGYYhI=
github.com/aws/aws-sdk-go-v2/service/ssm v1.59.0 h1:KWArCwA/WkuHWKfygkNz0B6YS6OvdgoJUaJHX0Qby1s=
github.com/aws/aws-sdk-go-v2/service/ssm v1.59.0/go.mod h1:PUWUl5MDiYNQkUHN9Pyd9kgtA/YhbxnSnHP+yQqzrM8=
github.com/aws/aws-sdk-go-v2/service/sso v1.20.5 h1:vN8hEbpRnL7+Hopy9dzmRle1xmDc7o8tmY0klsr175w=
github.com/aws/aws-sdk-go-v2/service/sso v1.20.5/go.mod h1:qGzynb/msuZIE8I75DVRCUXw3o3ZyBmUvMwQ2t/BrGM=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4 h1:Jux+gDDyi1Lruk+KHF91tK2KCuY61kzoCpvtvJJBtOE=
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
}
Loading