Skip to content

Commit 12a5c0a

Browse files
Refactor: Migrate GC service to AWS SDK v2
Migrate the garbage collection service and related components to use the AWS SDK v2. This involves updating dependencies, refactoring client initialization, and updating API calls within the GC logic. Adds new v2 specific converters, filters, and mocks. Migrate the garbage collection logic for AWS Application Load Balancers (ALBs) and Network Load Balancers (NLBs) to use the AWS SDK v2. Migrate the garbage collection logic for Classic Load Balancers (ELB) from the AWS SDK v1 to v2. Signed-off-by: Danil-Grigorev <[email protected]>
1 parent 2f41cef commit 12a5c0a

File tree

18 files changed

+1218
-241
lines changed

18 files changed

+1218
-241
lines changed

go.mod

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,20 @@ require (
1010
github.com/apparentlymart/go-cidr v1.1.0
1111
github.com/aws/amazon-vpc-cni-k8s v1.15.5
1212
github.com/aws/aws-lambda-go v1.41.0
13-
github.com/aws/aws-sdk-go v1.55.5
13+
github.com/aws/aws-sdk-go v1.55.7
1414
github.com/aws/aws-sdk-go-v2 v1.36.3
1515
github.com/aws/aws-sdk-go-v2/config v1.27.11
1616
github.com/aws/aws-sdk-go-v2/credentials v1.17.11
1717
github.com/aws/aws-sdk-go-v2/service/autoscaling v1.52.4
18+
github.com/aws/aws-sdk-go-v2/service/ec2 v1.159.0
1819
github.com/aws/aws-sdk-go-v2/service/eks v1.64.0
20+
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.29.3
21+
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.45.2
1922
github.com/aws/aws-sdk-go-v2/service/iam v1.32.0
23+
github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.26.3
2024
github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1
25+
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.28.6
26+
github.com/aws/aws-sdk-go-v2/service/ssm v1.59.0
2127
github.com/aws/aws-sdk-go-v2/service/sts v1.28.6
2228
github.com/aws/smithy-go v1.22.2
2329
github.com/awslabs/goformation/v4 v4.19.5
@@ -85,13 +91,11 @@ require (
8591
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
8692
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.5 // indirect
8793
github.com/aws/aws-sdk-go-v2/service/cloudformation v1.50.0 // indirect
88-
github.com/aws/aws-sdk-go-v2/service/ec2 v1.159.0 // indirect
8994
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect
9095
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.7 // indirect
9196
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7 // indirect
9297
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.5 // indirect
9398
github.com/aws/aws-sdk-go-v2/service/organizations v1.27.3 // indirect
94-
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.28.6 // indirect
9599
github.com/aws/aws-sdk-go-v2/service/servicequotas v1.21.4 // indirect
96100
github.com/aws/aws-sdk-go-v2/service/sso v1.20.5 // indirect
97101
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4 // indirect

go.sum

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ github.com/aws/amazon-vpc-cni-k8s v1.15.5 h1:/mqTXB4HoGYg4CiU4Gco9iEvZ+V/309Na4H
4242
github.com/aws/amazon-vpc-cni-k8s v1.15.5/go.mod h1:jV4wNtmgT2Ra1/oZU99DPOFsCUKnf0mYfIyzDyAUVAY=
4343
github.com/aws/aws-lambda-go v1.41.0 h1:l/5fyVb6Ud9uYd411xdHZzSf2n86TakxzpvIoz7l+3Y=
4444
github.com/aws/aws-lambda-go v1.41.0/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM=
45-
github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU=
46-
github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
45+
github.com/aws/aws-sdk-go v1.55.7 h1:UJrkFq7es5CShfBwlWAC8DA077vp8PyVbQd3lqLiztE=
46+
github.com/aws/aws-sdk-go v1.55.7/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
4747
github.com/aws/aws-sdk-go-v2 v1.36.3 h1:mJoei2CxPutQVxaATCzDUjcZEjVRdpsiiXi2o38yqWM=
4848
github.com/aws/aws-sdk-go-v2 v1.36.3/go.mod h1:LLXuLpgzEbD766Z5ECcRmi8AzSwfZItDtmABVkRLGzg=
4949
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 h1:x6xsQXGSmW6frevwDA+vi/wqhp1ct18mVXYN08/93to=
@@ -70,6 +70,10 @@ github.com/aws/aws-sdk-go-v2/service/ec2 v1.159.0 h1:DmmVmiLPlcntOcjWMRwDPMNx/wi
7070
github.com/aws/aws-sdk-go-v2/service/ec2 v1.159.0/go.mod h1:xejKuuRDjz6z5OqyeLsz01MlOqqW7CqpAB4PabNvpu8=
7171
github.com/aws/aws-sdk-go-v2/service/eks v1.64.0 h1:EYeOThTRysemFtC6J6h6b7dNg3jN03QuO5cg92ojIQE=
7272
github.com/aws/aws-sdk-go-v2/service/eks v1.64.0/go.mod h1:v1xXy6ea0PHtWkjFUvAUh6B/5wv7UF909Nru0dOIJDk=
73+
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.29.3 h1:DpyV8LeDf0y7iDaGZ3h1Y+Nh5IaBOR+xj44vVgEEegY=
74+
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.29.3/go.mod h1:H232HdqVlSUoqy0cMJYW1TKjcxvGFGFZ20xQG8fOAPw=
75+
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.45.2 h1:vX70Z4lNSr7XsioU0uJq5yvxgI50sB66MvD+V/3buS4=
76+
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.45.2/go.mod h1:xnCC3vFBfOKpU6PcsCKL2ktgBTZfOwTGxj6V8/X3IS4=
7377
github.com/aws/aws-sdk-go-v2/service/iam v1.32.0 h1:ZNlfPdw849gBo/lvLFbEEvpTJMij0LXqiNWZ+lIamlU=
7478
github.com/aws/aws-sdk-go-v2/service/iam v1.32.0/go.mod h1:aXWImQV0uTW35LM0A/T4wEg6R1/ReXUu4SM6/lUHYK0=
7579
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 h1:Ji0DY1xUsUr3I8cHps0G+XM3WWU16lP6yG8qu1GAZAs=
@@ -82,12 +86,16 @@ github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.5 h1:f9RyWNtS8oH7cZ
8286
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.5/go.mod h1:h5CoMZV2VF297/VLhRhO1WF+XYWOzXo+4HsObA4HjBQ=
8387
github.com/aws/aws-sdk-go-v2/service/organizations v1.27.3 h1:CnPWlONzFX9/yO6IGuKg9sWUE8WhKztYRFbhmOHXjJI=
8488
github.com/aws/aws-sdk-go-v2/service/organizations v1.27.3/go.mod h1:hUHSXe9HFEmLfHrXndAX5e69rv0nBsg22VuNQYl0JLM=
89+
github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.26.3 h1:P87jejqS8WvQvRWyXlHUylt99VXt0y/WUIFuU6gBU7A=
90+
github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.26.3/go.mod h1:cgPfPTC/V3JqwCKed7Q6d0FrgarV7ltz4Bz6S4Q+Dqk=
8591
github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1 h1:6cnno47Me9bRykw9AEv9zkXE+5or7jz8TsskTTccbgc=
8692
github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1/go.mod h1:qmdkIIAC+GCLASF7R2whgNrJADz0QZPX+Seiw/i4S3o=
8793
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.28.6 h1:TIOEjw0i2yyhmhRry3Oeu9YtiiHWISZ6j/irS1W3gX4=
8894
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.28.6/go.mod h1:3Ba++UwWd154xtP4FRX5pUK3Gt4up5sDHCve6kVfE+g=
8995
github.com/aws/aws-sdk-go-v2/service/servicequotas v1.21.4 h1:SSDkZRAO8Ok5SoQ4BJ0onDeb0ga8JBOCkUmNEpRChcw=
9096
github.com/aws/aws-sdk-go-v2/service/servicequotas v1.21.4/go.mod h1:plXue/Zg49kU3uU6WwfCWgRR5SRINNiJf03Y/UhYOhU=
97+
github.com/aws/aws-sdk-go-v2/service/ssm v1.59.0 h1:KWArCwA/WkuHWKfygkNz0B6YS6OvdgoJUaJHX0Qby1s=
98+
github.com/aws/aws-sdk-go-v2/service/ssm v1.59.0/go.mod h1:PUWUl5MDiYNQkUHN9Pyd9kgtA/YhbxnSnHP+yQqzrM8=
9199
github.com/aws/aws-sdk-go-v2/service/sso v1.20.5 h1:vN8hEbpRnL7+Hopy9dzmRle1xmDc7o8tmY0klsr175w=
92100
github.com/aws/aws-sdk-go-v2/service/sso v1.20.5/go.mod h1:qGzynb/msuZIE8I75DVRCUXw3o3ZyBmUvMwQ2t/BrGM=
93101
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4 h1:Jux+gDDyi1Lruk+KHF91tK2KCuY61kzoCpvtvJJBtOE=

pkg/cloud/convertersv2/tags.go

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package convertersv2 provides conversion functions for AWS SDK V2 types to CAPA types.
18+
package convertersv2
19+
20+
import (
21+
"sort"
22+
23+
"github.com/aws/aws-sdk-go-v2/aws"
24+
autoscalingtypes "github.com/aws/aws-sdk-go-v2/service/autoscaling/types"
25+
v2ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
26+
elbv1types "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/types"
27+
elbv2types "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types"
28+
iamtypes "github.com/aws/aws-sdk-go-v2/service/iam/types"
29+
secretsmanagertypes "github.com/aws/aws-sdk-go-v2/service/secretsmanager/types"
30+
ssmtypes "github.com/aws/aws-sdk-go-v2/service/ssm/types"
31+
32+
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
33+
)
34+
35+
// TagsToMap converts a []v2ec2types.Tag into a infrav1.Tags.
36+
func TagsToMap(src []v2ec2types.Tag) infrav1.Tags {
37+
tags := make(infrav1.Tags, len(src))
38+
39+
for _, t := range src {
40+
tags[*t.Key] = *t.Value
41+
}
42+
43+
return tags
44+
}
45+
46+
// MapPtrToMap converts a [string]*string into a infrav1.Tags.
47+
func MapPtrToMap(src map[string]*string) infrav1.Tags {
48+
tags := make(infrav1.Tags, len(src))
49+
50+
for k, v := range src {
51+
tags[k] = *v
52+
}
53+
54+
return tags
55+
}
56+
57+
// MapToTags converts a infrav1.Tags to a []v2ec2types.Tag.
58+
func MapToTags(src infrav1.Tags) []v2ec2types.Tag {
59+
tags := make([]v2ec2types.Tag, 0, len(src))
60+
61+
for k, v := range src {
62+
tag := v2ec2types.Tag{
63+
Key: aws.String(k),
64+
Value: aws.String(v),
65+
}
66+
67+
tags = append(tags, tag)
68+
}
69+
70+
// Sort so that unit tests can expect a stable order
71+
sort.Slice(tags, func(i, j int) bool { return *tags[i].Key < *tags[j].Key })
72+
73+
return tags
74+
}
75+
76+
// ELBTagsToMap converts a []elbv1types.Tag into a infrav1.Tags.
77+
func ELBTagsToMap(src []elbv1types.Tag) infrav1.Tags {
78+
tags := make(infrav1.Tags, len(src))
79+
80+
for _, t := range src {
81+
tags[*t.Key] = *t.Value
82+
}
83+
84+
return tags
85+
}
86+
87+
// V2TagsToMap converts a []elbv2types.Tag into a infrav1.Tags.
88+
func V2TagsToMap(src []elbv2types.Tag) infrav1.Tags {
89+
tags := make(infrav1.Tags, len(src))
90+
91+
for _, t := range src {
92+
tags[*t.Key] = *t.Value
93+
}
94+
95+
return tags
96+
}
97+
98+
// MapToELBTags converts a infrav1.Tags to a []elbv1types.Tag.
99+
func MapToELBTags(src infrav1.Tags) []elbv1types.Tag {
100+
tags := make([]elbv1types.Tag, 0, len(src))
101+
102+
for k, v := range src {
103+
tag := elbv1types.Tag{
104+
Key: aws.String(k),
105+
Value: aws.String(v),
106+
}
107+
108+
tags = append(tags, tag)
109+
}
110+
111+
// Sort so that unit tests can expect a stable order
112+
sort.Slice(tags, func(i, j int) bool { return *tags[i].Key < *tags[j].Key })
113+
114+
return tags
115+
}
116+
117+
// MapToV2Tags converts a infrav1.Tags to a []elbv2types.Tag.
118+
func MapToV2Tags(src infrav1.Tags) []elbv2types.Tag {
119+
tags := make([]elbv2types.Tag, 0, len(src))
120+
121+
for k, v := range src {
122+
tag := elbv2types.Tag{
123+
Key: aws.String(k),
124+
Value: aws.String(v),
125+
}
126+
127+
tags = append(tags, tag)
128+
}
129+
130+
// Sort so that unit tests can expect a stable order
131+
sort.Slice(tags, func(i, j int) bool { return *tags[i].Key < *tags[j].Key })
132+
133+
return tags
134+
}
135+
136+
// MapToSecretsManagerTags converts a infrav1.Tags to a []secretsmanagertypes.Tag.
137+
func MapToSecretsManagerTags(src infrav1.Tags) []secretsmanagertypes.Tag {
138+
tags := make([]secretsmanagertypes.Tag, 0, len(src))
139+
140+
for k, v := range src {
141+
tag := secretsmanagertypes.Tag{
142+
Key: aws.String(k),
143+
Value: aws.String(v),
144+
}
145+
146+
tags = append(tags, tag)
147+
}
148+
149+
// Sort so that unit tests can expect a stable order
150+
sort.Slice(tags, func(i, j int) bool { return *tags[i].Key < *tags[j].Key })
151+
152+
return tags
153+
}
154+
155+
// MapToSSMTags converts a infrav1.Tags to a []ssm.Tag.
156+
func MapToSSMTags(src infrav1.Tags) []ssmtypes.Tag {
157+
tags := make([]ssmtypes.Tag, 0, len(src))
158+
159+
for k, v := range src {
160+
tag := ssmtypes.Tag{
161+
Key: aws.String(k),
162+
Value: aws.String(v),
163+
}
164+
165+
tags = append(tags, tag)
166+
}
167+
168+
// Sort so that unit tests can expect a stable order
169+
sort.Slice(tags, func(i, j int) bool { return *tags[i].Key < *tags[j].Key })
170+
171+
return tags
172+
}
173+
174+
// MapToIAMTags converts a infrav1.Tags to a []iamtypes.Tag.
175+
func MapToIAMTags(src infrav1.Tags) []iamtypes.Tag {
176+
tags := make([]iamtypes.Tag, 0, len(src))
177+
178+
for k, v := range src {
179+
tag := iamtypes.Tag{
180+
Key: aws.String(k),
181+
Value: aws.String(v),
182+
}
183+
184+
tags = append(tags, tag)
185+
}
186+
187+
// Sort so that unit tests can expect a stable order
188+
sort.Slice(tags, func(i, j int) bool { return *tags[i].Key < *tags[j].Key })
189+
190+
return tags
191+
}
192+
193+
// ASGTagsToMap converts a []autoscalingtypes.TagDescription into a infrav1.Tags.
194+
func ASGTagsToMap(src []autoscalingtypes.TagDescription) infrav1.Tags {
195+
tags := make(infrav1.Tags, len(src))
196+
197+
for _, t := range src {
198+
tags[*t.Key] = *t.Value
199+
}
200+
201+
return tags
202+
}

0 commit comments

Comments
 (0)