fix(sanitize): strip the kcp.io/cluster annotation from Git writes#227
Merged
Conversation
kcp stamps `kcp.io/cluster` on every object to name the logical cluster the object was read from. That is an address, not user intent: committed to Git it pins a manifest to one workspace and then travels with it into every other. Matched as an exact key, beside the Argo CD tracking annotations, rather than as a `kcp.io/` prefix strip — sibling keys under that prefix are not assumed to be bookkeeping. A test pins that asymmetry. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe sanitizer now removes the exact ChangesKCP annotation sanitization
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This was referenced Jul 11, 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.
Why
kcp stamps
kcp.io/clusteron every object it serves, naming the logical cluster the object was read from. That makes it an address, not intent: it describes where a copy of the object happened to live, not anything the user asked for.Committed to Git it is actively wrong, and in the way that is hardest to notice — the manifest is pinned to one workspace, and then travels with that pin into every other workspace it is applied to.
What
One key added to the operational-annotation set in
internal/sanitize/types.go:Why it is an exact key and not a
kcp.io/prefix stripDeliberately, and for the same reason the Argo CD keys next to it are exact.
A prefix strip is the tempting shape and the wrong one: it assumes every sibling key under the vendor prefix is bookkeeping too. That assumption is what the existing comment on
isOperationalAnnotationalready warns about forargocd.argoproj.io/— a blanket strip there would silently dropsync-wave,sync-options,hookand other genuine user intent. Nothing tells uskcp.io/is safer, so it gets the same treatment.Two tests pin the asymmetry rather than leaving it to the comment:
remove kcp logical-cluster annotation—kcp.io/clusteris strippedkeep other kcp annotations—kcp.io/pathsurvivesIf a second kcp key ever turns out to be bookkeeping, it should be added by name, and its own test should say so.
Scope
Annotations only — kcp carries this as an annotation, so
isOperationalLabelis untouched. No behavior change for any object that does not carry the key.docs/bi-directional.md's stripped-metadata table is a Flux-vs-Argo comparison, so kcp has no row there; the rationale lives in the godoc onisOperationalAnnotation, where the sibling reasoning already is.Validation
task fmt✅ ·task vet✅ ·task lint✅ (0 issues) ·task test✅ (coverage 75.4%, within the 0.5% tolerance of the 75.5% baseline — no baseline change) ·task test-e2e✅ (54 passed, 0 failed, 10 skipped — the skips are the opt-in bi-directional corner)🤖 Generated with Claude Code