fix(reconciler): prevent unnecessary updates when auto-attaching finalizers#1057
Merged
kimpenhaus merged 15 commits intodotnet:mainfrom Feb 25, 2026
Merged
Conversation
# Conflicts: # test/KubeOps.Operator.Test/Controller/EntityController.Integration.Test.cs
…sary entity updates
buehler
previously approved these changes
Feb 25, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes the reconciler’s auto-finalizer attachment/detachment flow to reduce unnecessary Kubernetes updates (and related 409 conflicts), and extends tests to cover the intended behavior when status updates occur during reconciliation.
Changes:
- Update auto-attach logic to only
UpdateAsyncwhen at least one finalizer was actually added. - Update auto-detach logic to only
UpdateAsyncwhen a finalizer was actually removed. - Add/extend unit + integration tests to validate “no finalizers => no update” and to exercise status updates alongside auto-attach.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/KubeOps.Operator/Reconciliation/Reconciler.cs |
Avoids unconditional updates when auto-attaching; only updates on actual finalizer changes and only detaches when removal succeeds. |
test/KubeOps.Operator.Test/Reconciliation/Reconciler.Test.cs |
Updates tests to use the xUnit-provided cancellation token; adds a unit test ensuring no update occurs when no finalizers exist. |
test/KubeOps.Operator.Test/Finalizer/EntityFinalizer.AutoAttachIntegration.Test.cs |
Adds an integration test around auto-attach behavior with a controller that updates status. |
test/KubeOps.Operator.Test/Controller/EntityController.Integration.Test.cs |
Adjusts integration controller to optionally update status to reproduce/guard against the 409-conflict scenario. |
test/KubeOps.Operator.Test/TestEntities/V1OperatorIntegrationTestEntity.cs |
Adds a spec flag used by integration tests to trigger status updates from the controller. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
test/KubeOps.Operator.Test/Finalizer/EntityFinalizer.AutoAttachIntegration.Test.cs
Outdated
Show resolved
Hide resolved
test/KubeOps.Operator.Test/Finalizer/EntityFinalizer.AutoAttachIntegration.Test.cs
Show resolved
Hide resolved
…hIntegration.Test.cs Co-authored-by: Copilot <[email protected]>
This was referenced Mar 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
optimizes the finalizer attachment logic to avoid unnecessary entity updates:
this most probably could fix #1001