Skip to content

fix: update normalization for ignoreDifferences on server-side diff #747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

pjiang-dev
Copy link
Contributor

@pjiang-dev pjiang-dev commented Jul 16, 2025

fixes argoproj/argo-cd#17362 (comment)

When ignoreDifferences normalization removes fields before server-side apply, it causes validation errors because required fields (like image) are missing from the config sent to the Kubernetes API.

To avoid this issue we will

  1. Skip the normalizer (ignoreDifferences) with a new option applyIgnoreDifference when performing server-side apply --dry-run
  2. After predictedLive is performed, we can now normalize (ignoreDifferences) the config and live
  3. Result will be a diff without those ignoreDifferences fields

Copy link

codecov bot commented Jul 17, 2025

Codecov Report

Attention: Patch coverage is 81.25000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 47.58%. Comparing base (8849c3f) to head (41d976c).
Report is 52 commits behind head on master.

Files with missing lines Patch % Lines
pkg/diff/diff.go 57.14% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #747      +/-   ##
==========================================
- Coverage   54.26%   47.58%   -6.68%     
==========================================
  Files          64       64              
  Lines        6164     6573     +409     
==========================================
- Hits         3345     3128     -217     
- Misses       2549     3188     +639     
+ Partials      270      257      -13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pjiang-dev pjiang-dev force-pushed the pjiang/ignorediff-ssd branch from c229d82 to 164adfc Compare July 17, 2025 05:58
Signed-off-by: Peter Jiang <[email protected]>
@pjiang-dev pjiang-dev marked this pull request as ready for review July 17, 2025 06:21
@pjiang-dev pjiang-dev requested a review from a team as a code owner July 17, 2025 06:21
@pjiang-dev pjiang-dev changed the title WIP fix: update normalization for ignoreDifferences on server-side diff fix: update normalization for ignoreDifferences on server-side diff Jul 17, 2025
Copy link
Contributor

@leoluz leoluz left a comment

Choose a reason for hiding this comment

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

PR is missing tests.

Copy link

Comment on lines +848 to +855
// Skip the normalizer (ignoreDifferences + knownTypes) for server-side diff
// In the case an ignoreDifferences field is required, it needs to be be present in the config
// before server-side diff is calculated and normalized before final comparison.
if o.applyIgnoreDifferences {
err := o.normalizer.Normalize(un)
if err != nil {
o.log.Error(err, fmt.Sprintf("Failed to normalize %s/%s/%s", un.GroupVersionKind(), un.GetNamespace(), un.GetName()))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a public function and is likely called by Argo CD. Maybe we should add a configuration to skip the normalization instead of applying it. This way, it will be backward compatible and we only set the skip option during server-side diff. WDYT?

Copy link
Contributor Author

@pjiang-dev pjiang-dev Jul 22, 2025

Choose a reason for hiding this comment

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

What this is doing is skipping this public Normalization function before calculating predicted live for server-side diff. Then after predicted live is calculated, we do the public Normalize:

Normalize(predictedLive, opts...)
which was already present.

I don't think we can fully skip the Normalization for server-side diff still as it would then show diffs for ignoreDifferences fields.

}
if live != nil {
live = remarshal(live, o)
Normalize(live, opts...)
Normalize(live, append(opts, WithApplyIgnoreDifferences(false))...)
Copy link
Member

@agaudreault agaudreault Jul 23, 2025

Choose a reason for hiding this comment

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

This might be causing a regression with the 2-way diff and 3-way diff below in this method. When 3-way diff is called, the Normalization with IgnoreDifference=true will be done before calling ThreeWayDiff only for the obj in the last-applied-configuration. However, Normalize is not called anymore for live and config, so o.normalizer.Normalize(un) will never be called anymore for 2-way and 3-way diffs. While ServerSideDiff does call Normalize again for live and config, it is not the case for the TwoWayDiff/ThreeWayDiff method.

	Normalize(orig, opts...)
	dr, err := ThreeWayDiff(orig, config, live)
	return TwoWayDiff(config, live)

My suggestion would be to call normalize based on serverSideDiff option, and preserve the behaviour for other kind of diff. I assume RespectIgnoreDifference is important for 2-way and 3-way diff, and I feel tests are missing for this.

	preDiffOpts := opts
	o := applyOptions(opts)
	if o.serverSideDiff {
		preDiffOpts = append(preDiffOpts, WithApplyIgnoreDifferences(false))
	}
	if config != nil {
		config = remarshal(config, o)
		Normalize(config, preDiffOpts...)
	}
	if live != nil {
		live = remarshal(live, o)
		Normalize(live, preDiffOpts...)
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. I missed that this Diff function is shared with the other diff methods.

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.

Server-Side Diff with RespectIgnoreDifferences can fail diff due to missing required fields
3 participants