Skip to content

fix: honor management-policy for create/update in reconcile worker#58

Open
matteogastaldello wants to merge 1 commit into
mainfrom
fix/honor-management-policy-create-update
Open

fix: honor management-policy for create/update in reconcile worker#58
matteogastaldello wants to merge 1 commit into
mainfrom
fix/honor-management-policy-create-update

Conversation

@matteogastaldello

Copy link
Copy Markdown
Contributor

Problem

The reconcile worker only gated the delete action against the management
policy (meta.ShouldDelete in processNextItem). The krateo.io/management-policy
values that should suppress writes were therefore not enforced for create/update:
handleObserve enqueued a Create event whenever Observe reported the resource
missing, and an Update event 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 are
meant to behave identically from a resource-lifecycle standpoint, so this was a bug.

Fix

pkg/controller/worker.gohandleObserve now gates the enqueued actions:

  • Create is enqueued only when !ResourceExists && meta.ShouldCreate(el)
  • Update is enqueued only when ResourceExists && !ResourceUpToDate && meta.ShouldUpdate(el)

When the pending action is disallowed by the policy (e.g. observe, observe-delete),
handleObserve falls through to the existing success/no-op path: it sets
ReconcileSuccess and updates status instead of enqueueing the action.
Delete continues to be gated by meta.ShouldDelete as before.

Tests

Adds TestHandleObserve_ManagementPolicyGatesCreateAndUpdate, a table-driven test
covering observe, observe-delete, observe-create-update and the default
(no annotation) policy across both the create and update paths.

go build ./... and go test ./... pass.

🤖 Generated with Claude Code

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

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.89474% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/controller/worker.go 57.89% 6 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

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.

1 participant