Skip to content

Commit 0e3b7d8

Browse files
authored
feat: Recreate TransitGateway if resource has deleted status (#257)
Issue #, if available: Description of changes: Currently if a TransitGateway is deleted on accident by calling the API or console, it still dangles with a `deleted` state. With this change, the controller will recreate the TransitGateway if the resource has `deleted` state By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 831140e commit 0e3b7d8

File tree

9 files changed

+69
-2
lines changed

9 files changed

+69
-2
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: "2025-04-02T00:53:09Z"
2+
build_date: "2025-04-02T20:13:02Z"
33
build_hash: 980cb1e4734f673d16101cf55206b84ca639ec01
44
go_version: go1.24.1
55
version: v0.44.0
66
api_directory_checksum: 5e4731f8ab6fa4bafdb863edf0e678e604697103
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.32.6
99
generator_config_info:
10-
file_checksum: e698ea1f155660431146b92e305118d58ee80a76
10+
file_checksum: 91537a111710acf9c1f9c7c6c451ca017568ecb7
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/generator.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,8 @@ resources:
598598
hooks:
599599
sdk_create_post_build_request:
600600
template_path: hooks/nat_gateway/sdk_create_post_build_request.go.tpl
601+
sdk_read_many_post_set_output:
602+
template_path: hooks/nat_gateway/sdk_read_many_post_set_output.go.tpl
601603
sdk_file_end:
602604
template_path: hooks/nat_gateway/sdk_file_end.go.tpl
603605
update_operation:
@@ -877,6 +879,8 @@ resources:
877879
hooks:
878880
sdk_create_post_build_request:
879881
template_path: hooks/transit_gateway/sdk_create_post_build_request.go.tpl
882+
sdk_read_many_post_set_output:
883+
template_path: hooks/transit_gateway/sdk_read_many_post_set_output.go.tpl
880884
sdk_file_end:
881885
template_path: hooks/transit_gateway/sdk_file_end.go.tpl
882886
update_operation:

generator.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,8 @@ resources:
598598
hooks:
599599
sdk_create_post_build_request:
600600
template_path: hooks/nat_gateway/sdk_create_post_build_request.go.tpl
601+
sdk_read_many_post_set_output:
602+
template_path: hooks/nat_gateway/sdk_read_many_post_set_output.go.tpl
601603
sdk_file_end:
602604
template_path: hooks/nat_gateway/sdk_file_end.go.tpl
603605
update_operation:
@@ -877,6 +879,8 @@ resources:
877879
hooks:
878880
sdk_create_post_build_request:
879881
template_path: hooks/transit_gateway/sdk_create_post_build_request.go.tpl
882+
sdk_read_many_post_set_output:
883+
template_path: hooks/transit_gateway/sdk_read_many_post_set_output.go.tpl
880884
sdk_file_end:
881885
template_path: hooks/transit_gateway/sdk_file_end.go.tpl
882886
update_operation:

pkg/resource/nat_gateway/hooks.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ import (
2424
"github.com/aws-controllers-k8s/ec2-controller/pkg/tags"
2525
)
2626

27+
func isResourceDeleted(r *resource) bool {
28+
if r.ko.Status.State == nil {
29+
return true
30+
}
31+
status := *r.ko.Status.State
32+
return status == string(svcsdktypes.NatGatewayStateDeleted)
33+
}
34+
35+
func isResourcePending(r *resource) bool {
36+
if r.ko.Status.State == nil {
37+
return false
38+
}
39+
status := *r.ko.Status.State
40+
return status == string(svcsdktypes.NatGatewayStatePending)
41+
}
42+
2743
func (rm *resourceManager) customUpdateNATGateway(
2844
ctx context.Context,
2945
desired *resource,
@@ -40,6 +56,7 @@ func (rm *resourceManager) customUpdateNATGateway(
4056
// an error, then the update was successful and desired.Spec
4157
// (now updated.Spec) reflects the latest resource state.
4258
updated = rm.concreteResource(desired.DeepCopy())
59+
updated.ko.Status = latest.ko.Status
4360

4461
if delta.DifferentAt("Spec.Tags") {
4562
if err := tags.Sync(

pkg/resource/nat_gateway/sdk.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/resource/transit_gateway/hooks.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ import (
2424
"github.com/aws-controllers-k8s/ec2-controller/pkg/tags"
2525
)
2626

27+
func isResourceDeleted(r *resource) bool {
28+
if r.ko.Status.State == nil {
29+
return true
30+
}
31+
status := *r.ko.Status.State
32+
return status == string(svcsdktypes.TransitGatewayStateDeleted)
33+
}
34+
35+
func isResourcePending(r *resource) bool {
36+
if r.ko.Status.State == nil {
37+
return false
38+
}
39+
status := *r.ko.Status.State
40+
return status == string(svcsdktypes.TransitGatewayStatePending)
41+
}
42+
2743
func (rm *resourceManager) customUpdateTransitGateway(
2844
ctx context.Context,
2945
desired *resource,

pkg/resource/transit_gateway/sdk.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
if isResourceDeleted(&resource{ko}) {
2+
return nil, ackerr.NotFound
3+
}
4+
if isResourcePending(&resource{ko}) {
5+
return nil, ackrequeue.Needed(fmt.Errorf("resource is pending"))
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
if isResourceDeleted(&resource{ko}) {
2+
return nil, ackerr.NotFound
3+
}
4+
if isResourcePending(&resource{ko}) {
5+
return nil, ackrequeue.Needed(fmt.Errorf("resource is pending"))
6+
}

0 commit comments

Comments
 (0)