Skip to content

fix(reconciler): prevent unnecessary updates when auto-attaching finalizers#1057

Merged
kimpenhaus merged 15 commits intodotnet:mainfrom
kimpenhaus:bugfix/409-no-finalizers-auto-attach
Feb 25, 2026
Merged

fix(reconciler): prevent unnecessary updates when auto-attaching finalizers#1057
kimpenhaus merged 15 commits intodotnet:mainfrom
kimpenhaus:bugfix/409-no-finalizers-auto-attach

Conversation

@kimpenhaus
Copy link
Collaborator

optimizes the finalizer attachment logic to avoid unnecessary entity updates:

  • Only updates entity in the cluster when finalizers are actually added
  • Only removes finalizers when auto-detach is enabled and removal succeeds
  • Adds integration test verifying auto-attach behavior with status updates

this most probably could fix #1001

buehler
buehler previously approved these changes Feb 25, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 UpdateAsync when at least one finalizer was actually added.
  • Update auto-detach logic to only UpdateAsync when 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.

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.

[bug]: Reconciliation 409-Conflict failing on Modified entities since v10

3 participants