Skip to content

feat: Recreate TransitGateway/NatGatway if resource has deleted status #257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apis/v1alpha1/ack-generate-metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
ack_generate_info:
build_date: "2025-04-02T00:53:09Z"
build_date: "2025-04-02T20:13:02Z"
build_hash: 980cb1e4734f673d16101cf55206b84ca639ec01
go_version: go1.24.1
version: v0.44.0
api_directory_checksum: 5e4731f8ab6fa4bafdb863edf0e678e604697103
api_version: v1alpha1
aws_sdk_go_version: v1.32.6
generator_config_info:
file_checksum: e698ea1f155660431146b92e305118d58ee80a76
file_checksum: 91537a111710acf9c1f9c7c6c451ca017568ecb7
original_file_name: generator.yaml
last_modification:
reason: API generation
4 changes: 4 additions & 0 deletions apis/v1alpha1/generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,8 @@ resources:
hooks:
sdk_create_post_build_request:
template_path: hooks/nat_gateway/sdk_create_post_build_request.go.tpl
sdk_read_many_post_set_output:
template_path: hooks/nat_gateway/sdk_read_many_post_set_output.go.tpl
sdk_file_end:
template_path: hooks/nat_gateway/sdk_file_end.go.tpl
update_operation:
Expand Down Expand Up @@ -877,6 +879,8 @@ resources:
hooks:
sdk_create_post_build_request:
template_path: hooks/transit_gateway/sdk_create_post_build_request.go.tpl
sdk_read_many_post_set_output:
template_path: hooks/transit_gateway/sdk_read_many_post_set_output.go.tpl
sdk_file_end:
template_path: hooks/transit_gateway/sdk_file_end.go.tpl
update_operation:
Expand Down
4 changes: 4 additions & 0 deletions generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,8 @@ resources:
hooks:
sdk_create_post_build_request:
template_path: hooks/nat_gateway/sdk_create_post_build_request.go.tpl
sdk_read_many_post_set_output:
template_path: hooks/nat_gateway/sdk_read_many_post_set_output.go.tpl
sdk_file_end:
template_path: hooks/nat_gateway/sdk_file_end.go.tpl
update_operation:
Expand Down Expand Up @@ -877,6 +879,8 @@ resources:
hooks:
sdk_create_post_build_request:
template_path: hooks/transit_gateway/sdk_create_post_build_request.go.tpl
sdk_read_many_post_set_output:
template_path: hooks/transit_gateway/sdk_read_many_post_set_output.go.tpl
sdk_file_end:
template_path: hooks/transit_gateway/sdk_file_end.go.tpl
update_operation:
Expand Down
17 changes: 17 additions & 0 deletions pkg/resource/nat_gateway/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ import (
"github.com/aws-controllers-k8s/ec2-controller/pkg/tags"
)

func isResourceDeleted(r *resource) bool {
if r.ko.Status.State == nil {
return true
}
status := *r.ko.Status.State
return status == string(svcsdktypes.NatGatewayStateDeleted)
}

func isResourcePending(r *resource) bool {
if r.ko.Status.State == nil {
return false
}
status := *r.ko.Status.State
return status == string(svcsdktypes.NatGatewayStatePending)
}

func (rm *resourceManager) customUpdateNATGateway(
ctx context.Context,
desired *resource,
Expand All @@ -40,6 +56,7 @@ func (rm *resourceManager) customUpdateNATGateway(
// an error, then the update was successful and desired.Spec
// (now updated.Spec) reflects the latest resource state.
updated = rm.concreteResource(desired.DeepCopy())
updated.ko.Status = latest.ko.Status
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't want the latest.Status to be discarded..the state was never being patched when i tested it locally.
https://github.com/aws-controllers-k8s/runtime/blob/07dcd404a9a7bc3efe890791b910f9ec41712926/pkg/runtime/reconciler.go#L781

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do need some preCompareDeltas to ensure we ignore everything except tags tho..since that's the only field we can update


if delta.DifferentAt("Spec.Tags") {
if err := tags.Sync(
Expand Down
7 changes: 7 additions & 0 deletions pkg/resource/nat_gateway/sdk.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions pkg/resource/transit_gateway/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ import (
"github.com/aws-controllers-k8s/ec2-controller/pkg/tags"
)

func isResourceDeleted(r *resource) bool {
if r.ko.Status.State == nil {
return true
}
status := *r.ko.Status.State
return status == string(svcsdktypes.TransitGatewayStateDeleted)
}

func isResourcePending(r *resource) bool {
if r.ko.Status.State == nil {
return false
}
status := *r.ko.Status.State
return status == string(svcsdktypes.TransitGatewayStatePending)
}

func (rm *resourceManager) customUpdateTransitGateway(
ctx context.Context,
desired *resource,
Expand Down
7 changes: 7 additions & 0 deletions pkg/resource/transit_gateway/sdk.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if isResourceDeleted(&resource{ko}) {
return nil, ackerr.NotFound
}
if isResourcePending(&resource{ko}) {
return nil, ackrequeue.Needed(fmt.Errorf("resource is pending"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if isResourceDeleted(&resource{ko}) {
return nil, ackerr.NotFound
}
if isResourcePending(&resource{ko}) {
return nil, ackrequeue.Needed(fmt.Errorf("resource is pending"))
}