Skip to content

Commit a6f8761

Browse files
authored
Refactor and uniform tags comparison/update logic (#196)
Fixes aws-controllers-k8s/community#2063 During the early days of ACK, the ec2 controller didn't have a lot of CRDs and most of the work around tag handling was some sort of copy/pasta from resource to resource. Time passed and now ec2-controller has 15 resources each with a slightly different tags handling implementations - making it very hard for us to maintain and bug fix if something goes wrong. This patch does a few things to simplify the life of an ACK developer: - Moves a lot of the tags handling logic into a single, simple and maintainable package (`pkg/tags`). - Rely back on generated tags delta computation (back then this wasn't supported) - Add type safety around the algorithm that was used to compare two array slices. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 370b5e1 commit a6f8761

File tree

38 files changed

+309
-1921
lines changed

38 files changed

+309
-1921
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
ack_generate_info:
2-
build_date: "2024-06-03T07:09:57Z"
2+
build_date: "2024-06-04T06:39:17Z"
33
build_hash: 14cef51778d471698018b6c38b604181a6948248
44
go_version: go1.22.3
55
version: v0.34.0
66
api_directory_checksum: 7fd395ceb7d5d8e35906991c7348d3498f384741
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.44.93
99
generator_config_info:
10-
file_checksum: b38071cec6cdb8156420ad489b68841fd9b30726
10+
file_checksum: 50dfb186094519e9534c5774690536b3e2474428
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/generator.yaml

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,7 @@ resources:
241241
from:
242242
operation: CreateTags
243243
path: Tags
244-
compare:
245-
is_ignored: True
246244
hooks:
247-
delta_pre_compare:
248-
code: compareTags(delta, a, b)
249245
sdk_create_post_build_request:
250246
template_path: hooks/dhcp_options/sdk_create_post_build_request.go.tpl
251247
sdk_create_post_set_output:
@@ -277,11 +273,7 @@ resources:
277273
from:
278274
operation: CreateTags
279275
path: Tags
280-
compare:
281-
is_ignored: True
282276
hooks:
283-
delta_pre_compare:
284-
code: compareTags(delta, a, b)
285277
sdk_create_post_build_request:
286278
template_path: hooks/instance/sdk_create_post_build_request.go.tpl
287279
sdk_create_post_set_output:
@@ -311,14 +303,10 @@ resources:
311303
from:
312304
operation: CreateTags
313305
path: Tags
314-
compare:
315-
is_ignored: True
316306
list_operation:
317307
match_fields:
318308
- AllocationId
319309
hooks:
320-
delta_pre_compare:
321-
code: compareTags(delta, a, b)
322310
sdk_create_post_build_request:
323311
template_path: hooks/elastic_ip_address/sdk_create_post_build_request.go.tpl
324312
sdk_delete_post_build_request:
@@ -348,11 +336,7 @@ resources:
348336
from:
349337
operation: CreateTags
350338
path: Tags
351-
compare:
352-
is_ignored: True
353339
hooks:
354-
delta_pre_compare:
355-
code: compareTags(delta, a, b)
356340
sdk_create_post_build_request:
357341
template_path: hooks/flow_log/sdk_create_post_build_request.go.tpl
358342
sdk_create_post_set_output:
@@ -375,8 +359,6 @@ resources:
375359
from:
376360
operation: CreateTags
377361
path: Tags
378-
compare:
379-
is_ignored: True
380362
VPC:
381363
from:
382364
operation: AttachInternetGateway
@@ -395,8 +377,6 @@ resources:
395377
path: Status.internetGatewayID
396378
name: ID
397379
hooks:
398-
delta_pre_compare:
399-
code: compareTags(delta, a, b)
400380
sdk_create_post_build_request:
401381
template_path: hooks/internet_gateway/sdk_create_post_build_request.go.tpl
402382
sdk_create_post_set_output:
@@ -436,16 +416,12 @@ resources:
436416
from:
437417
operation: CreateTags
438418
path: Tags
439-
compare:
440-
is_ignored: True
441419
synced:
442420
when:
443421
- path: Status.State
444422
in:
445423
- available
446424
hooks:
447-
delta_pre_compare:
448-
code: compareTags(delta, a, b)
449425
sdk_create_post_build_request:
450426
template_path: hooks/nat_gateway/sdk_create_post_build_request.go.tpl
451427
sdk_file_end:
@@ -479,8 +455,6 @@ resources:
479455
from:
480456
operation: CreateTags
481457
path: Tags
482-
compare:
483-
is_ignored: True
484458
VpcId:
485459
references:
486460
resource: VPC
@@ -541,8 +515,6 @@ resources:
541515
from:
542516
operation: CreateTags
543517
path: Tags
544-
compare:
545-
is_ignored: True
546518
VpcId:
547519
is_required: true
548520
references:
@@ -573,8 +545,6 @@ resources:
573545
GroupIds: Ids
574546
GroupNames: Names
575547
hooks:
576-
delta_pre_compare:
577-
code: compareTags(delta, a, b)
578548
sdk_create_post_build_request:
579549
template_path: hooks/security_group/sdk_create_post_build_request.go.tpl
580550
sdk_file_end:
@@ -603,8 +573,6 @@ resources:
603573
from:
604574
operation: CreateTags
605575
path: Tags
606-
compare:
607-
is_ignored: True
608576
VpcId:
609577
is_required: true
610578
references:
@@ -632,8 +600,6 @@ resources:
632600
input_fields:
633601
NetworkAclId: Id
634602
hooks:
635-
delta_pre_compare:
636-
code: compareTags(delta, a, b)
637603
sdk_create_post_build_request:
638604
template_path: hooks/network_acl/sdk_create_post_build_request.go.tpl
639605
sdk_file_end:
@@ -682,8 +648,6 @@ resources:
682648
from:
683649
operation: CreateTags
684650
path: Tags
685-
compare:
686-
is_ignored: True
687651
VpcId:
688652
references:
689653
resource: VPC
@@ -693,8 +657,6 @@ resources:
693657
- InvalidParameterValue
694658
- InvalidCustomerOwnedIpv4PoolID.Malformed
695659
hooks:
696-
delta_pre_compare:
697-
code: compareTags(delta, a, b)
698660
sdk_create_post_build_request:
699661
template_path: hooks/subnet/sdk_create_post_build_request.go.tpl
700662
sdk_create_post_set_output:
@@ -711,8 +673,6 @@ resources:
711673
from:
712674
operation: CreateTags
713675
path: Tags
714-
compare:
715-
is_ignored: True
716676
State:
717677
print:
718678
path: Status.state
@@ -722,8 +682,6 @@ resources:
722682
path: Status.transitGatewayID
723683
name: ID
724684
hooks:
725-
delta_pre_compare:
726-
code: compareTags(delta, a, b)
727685
sdk_create_post_build_request:
728686
template_path: hooks/transit_gateway/sdk_create_post_build_request.go.tpl
729687
sdk_file_end:
@@ -760,15 +718,11 @@ resources:
760718
from:
761719
operation: CreateTags
762720
path: Tags
763-
compare:
764-
is_ignored: True
765721
VpcID:
766722
print:
767723
path: Status.vpcID
768724
name: ID
769725
hooks:
770-
delta_pre_compare:
771-
code: compareTags(delta, a, b)
772726
sdk_create_post_build_request:
773727
template_path: hooks/vpc/sdk_create_post_build_request.go.tpl
774728
sdk_create_post_set_output:
@@ -785,8 +739,6 @@ resources:
785739
from:
786740
operation: CreateTags
787741
path: Tags
788-
compare:
789-
is_ignored: True
790742
VpcId:
791743
references:
792744
resource: VPC
@@ -816,8 +768,6 @@ resources:
816768
- InvalidVpcId.Malformed
817769
- InvalidServiceName
818770
hooks:
819-
delta_pre_compare:
820-
code: compareTags(delta, a, b)
821771
sdk_create_post_build_request:
822772
template_path: hooks/vpc_endpoint/sdk_create_post_build_request.go.tpl
823773
sdk_create_post_set_output:
@@ -851,16 +801,12 @@ resources:
851801
from:
852802
operation: CreateTags
853803
path: Tags
854-
compare:
855-
is_ignored: true
856804
synced:
857805
when:
858806
- path: Status.ServiceState
859807
in:
860808
- available
861809
hooks:
862-
delta_pre_compare:
863-
code: compareTags(delta, a, b)
864810
sdk_delete_post_build_request:
865811
template_path: hooks/vpc_endpoint_service_configuration/sdk_delete_post_build_request.go.tpl
866812
sdk_file_end:
@@ -893,11 +839,7 @@ resources:
893839
from:
894840
operation: CreateTags
895841
path: Tags
896-
compare:
897-
is_ignored: True
898842
hooks:
899-
delta_pre_compare:
900-
code: compareTags(delta, a, b)
901843
sdk_create_post_build_request:
902844
template_path: hooks/vpc_peering_connection/sdk_create_post_build_request.go.tpl
903845
sdk_create_post_set_output:

0 commit comments

Comments
 (0)