diff --git a/internal/sanitize/types.go b/internal/sanitize/types.go index 9c522a8a..8e4a9353 100644 --- a/internal/sanitize/types.go +++ b/internal/sanitize/types.go @@ -95,11 +95,17 @@ func isOperationalLabel(key string) bool { // that belongs in Git, and stripping them would silently drop a user's sync // ordering. Hence the exact-key match. // +// `kcp.io/cluster` is matched exactly for the same reason. kcp stamps it on every +// object to name the logical cluster the object was read from, so it is an address +// rather than intent: committed to Git it would pin a manifest to one workspace and +// travel with it into every other. Sibling `kcp.io/` keys are not assumed to be +// bookkeeping too, so this is not a prefix strip either. +// // Exercised end-to-end against a real Argo CD in // test/e2e/argocd_bi_directional_e2e_test.go. func isOperationalAnnotation(key string) bool { switch key { - case "argocd.argoproj.io/tracking-id", "argocd.argoproj.io/installation-id": + case "argocd.argoproj.io/tracking-id", "argocd.argoproj.io/installation-id", "kcp.io/cluster": return true } diff --git a/internal/sanitize/types_test.go b/internal/sanitize/types_test.go index c0b36f80..64b0344b 100644 --- a/internal/sanitize/types_test.go +++ b/internal/sanitize/types_test.go @@ -309,12 +309,37 @@ func TestCleanAnnotations(t *testing.T) { "argocd.argoproj.io/hook": "kept", }, }, + { + // kcp names the logical cluster an object was read from. It is an address, + // not intent: in Git it would pin the manifest to one workspace and travel + // with it into every other. + name: "remove kcp logical-cluster annotation", + input: map[string]string{ + "kcp.io/cluster": "root:org:team", + "user-annotation": "kept", + }, + expected: map[string]string{ + "user-annotation": "kept", + }, + }, + { + // Exact-key, not a `kcp.io/` prefix strip: sibling keys under the prefix are + // not assumed to be bookkeeping. + name: "keep other kcp annotations", + input: map[string]string{ + "kcp.io/path": "kept", + }, + expected: map[string]string{ + "kcp.io/path": "kept", + }, + }, { name: "all annotations operational - return nil", input: map[string]string{ "kubectl.kubernetes.io/last-applied-configuration": "removed", "control-plane.alpha.kubernetes.io/leader": "removed", "argocd.argoproj.io/tracking-id": "removed", + "kcp.io/cluster": "removed", }, expected: nil, },