Skip to content

Commit 830d469

Browse files
committed
feat: Recreate TransitGateway if resource has deleted status
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
1 parent 298fc7d commit 830d469

File tree

6 files changed

+35
-2
lines changed

6 files changed

+35
-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-03-31T23:40:39Z"
2+
build_date: "2025-04-02T00:19:15Z"
33
build_hash: 3722729cebe6d3c03c7e442655ef0846f91566a2
44
go_version: go1.24.1
55
version: v0.43.2-7-g3722729
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: 90439f8d2bf55985bf86317d3cb6632f954bf92e
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/generator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,8 @@ resources:
877877
hooks:
878878
sdk_create_post_build_request:
879879
template_path: hooks/transit_gateway/sdk_create_post_build_request.go.tpl
880+
sdk_read_many_post_set_output:
881+
template_path: hooks/transit_gateway/sdk_read_many_post_set_output.go.tpl
880882
sdk_file_end:
881883
template_path: hooks/transit_gateway/sdk_file_end.go.tpl
882884
update_operation:

generator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,8 @@ resources:
877877
hooks:
878878
sdk_create_post_build_request:
879879
template_path: hooks/transit_gateway/sdk_create_post_build_request.go.tpl
880+
sdk_read_many_post_set_output:
881+
template_path: hooks/transit_gateway/sdk_read_many_post_set_output.go.tpl
880882
sdk_file_end:
881883
template_path: hooks/transit_gateway/sdk_file_end.go.tpl
882884
update_operation:

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+
}

0 commit comments

Comments
 (0)