Skip to content

feat: add CompareResourceForPreDelete and DeltaForPreDelete support#686

Open
sapphirew wants to merge 1 commit intoaws-controllers-k8s:mainfrom
sapphirew:pre-delete-sync
Open

feat: add CompareResourceForPreDelete and DeltaForPreDelete support#686
sapphirew wants to merge 1 commit intoaws-controllers-k8s:mainfrom
sapphirew:pre-delete-sync

Conversation

@sapphirew
Copy link
Copy Markdown

@sapphirew sapphirew commented Apr 8, 2026

Add pre-delete delta comparison support to the code generator. Controllers can opt specific fields into pre-delete comparison via compare.pre_delete_include: true in generator.yaml, so that fields like DeletionProtectionEnabled are synced before deletion even when they use compare.is_ignored for normal reconciliation.

Config changes:

  • Add PreDeleteInclude bool to CompareFieldConfig (field.go)
  • Add PreDeleteSyncConfig with CompareAll to ResourceConfig (resource.go)

Code generation:

  • Add CompareResourceForPreDelete function that emits comparison code
    only for opted-in fields (or all fields when compare_all is true)
  • Register GoCodeCompareForPreDelete template function (controller.go)
  • Add newResourceDeltaForPreDelete in delta.go.tpl
  • Add DeltaForPreDelete method on resourceDescriptor in descriptor.go.tpl

Tests:

  • Four tests covering no-opt-in (empty), explicit opt-in, compare_all,
    and empty-without-opt-in scenarios
  • Two new S3 test fixture generator YAMLs

runtime changes: aws-controllers-k8s/runtime#234

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.

@ack-prow ack-prow bot requested review from a-hilaly and jlbutler April 8, 2026 18:15
@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

Copy link
Copy Markdown
Member

@michaelhtm michaelhtm left a comment

Choose a reason for hiding this comment

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

Thanks @sapphirew
left one comment below

Comment on lines +992 to +997
// CompareResourceForPreDelete returns the Go code that traverses a set of two
// Resources, adding differences between the two Resources to an
// `ackcompare.Delta`. Unlike CompareResource, this function does NOT skip
// fields where compareConfig.IsIgnored is true. This is used for pre-delete
// sync to ensure fields like DeletionProtectionEnabled are included in the
// delta comparison.
Copy link
Copy Markdown
Member

@michaelhtm michaelhtm Apr 8, 2026

Choose a reason for hiding this comment

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

should we make this delta comparison opt-in? Only compute delta on specific fields defined in generator.yaml?
In dsql example, we could just compare DeletionProtection field only

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

good call, that would provide fine-control on specific fields for a controller.

The current delta comparison can be enabled by a flag like this instead:

resources:
  Cluster:
    pre_delete_sync:
      compare_all: true

…Delete support

Add pre-delete delta comparison support to the code generator. Controllers
can opt specific fields into pre-delete comparison via
compare.pre_delete_include: true in generator.yaml, so that fields like
DeletionProtectionEnabled are synced before deletion even when they use
compare.is_ignored for normal reconciliation.

Config changes:
- Add PreDeleteInclude bool to CompareFieldConfig (field.go)
- Add PreDeleteSyncConfig with CompareAll to ResourceConfig (resource.go)

Code generation:
- Add CompareResourceForPreDelete function that emits comparison code
  only for opted-in fields (or all fields when compare_all is true)
- Register GoCodeCompareForPreDelete template function (controller.go)
- Add newResourceDeltaForPreDelete in delta.go.tpl
- Add DeltaForPreDelete method on resourceDescriptor in descriptor.go.tpl

Tests:
- Four tests covering no-opt-in (empty), explicit opt-in, compare_all,
  and empty-without-opt-in scenarios
- Two new S3 test fixture generator YAMLs
@sapphirew
Copy link
Copy Markdown
Author

/test s3-controller-test

@sapphirew
Copy link
Copy Markdown
Author

/test lambda-controller-test

@sapphirew
Copy link
Copy Markdown
Author

/retest

2 similar comments
@sapphirew
Copy link
Copy Markdown
Author

/retest

@sapphirew
Copy link
Copy Markdown
Author

/retest

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.

3 participants