Skip to content

Warn about conflicting Kustomization ownership - #1807

Merged
matheuscscp merged 1 commit into
fluxcd:mainfrom
DDINGJOO:warn-resource-ownership
Nov 20, 2026
Merged

matheuscscp merged 1 commit into
fluxcd:mainfrom
DDINGJOO:warn-resource-ownership

Conversation

@DDINGJOO

@DDINGJOO DDINGJOO commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

When ownership labels identify another Kustomization, emit one short OwnershipConflict Warning event per apply attempt before writing the first conflicting resource. Record all detected resources and their previous owners in one structured log per apply, including failed applies. SSA continues without changing readiness or pruning behavior.

Use ApplyOptions.OnOwnershipConflict from the released github.com/fluxcd/pkg/ssa v0.84.0 to reuse SSA's live-object lookup and skip-policy handling. The warning is limited with a function-local sync.Once; conflict details are collected safely across concurrent callbacks and logged when staged apply returns.

Includes 21 ownership cases, a read-concurrency regression and 32-object concurrent batches. Tests check one GET per resource, warning timing, one short event and one log containing every resource and previous owner, repeated attempts, write failures and silence without conflicts. Reverting the log aggregation makes both conflict batch cases fail with 32 logs instead of one.

Validation: make test GO_TEST_ARGS='-count=1' ENVTEST_KUBERNETES_VERSION=1.37.0 passes, including tidy, generation, formatting and vet. The full suite passes 90 top-level tests (403 including subtests), with no failures or skips. Generated files are unchanged. Focused ownership tests also pass with -race.

Fixes #1724

AI assistance: Codex (GPT-6).

@matheuscscp

matheuscscp commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Not sure we want to add one GET per object... I'm wondering if it would be possible for the SSA lib to report the conflicts back to the controller, then the controller emits the warning...

@DDINGJOO

Copy link
Copy Markdown
Contributor Author

Thanks, that makes sense. I've opened fluxcd/pkg#1377 to report ownership conflicts from SSA's existing live-object lookup, after skip checks and before the first write.

I tested the controller change locally against that patch: the ownership tests now assert one GET per object and a warning before the first PATCH. The full SSA suite passes with race detection, and the full controller suite passes. I'll update this PR to use the callback once the upstream SSA change is available.

@DDINGJOO

Copy link
Copy Markdown
Contributor Author

The SSA prerequisite, fluxcd/pkg#1377, is now merged. I'll update this PR once an official SSA release includes OnOwnershipConflict, using that release to reuse SSA's existing live-object lookup instead of the separate ownership GET. The source integration is prepared locally; I'll rerun the controller checks against the released dependency before pushing it here.

@matheuscscp

Copy link
Copy Markdown
Member

Tag ssa/v0.84.0 is released.

@DDINGJOO

Copy link
Copy Markdown
Contributor Author

Updated this PR to use the released SSA v0.84.0 and OnOwnershipConflict, removing the separate ownership GET. Tests now assert one GET per resource and a warning before the first PATCH. make tidy fmt vet and the full make test suite pass against the release (399 tests including subtests).

@matheuscscp matheuscscp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A big problem with this implementation is that we may end up sending too many events... There could be a situation where two different Kustomizations apply 1000 overlapping objects...

In fluxcd/source-watcher#392 we introduced OwnershipConflict by making the event content short. We can for example emit all the object references in the controller logs, but not on events...

@DDINGJOO

Copy link
Copy Markdown
Contributor Author

Agreed, one event per object is too much. Updated this to emit a single short OwnershipConflict warning per apply attempt and log each resource and previous owner. The warning is still emitted before applying the first conflicting resource, including when apply later fails.

Added concurrent batch coverage for successful and failed applies, repeated attempts, and GET reuse. Local make test and the focused race tests pass.

Comment thread docs/spec/v1/kustomizations.md Resolved
@matheuscscp matheuscscp added enhancement New feature or request area/ux In pursuit of a delightful user experience labels Nov 18, 2026
@matheuscscp

Copy link
Copy Markdown
Member

@DDINGJOO Please run make fix, otherwise the CI will fail like this:

https://github.com/fluxcd/kustomize-controller/actions/runs/44234357357/job/134693901633?pr=1807

@matheuscscp matheuscscp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@DDINGJOO Please squash all the commits into one and force-push 🙏

Emit one warning per apply before adopting resources owned by another
Kustomization, and log the conflicting resources and previous owners.
Reuse the SSA ownership lookup and cover ordering and concurrency.

Signed-off-by: MyungJoo Song <173995233+DDINGJOO@users.noreply.github.com>
Assisted-by: Codex/GPT-6
@DDINGJOO
DDINGJOO force-pushed the warn-resource-ownership branch from 4673a55 to 492c564 Compare November 19, 2026 08:52
@DDINGJOO

Copy link
Copy Markdown
Contributor Author

Squashed into one commit and force-pushed as 492c564. The workflows are waiting for approval. Thanks for the review!

@matheuscscp
matheuscscp merged commit 4fc25ef into fluxcd:main Nov 20, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ux In pursuit of a delightful user experience enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emit a warning event when a Kustomization overwrites an object owned by another Kustomization

2 participants