Skip to content

Conversation

@pjiang-dev
Copy link
Contributor

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

closes #23868
fixes #22345
fixes #23171

Adds CLI support for argocd app diff --server-side-diff and works with existing flags --local --revision

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • The title of the PR conforms to the Toolchain Guide
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).
  • My new feature complies with the feature status guidelines.
  • I have added a brief description of why this PR is necessary and/or what this PR solves.
  • Optional. My organization is added to USERS.md.
  • Optional. For bug fixes, I've indicated what older releases this fix should be cherry-picked into (this may or may not happen depending on risk/complexity).

@pjiang-dev pjiang-dev requested review from a team as code owners July 28, 2025 21:59
@bunnyshell
Copy link

bunnyshell bot commented Jul 28, 2025

❌ Preview Environment deleted from Bunnyshell

Available commands (reply to this comment):

  • 🚀 /bns:deploy to deploy the environment

@pjiang-dev pjiang-dev marked this pull request as draft July 28, 2025 22:47
@pjiang-dev pjiang-dev marked this pull request as ready for review July 29, 2025 00:05
Copy link
Member

@nitishfy nitishfy left a comment

Choose a reason for hiding this comment

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

can you please fix the failing checks?

@codecov
Copy link

codecov bot commented Jul 29, 2025

Codecov Report

❌ Patch coverage is 20.14388% with 222 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.10%. Comparing base (03ac864) to head (f579cba).
⚠️ Report is 807 commits behind head on master.

Files with missing lines Patch % Lines
cmd/argocd/commands/app.go 1.40% 140 Missing ⚠️
server/application/application.go 39.70% 70 Missing and 12 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #23978      +/-   ##
==========================================
- Coverage   60.25%   60.10%   -0.15%     
==========================================
  Files         347      347              
  Lines       59354    59853     +499     
==========================================
+ Hits        35761    35976     +215     
- Misses      20724    20987     +263     
- Partials     2869     2890      +21     

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

Comment on lines 1419 to 1423
foundDiffs := findAndPrintServerSideDiff(ctx, app, proj.Project, resources, argoSettings, diffOption, appIf, appName, appNs)
if foundDiffs && exitCode {
os.Exit(diffExitCode)
}
return
Copy link
Collaborator

Choose a reason for hiding this comment

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

It doesn't seem like a good idea to create a new function just for server-side diff. Note that findandPrintDiff is also called in the sync command which wouldn't have the SSD feature. I think that we should modify the findandPrintDiff function and add the SSD feature there based on the diff options provided.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. I did not realize this findandPrintDiff is used in sync command as well

Copy link
Contributor Author

@pjiang-dev pjiang-dev Aug 1, 2025

Choose a reason for hiding this comment

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

Question @leoluz. For the sync command, are we going to infer whether to use server-side diff in the result by using the app's annotation only?
Or will we need a new flag for sync as well for --server-side-diff ?
For example something like argocd app sync myapp --dry-run --server-side ?

I have currently hardcoded it to false until we decide

Copy link
Collaborator

@leoluz leoluz Aug 11, 2025

Choose a reason for hiding this comment

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

are we going to infer whether to use server-side diff in the result by using the app's annotation only?
Or will we need a new flag for sync as well for --server-side-diff ?

Can we have both? I think by default it should be checking what is in the app's annotation. However it would be nice if from the CLI we could customize this behaviour as well. I would say: Make sure to honour what is configured in the app is the priority #1. Adding a new flag is a nice to have but lower priority.

Signed-off-by: Peter Jiang <[email protected]>
Signed-off-by: Peter Jiang <[email protected]>
Signed-off-by: Peter Jiang <[email protected]>
Signed-off-by: Peter Jiang <[email protected]>
Signed-off-by: Peter Jiang <[email protected]>
Signed-off-by: Peter Jiang <[email protected]>
Signed-off-by: Peter Jiang <[email protected]>
Signed-off-by: Peter Jiang <[email protected]>
Signed-off-by: Peter Jiang <[email protected]>
Signed-off-by: Peter Jiang <[email protected]>
Signed-off-by: Peter Jiang <[email protected]>
Signed-off-by: Peter Jiang <[email protected]>
Signed-off-by: Peter Jiang <[email protected]>
Signed-off-by: Peter Jiang <[email protected]>
Signed-off-by: Peter Jiang <[email protected]>
Copy link
Member

@agaudreault agaudreault left a comment

Choose a reason for hiding this comment

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

overall LGTM, few nitpicks

Signed-off-by: Peter Jiang <[email protected]>
Comment on lines +2859 to +2881
// Get cluster connection for server-side dry run
cluster, err := argo.GetDestinationCluster(ctx, a.Spec.Destination, s.db)
if err != nil {
return nil, fmt.Errorf("error getting destination cluster: %w", err)
}

clusterConfig, err := cluster.RawRestConfig()
if err != nil {
return nil, fmt.Errorf("error getting cluster raw REST config: %w", err)
}

// Create server-side diff dry run applier
openAPISchema, gvkParser, err := s.kubectl.LoadOpenAPISchema(clusterConfig)
if err != nil {
return nil, fmt.Errorf("failed to get OpenAPI schema: %w", err)
}

applier, cleanup, err := kubeutil.ManageServerSideDiffDryRuns(clusterConfig, openAPISchema, func(_ string) (kube.CleanupFunc, error) {
return func() {}, nil
})
if err != nil {
return nil, fmt.Errorf("error creating server-side dry run applier: %w", err)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This logic is similar to appStateManager.getServerSideDiffDryRunApplier (in controller/sync.go). Can you please verify if we can extract the similar logic from both and centralize it in a single function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They do look similar but are different workflows with different patterns.
Controller uses liveStateCache.GetClusterCache(cluster) to get a cached cluster object
and openAPISchema is already loaded and cached

Server uses argo.GetDestinationCluster() to get a fresh cluster object and openAPI schema must be loaded fresh via s.kubectl.LoadOpenAPISchema(clusterConfig)

Controller: Needs RawRestConfig() only for the applier creation
Server: Needs RawRestConfig() twice - once for schema loading AND once for applier creation

So centralizing the logic would require abstracting cache vs. direct cluster acces and i don't think this is worth the complexity

Copy link
Collaborator

@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.

Replied #23978 (comment)
PTAL

Copy link
Collaborator

@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.

We need to make sure that the documentation of this new command is created in ./docs/user-guide/commands. I believe that there is a make target available for updating that folder.

Signed-off-by: Peter Jiang <[email protected]>
Signed-off-by: Peter Jiang <[email protected]>
Signed-off-by: Peter Jiang <[email protected]>
Copy link
Collaborator

@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.

LGTM

@leoluz leoluz merged commit 6a20776 into argoproj:master Aug 12, 2025
28 checks passed
yohanb pushed a commit to yohanb/argo-cd that referenced this pull request Aug 12, 2025
yohanb pushed a commit to yohanb/argo-cd that referenced this pull request Aug 12, 2025
Signed-off-by: Peter Jiang <[email protected]>

feat(azure): allow setting azure cloud (gov, china) for authentication

Signed-off-by: Yohan Belval <[email protected]>

feat(azure): allow setting azure cloud (gov, china) for authentication

Signed-off-by: Yohan Belval <[email protected]>
yohanb pushed a commit to yohanb/argo-cd that referenced this pull request Aug 12, 2025
Signed-off-by: Peter Jiang <[email protected]>

feat(azure): allow setting azure cloud (gov, china) for authentication

Signed-off-by: Yohan Belval <[email protected]>

feat(azure): allow setting azure cloud (gov, china) for authentication

Signed-off-by: Yohan Belval <[email protected]>
yohanb pushed a commit to yohanb/argo-cd that referenced this pull request Aug 12, 2025
enneitex pushed a commit to enneitex/argo-cd that referenced this pull request Aug 24, 2025
downfa11 pushed a commit to downfa11/argo-cd that referenced this pull request Aug 25, 2025
Mangaal pushed a commit to Mangaal/argo-cd that referenced this pull request Sep 10, 2025
downfa11 pushed a commit to downfa11/argo-cd that referenced this pull request Sep 12, 2025
@nitishfy nitishfy added the release-blog-3.2rc PRs to be included in Argo CD v3.2 RC label Sep 15, 2025
sivasath16 pushed a commit to sivasath16/argo-cd that referenced this pull request Sep 17, 2025
sivasath16 pushed a commit to sivasath16/argo-cd that referenced this pull request Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-blog-3.2rc PRs to be included in Argo CD v3.2 RC

Projects

None yet

4 participants