fix: skip target normalization merge patch for resources without matching ignoreDifferences (#26588)#26994
Conversation
❌ Preview Environment undeployed from BunnyshellAvailable commands (reply to this comment):
|
…ut matching ignoreDifferences rules Fixes argoproj#26588 Signed-off-by: Eugene Babichev <eugene.babichev@clickhouse.com>
5fd7fd7 to
1b64ad3
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #26994 +/- ##
==========================================
+ Coverage 63.96% 63.98% +0.02%
==========================================
Files 421 421
Lines 57774 57791 +17
==========================================
+ Hits 36954 36978 +24
+ Misses 17338 17333 -5
+ Partials 3482 3480 -2 ☔ View full report in Codecov by Sentry. |
|
Hi, Severity: action required | Category: correctness How to fix: Ignore non-sync overrides in guard Agent prompt to fix - you can give this to your LLM of choice:
We noticed a couple of other issues in this PR as well — happy to share if helpful. Found by Qodo code review |
|
Thanks for the review!
Yes, please, do let me know. |
Signed-off-by: Eugene Babichev <eugene.babichev@clickhouse.com>
0f703a7 to
2442a09
Compare
|
@qodo-ai-reviewer The issue should be fixed now |
Fixes #26588 (partially)
Checklist:
normalizeTargetResources()computes a merge patch between normalized-live and raw-live, then applies it to the sync target. The idea is to copy ignored field values from the live object into the target so they don't get changed during sync.Problem is, this runs for every resource regardless of whether any
ignoreDifferencesrules actually match it. For most fields that's fine — the patch is effectively a no-op. But it breaks for:Fields with
patchStrategy:"replace"—CreateThreeWayMergePatchalways includes these in the patch even when the values are identical across all inputs. This is by-design in the k8s strategic merge patch library (replace-strategy fields are atomic). Example:PodDisruptionBudget.spec.selector.CRDs not registered in the k8s scheme — falls back to JSON merge patch which replaces arrays wholesale instead of merging by key. This is the Rollout env var case from Enabling RespectIgnoreDifferences causes diff to not be applied and app to become stuck in an OutOfSync state #26588.
In both cases the live state gets written into the target, ArgoCD applies it (no actual change), the diff persists, and the app is stuck OutOfSync forever while reporting sync "Succeeded".
I hit this on EKS clusters where the
corednsPDB had a different selector in live (set by EKS) vs desired (set by our Helm chart). RemovingRespectIgnoreDifferences=trueimmediately fixed sync.The fix has two parts:
Before computing the merge patch for a resource, check if it has any matching
ignoreDifferencesrules (app-level or system-level overrides). If not, skip the merge-patch-and-apply step entirely and return the original target. There's nothing to copy from live if no fields are being ignored.Filter out
/statusfrom resource overrides before the per-resource check. By default,GetResourceOverrides()injects a*/*override with/statusignored — this is for diffing, not target normalization (status isn't in targets and gets stripped by the API server). Without filtering,HasIgnoreDifferencereturnstruefor every resource via the wildcard match, defeating the skip logic entirely.This doesn't help the case where ignore rules DO match the resource —
patchStrategy:"replace"fields will still get overwritten there. That's a harder problem for a follow-up.Note: there's an existing PR #26924 that skips normalization when ignores are empty. This PR goes further — it skips per-resource when the rules don't match, which also handles the case from the original issue reporter's comment where unrelated ignore rules are present.
Cherry-pick candidates: 2.14, 2.13 (probably any release with
normalizeTargetResources).