Skip to content
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

Conditional clearing of finalizers #525

Merged
merged 1 commit into from
May 22, 2024

Conversation

scothis
Copy link
Contributor

@scothis scothis commented May 15, 2024

WithFinalizer's ReadyToClearFinalizer can be used to define custom rules for clearing the finalizer. For example, deletion of a resource can be blocked until all child resources are fully deleted replicating the behavior of an owner reference in parent-child relationships that are not supported by owner references. Client lookups and advanced logic should be avoided as errors cannot be returned. Computed values can be retrieved that were stashed from a previous reconciler, like a SyncReconciler#Finalize hook.

WithFinalizer's ReadyToClearFinalizer can be used to define custom rules
for clearing the finalizer. For example, deletion of a resource can be
blocked until all child resources are fully deleted replicating the
behavior of an owner reference in parent-child relationships that are
not supported by owner references. Client lookups and advanced logic
should be avoided as errors cannot be returned. Computed values can be
retrieved that were stashed from a previous reconciler, like a
SyncReconciler#Finalize hook.

Signed-off-by: Scott Andrews <scott@andrews.me>
Copy link

codecov bot commented May 15, 2024

Codecov Report

Attention: Patch coverage is 90.00000% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 59.73%. Comparing base (01b12e7) to head (7d81d03).

Files Patch % Lines
reconcilers/finalizer.go 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #525      +/-   ##
==========================================
+ Coverage   59.59%   59.73%   +0.13%     
==========================================
  Files          31       31              
  Lines        2772     2779       +7     
==========================================
+ Hits         1652     1660       +8     
+ Misses       1028     1027       -1     
  Partials       92       92              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@mamachanko mamachanko left a comment

Choose a reason for hiding this comment

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

lgtm

@squeedee
Copy link
Collaborator

If the inner reconciler deleted some child resources and they're still in "finalize" state, is there a way I can use this hook to observe that without client lookups?

@scothis
Copy link
Contributor Author

scothis commented May 15, 2024

If the inner reconciler deleted some child resources and they're still in "finalize" state, is there a way I can use this hook to observe that without client lookups?

Nope, that info isn't available from calling client.Delete(). You'll need to do the lookup of the resources you care about.

edit: I've considered introducing a side effect to ChildSetReconciler that leaks the current known children into the stash so that a later reconciler could observe them without needing to re-lookup/filter the set. That wouldn't reflect updates/deletes until the next reconcile, but that's probably good enough for your purpose.

@squeedee
Copy link
Collaborator

squeedee commented May 16, 2024

That wouldn't reflect updates/deletes until the next reconcile, but that's probably good enough for your purpose.

I would have cleared the finalizer by then because "nothing went wrong".

@scothis
Copy link
Contributor Author

scothis commented May 16, 2024

That wouldn't reflect updates/deletes until the next reconcile, but that's probably good enough for your purpose.

I would have cleared the finalizer by then because "nothing went wrong".

As is today, yes. With this new hook you can hold on to the finalizer until you're ready to release. Deciding when that is becomes your business logic.

@scothis scothis merged commit c91817b into reconcilerio:main May 22, 2024
4 checks passed
@scothis scothis deleted the clear-finalizer-conditional branch May 22, 2024 14:00
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.

None yet

3 participants