Skip to content

Commit 9c01fad

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. Signed-off-by: Danil-Grigorev <[email protected]>
1 parent ec21422 commit 9c01fad

File tree

15 files changed

+864
-214
lines changed

15 files changed

+864
-214
lines changed

go.mod

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@ 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
19+
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.29.3
20+
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.45.2
1821
github.com/aws/aws-sdk-go-v2/service/iam v1.32.0
22+
github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.26.3
1923
github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1
24+
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.28.6
25+
github.com/aws/aws-sdk-go-v2/service/ssm v1.59.0
2026
github.com/aws/aws-sdk-go-v2/service/sts v1.28.6
2127
github.com/aws/smithy-go v1.22.2
2228
github.com/awslabs/goformation/v4 v4.19.5
@@ -84,13 +90,11 @@ require (
8490
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
8591
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.5 // indirect
8692
github.com/aws/aws-sdk-go-v2/service/cloudformation v1.50.0 // indirect
87-
github.com/aws/aws-sdk-go-v2/service/ec2 v1.159.0 // indirect
8893
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect
8994
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.7 // indirect
9095
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7 // indirect
9196
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.5 // indirect
9297
github.com/aws/aws-sdk-go-v2/service/organizations v1.27.3 // indirect
93-
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.28.6 // indirect
9498
github.com/aws/aws-sdk-go-v2/service/servicequotas v1.21.4 // indirect
9599
github.com/aws/aws-sdk-go-v2/service/sso v1.20.5 // indirect
96100
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=
@@ -68,6 +68,10 @@ github.com/aws/aws-sdk-go-v2/service/cloudformation v1.50.0 h1:Ap5tOJfeAH1hO2UQc
6868
github.com/aws/aws-sdk-go-v2/service/cloudformation v1.50.0/go.mod h1:/v2KYdCW4BaHKayenaWEXOOdxItIwEA3oU0XzuQY3F0=
6969
github.com/aws/aws-sdk-go-v2/service/ec2 v1.159.0 h1:DmmVmiLPlcntOcjWMRwDPMNx/wi2kAVrf2ZmSN5gkAg=
7070
github.com/aws/aws-sdk-go-v2/service/ec2 v1.159.0/go.mod h1:xejKuuRDjz6z5OqyeLsz01MlOqqW7CqpAB4PabNvpu8=
71+
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.29.3 h1:DpyV8LeDf0y7iDaGZ3h1Y+Nh5IaBOR+xj44vVgEEegY=
72+
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.29.3/go.mod h1:H232HdqVlSUoqy0cMJYW1TKjcxvGFGFZ20xQG8fOAPw=
73+
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.45.2 h1:vX70Z4lNSr7XsioU0uJq5yvxgI50sB66MvD+V/3buS4=
74+
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.45.2/go.mod h1:xnCC3vFBfOKpU6PcsCKL2ktgBTZfOwTGxj6V8/X3IS4=
7175
github.com/aws/aws-sdk-go-v2/service/iam v1.32.0 h1:ZNlfPdw849gBo/lvLFbEEvpTJMij0LXqiNWZ+lIamlU=
7276
github.com/aws/aws-sdk-go-v2/service/iam v1.32.0/go.mod h1:aXWImQV0uTW35LM0A/T4wEg6R1/ReXUu4SM6/lUHYK0=
7377
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 h1:Ji0DY1xUsUr3I8cHps0G+XM3WWU16lP6yG8qu1GAZAs=
@@ -80,12 +84,16 @@ github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.5 h1:f9RyWNtS8oH7cZ
8084
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.5/go.mod h1:h5CoMZV2VF297/VLhRhO1WF+XYWOzXo+4HsObA4HjBQ=
8185
github.com/aws/aws-sdk-go-v2/service/organizations v1.27.3 h1:CnPWlONzFX9/yO6IGuKg9sWUE8WhKztYRFbhmOHXjJI=
8286
github.com/aws/aws-sdk-go-v2/service/organizations v1.27.3/go.mod h1:hUHSXe9HFEmLfHrXndAX5e69rv0nBsg22VuNQYl0JLM=
87+
github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.26.3 h1:P87jejqS8WvQvRWyXlHUylt99VXt0y/WUIFuU6gBU7A=
88+
github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.26.3/go.mod h1:cgPfPTC/V3JqwCKed7Q6d0FrgarV7ltz4Bz6S4Q+Dqk=
8389
github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1 h1:6cnno47Me9bRykw9AEv9zkXE+5or7jz8TsskTTccbgc=
8490
github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1/go.mod h1:qmdkIIAC+GCLASF7R2whgNrJADz0QZPX+Seiw/i4S3o=
8591
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.28.6 h1:TIOEjw0i2yyhmhRry3Oeu9YtiiHWISZ6j/irS1W3gX4=
8692
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.28.6/go.mod h1:3Ba++UwWd154xtP4FRX5pUK3Gt4up5sDHCve6kVfE+g=
8793
github.com/aws/aws-sdk-go-v2/service/servicequotas v1.21.4 h1:SSDkZRAO8Ok5SoQ4BJ0onDeb0ga8JBOCkUmNEpRChcw=
8894
github.com/aws/aws-sdk-go-v2/service/servicequotas v1.21.4/go.mod h1:plXue/Zg49kU3uU6WwfCWgRR5SRINNiJf03Y/UhYOhU=
95+
github.com/aws/aws-sdk-go-v2/service/ssm v1.59.0 h1:KWArCwA/WkuHWKfygkNz0B6YS6OvdgoJUaJHX0Qby1s=
96+
github.com/aws/aws-sdk-go-v2/service/ssm v1.59.0/go.mod h1:PUWUl5MDiYNQkUHN9Pyd9kgtA/YhbxnSnHP+yQqzrM8=
8997
github.com/aws/aws-sdk-go-v2/service/sso v1.20.5 h1:vN8hEbpRnL7+Hopy9dzmRle1xmDc7o8tmY0klsr175w=
9098
github.com/aws/aws-sdk-go-v2/service/sso v1.20.5/go.mod h1:qGzynb/msuZIE8I75DVRCUXw3o3ZyBmUvMwQ2t/BrGM=
9199
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4 h1:Jux+gDDyi1Lruk+KHF91tK2KCuY61kzoCpvtvJJBtOE=

pkg/cloud/convertersv2/tags.go

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
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
18+
19+
import (
20+
"sort"
21+
22+
"github.com/aws/aws-sdk-go-v2/aws"
23+
autoscalingtypes "github.com/aws/aws-sdk-go-v2/service/autoscaling/types"
24+
v2ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
25+
elbv1types "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing/types"
26+
elbv2types "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types"
27+
iamtypes "github.com/aws/aws-sdk-go-v2/service/iam/types"
28+
secretsmanagertypes "github.com/aws/aws-sdk-go-v2/service/secretsmanager/types"
29+
ssmtypes "github.com/aws/aws-sdk-go-v2/service/ssm/types"
30+
31+
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
32+
)
33+
34+
// TagsToMap converts a []v2ec2types.Tag into a infrav1.Tags.
35+
func TagsToMap(src []v2ec2types.Tag) infrav1.Tags {
36+
tags := make(infrav1.Tags, len(src))
37+
38+
for _, t := range src {
39+
tags[*t.Key] = *t.Value
40+
}
41+
42+
return tags
43+
}
44+
45+
// MapPtrToMap converts a [string]*string into a infrav1.Tags.
46+
func MapPtrToMap(src map[string]*string) infrav1.Tags {
47+
tags := make(infrav1.Tags, len(src))
48+
49+
for k, v := range src {
50+
tags[k] = *v
51+
}
52+
53+
return tags
54+
}
55+
56+
// MapToTags converts a infrav1.Tags to a []v2ec2types.Tag.
57+
func MapToTags(src infrav1.Tags) []v2ec2types.Tag {
58+
tags := make([]v2ec2types.Tag, 0, len(src))
59+
60+
for k, v := range src {
61+
tag := v2ec2types.Tag{
62+
Key: aws.String(k),
63+
Value: aws.String(v),
64+
}
65+
66+
tags = append(tags, tag)
67+
}
68+
69+
// Sort so that unit tests can expect a stable order
70+
sort.Slice(tags, func(i, j int) bool { return *tags[i].Key < *tags[j].Key })
71+
72+
return tags
73+
}
74+
75+
// ELBTagsToMap converts a []elbv1types.Tag into a infrav1.Tags.
76+
func ELBTagsToMap(src []elbv1types.Tag) infrav1.Tags {
77+
tags := make(infrav1.Tags, len(src))
78+
79+
for _, t := range src {
80+
tags[*t.Key] = *t.Value
81+
}
82+
83+
return tags
84+
}
85+
86+
// V2TagsToMap converts a []elbv2types.Tag into a infrav1.Tags.
87+
func V2TagsToMap(src []elbv2types.Tag) infrav1.Tags {
88+
tags := make(infrav1.Tags, len(src))
89+
90+
for _, t := range src {
91+
tags[*t.Key] = *t.Value
92+
}
93+
94+
return tags
95+
}
96+
97+
// MapToELBTags converts a infrav1.Tags to a []elbv1types.Tag.
98+
func MapToELBTags(src infrav1.Tags) []elbv1types.Tag {
99+
tags := make([]elbv1types.Tag, 0, len(src))
100+
101+
for k, v := range src {
102+
tag := elbv1types.Tag{
103+
Key: aws.String(k),
104+
Value: aws.String(v),
105+
}
106+
107+
tags = append(tags, tag)
108+
}
109+
110+
// Sort so that unit tests can expect a stable order
111+
sort.Slice(tags, func(i, j int) bool { return *tags[i].Key < *tags[j].Key })
112+
113+
return tags
114+
}
115+
116+
// MapToV2Tags converts a infrav1.Tags to a []elbv2types.Tag.
117+
func MapToV2Tags(src infrav1.Tags) []elbv2types.Tag {
118+
tags := make([]elbv2types.Tag, 0, len(src))
119+
120+
for k, v := range src {
121+
tag := elbv2types.Tag{
122+
Key: aws.String(k),
123+
Value: aws.String(v),
124+
}
125+
126+
tags = append(tags, tag)
127+
}
128+
129+
// Sort so that unit tests can expect a stable order
130+
sort.Slice(tags, func(i, j int) bool { return *tags[i].Key < *tags[j].Key })
131+
132+
return tags
133+
}
134+
135+
// MapToSecretsManagerTags converts a infrav1.Tags to a []secretsmanagertypes.Tag.
136+
func MapToSecretsManagerTags(src infrav1.Tags) []secretsmanagertypes.Tag {
137+
tags := make([]secretsmanagertypes.Tag, 0, len(src))
138+
139+
for k, v := range src {
140+
tag := secretsmanagertypes.Tag{
141+
Key: aws.String(k),
142+
Value: aws.String(v),
143+
}
144+
145+
tags = append(tags, tag)
146+
}
147+
148+
// Sort so that unit tests can expect a stable order
149+
sort.Slice(tags, func(i, j int) bool { return *tags[i].Key < *tags[j].Key })
150+
151+
return tags
152+
}
153+
154+
// MapToSSMTags converts a infrav1.Tags to a []ssm.Tag.
155+
func MapToSSMTags(src infrav1.Tags) []ssmtypes.Tag {
156+
tags := make([]ssmtypes.Tag, 0, len(src))
157+
158+
for k, v := range src {
159+
tag := ssmtypes.Tag{
160+
Key: aws.String(k),
161+
Value: aws.String(v),
162+
}
163+
164+
tags = append(tags, tag)
165+
}
166+
167+
// Sort so that unit tests can expect a stable order
168+
sort.Slice(tags, func(i, j int) bool { return *tags[i].Key < *tags[j].Key })
169+
170+
return tags
171+
}
172+
173+
// MapToIAMTags converts a infrav1.Tags to a []iamtypes.Tag.
174+
func MapToIAMTags(src infrav1.Tags) []iamtypes.Tag {
175+
tags := make([]iamtypes.Tag, 0, len(src))
176+
177+
for k, v := range src {
178+
tag := iamtypes.Tag{
179+
Key: aws.String(k),
180+
Value: aws.String(v),
181+
}
182+
183+
tags = append(tags, tag)
184+
}
185+
186+
// Sort so that unit tests can expect a stable order
187+
sort.Slice(tags, func(i, j int) bool { return *tags[i].Key < *tags[j].Key })
188+
189+
return tags
190+
}
191+
192+
// ASGTagsToMap converts a []autoscalingtypes.TagDescription into a infrav1.Tags.
193+
func ASGTagsToMap(src []autoscalingtypes.TagDescription) infrav1.Tags {
194+
tags := make(infrav1.Tags, len(src))
195+
196+
for _, t := range src {
197+
tags[*t.Key] = *t.Value
198+
}
199+
200+
return tags
201+
}

0 commit comments

Comments
 (0)