Skip to content

fix: include apiVersion in the phase-1 resource matching identity key - #506

Closed
carlochessamp wants to merge 1 commit into
dag-andersen:mainfrom
carlochessamp:fix/resource-matching-api-version
Closed

carlochessamp wants to merge 1 commit into
dag-andersen:mainfrom
carlochessamp:fix/resource-matching-api-version

Conversation

@carlochessamp

Copy link
Copy Markdown

Fix

What

Include apiVersion in the phase-1 resource identity key so resources from different CRD groups that share kind + name (e.g. an Istio networking.istio.io/v1alpha3 VirtualService and a Gloo gateway.solo.io/v1 VirtualService, both named after the app) are treated as distinct identities when pairing base and target manifests.

// before
return r.GetKind() + "/" + r.GetNamespace() + "/" + r.GetName()
// after
return r.GetAPIVersion() + "/" + r.GetKind() + "/" + r.GetNamespace() + "/" + r.GetName()

Why

Fixes #505. With kind+name-only keys, such duplicate-named resources collapse to one key and phase 1 pairs them by index order within the key's index slice — i.e. by manifest extraction order, which under --render-method server-api differs independently between the base and target extractions. When the orders disagree, istio↔gloo cross-pairs both ways, resourcesEqual reports both pairs as changed, and byte-identical renders emit large mirrored phantom hunks per app. We observed this at fleet scale: 84 apps rendering both VirtualServices, ~half of them flagged as Modified with ±100-line churn on any given run of a completely inert PR.

After this change the two resources key separately (per apiVersion), each pairing with its identical counterpart → no diff, as expected. Genuine renames/kind-changes are unaffected: they never matched in phase 1 anyway and continue to be handled by the similarity phases (2–4).

Test

TestChangedResources_SameNameDifferentApiVersionSwappedOrder — base and target render identical istio+gloo VirtualServices in swapped order (extraction order is not guaranteed). Fails on main (2 phantom changed pairs, cross-paired by index), passes with this fix (0 changed resources).

Verified locally:

go test ./pkg/matching/...   # full package green

Resources from different CRD groups can share kind+name (e.g. an Istio
networking.istio.io/v1alpha3 VirtualService and a Gloo gateway.solo.io/v1
VirtualService named after the same app). With kind+name-only keys they
collapsed into one key and phase 1 paired them by index order within the
key's slice - i.e. by manifest extraction order, which differs
independently between the base and target extractions under
--render-method server-api. When the orders disagreed, identical renders
cross-paired and reported both resources as changed, producing large
mirrored phantom hunks per app.

Fixes dag-andersen#505
@carlochessamp
carlochessamp deleted the fix/resource-matching-api-version branch October 29, 2026 13:45
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.

Phantom diffs for apps rendering same-named resources from different apiVersions (resource matching keys on kind/name, not apiVersion)

1 participant