Skip to content

feat(runtime): Add pre-delete sync step to deleteResource#234

Open
sapphirew wants to merge 4 commits intoaws-controllers-k8s:mainfrom
sapphirew:pre-del-sync
Open

feat(runtime): Add pre-delete sync step to deleteResource#234
sapphirew wants to merge 4 commits intoaws-controllers-k8s:mainfrom
sapphirew:pre-del-sync

Conversation

@sapphirew
Copy link
Copy Markdown

Add AWSResourceDescriptorWithPreDeleteDelta optional interface and preDeleteSync helper method to reconcile spec differences (including compare.is_ignored fields) before calling rm.Delete. This ensures fields like DeletionProtectionEnabled are synced to AWS before deletion.

The pre-delete sync:

  • Uses DeltaForPreDelete if the descriptor implements the optional interface, otherwise falls back to standard Delta
  • Calls rm.Update when spec differences are detected
  • Proceeds with deletion even if the update fails
  • Is a no-op when no spec differences exist

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Add AWSResourceDescriptorWithPreDeleteDelta optional interface and
preDeleteSync helper method to reconcile spec differences (including
compare.is_ignored fields) before calling rm.Delete. This ensures
fields like DeletionProtectionEnabled are synced to AWS before
deletion.

The pre-delete sync:
- Uses DeltaForPreDelete if the descriptor implements the optional
  interface, otherwise falls back to standard Delta
- Calls rm.Update when spec differences are detected
- Proceeds with deletion even if the update fails
- Is a no-op when no spec differences exist
@ack-prow ack-prow bot requested review from knottnt and michaelhtm April 8, 2026 18:02
@ack-prow
Copy link
Copy Markdown

ack-prow bot commented Apr 8, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: sapphirew
Once this PR has been reviewed and has the lgtm label, please assign michaelhtm for approval by writing /assign @michaelhtm in a comment. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

rhaowang added 3 commits April 8, 2026 14:17
…emented

When the resource descriptor does not implement the optional
AWSResourceDescriptorWithPreDeleteDelta interface, preDeleteSync now
returns immediately instead of falling back to the standard Delta.

The standard Delta can detect spec differences that are expected during
normal operation (e.g. tags added by EnsureTags during Sync). Calling
rm.Update with those differences during deletion could cause unintended
side effects like stripping tags from the AWS resource. Since the
standard Delta already excludes compare.is_ignored fields, there is
nothing extra to reconcile before deletion without the pre-delete
variant.
Add five unit tests to reconciler_test.go covering pre-delete sync
behavior during resource deletion:

- ReadOne returns NotFound: finalizer removed, no Update or Delete
- ReadOne returns non-NotFound error: error propagated, no Update or Delete
- Descriptor implements DeltaForPreDelete: pre-delete delta method used
- Descriptor does not implement DeltaForPreDelete: no-op, deletion proceeds
- DeletionProtection scenario: Update disables protection, then Delete called

Includes preDeleteDescriptorMock type and helper functions for test setup.
@sapphirew
Copy link
Copy Markdown
Author

/test ec2-controller-test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants