fix: honor management-policy for create/update in reconcile worker#58
Open
matteogastaldello wants to merge 1 commit into
Open
fix: honor management-policy for create/update in reconcile worker#58matteogastaldello wants to merge 1 commit into
matteogastaldello wants to merge 1 commit into
Conversation
The reconcile worker previously gated only the delete action via meta.ShouldDelete, so the krateo.io/management-policy values "observe" and "observe-delete" did not actually prevent create/update: handleObserve enqueued Create whenever the resource was missing and Update whenever it was not up to date, regardless of policy. Mirror provider-runtime by gating the enqueued actions with meta.ShouldCreate and meta.ShouldUpdate. When the pending action is disallowed by the policy, handleObserve now falls through to the success/no-op path (sets ReconcileSuccess and updates status) instead of enqueueing it. Adds table-driven tests covering observe, observe-delete, observe-create-update and the default policy for both the create and update paths. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Problem
The reconcile worker only gated the delete action against the management
policy (
meta.ShouldDeleteinprocessNextItem). Thekrateo.io/management-policyvalues that should suppress writes were therefore not enforced for create/update:
handleObserveenqueued aCreateevent wheneverObservereported the resourcemissing, and an
Updateevent whenever it reported the resource out of date —regardless of policy.
This diverged from the sibling library provider-runtime, which gates all three
actions (
ShouldCreate/ShouldUpdate/ShouldDelete). The two runtimes aremeant to behave identically from a resource-lifecycle standpoint, so this was a bug.
Fix
pkg/controller/worker.go—handleObservenow gates the enqueued actions:Createis enqueued only when!ResourceExists && meta.ShouldCreate(el)Updateis enqueued only whenResourceExists && !ResourceUpToDate && meta.ShouldUpdate(el)When the pending action is disallowed by the policy (e.g.
observe,observe-delete),handleObservefalls through to the existing success/no-op path: it setsReconcileSuccessand updates status instead of enqueueing the action.Deletecontinues to be gated bymeta.ShouldDeleteas before.Tests
Adds
TestHandleObserve_ManagementPolicyGatesCreateAndUpdate, a table-driven testcovering
observe,observe-delete,observe-create-updateand the default(no annotation) policy across both the create and update paths.
go build ./...andgo test ./...pass.🤖 Generated with Claude Code