Skip to content
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

feat(cli): Add app diff option to specify exit code when diff #20144

Merged
merged 1 commit into from
Oct 5, 2024

Conversation

eugene70
Copy link
Contributor

@eugene70 eugene70 commented Sep 28, 2024

The argocd app diff command returns 1 if a difference is found. In related issues, they want to return an error code that is distinguishable from common errors. However, changing the existing behavior is likely to break user's automation code. So we want to provide an explicit option(--diff-exit-code) to specify an error code.

Issue: #3588

@eugene70 eugene70 requested a review from a team as a code owner September 28, 2024 07:49
Copy link

bunnyshell bot commented Sep 28, 2024

❌ Preview Environment deleted from Bunnyshell

Available commands (reply to this comment):

  • 🚀 /bns:deploy to deploy the environment

Copy link

bunnyshell bot commented Sep 28, 2024

❌ Preview Environment deleted from Bunnyshell

Available commands (reply to this comment):

  • 🚀 /bns:deploy to deploy the environment

@eugene70 eugene70 changed the title feat(cli): Add app diff option for specify exit code when diff feat(cli): Add app diff option to specify exit code when diff Sep 28, 2024
@eugene70 eugene70 requested a review from a team as a code owner September 28, 2024 07:58
@eugene70
Copy link
Contributor Author

@jannfis PTAL!

Copy link

codecov bot commented Sep 28, 2024

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Project coverage is 55.97%. Comparing base (f506127) to head (110f45e).
Report is 13 commits behind head on master.

Files with missing lines Patch % Lines
cmd/argocd/commands/app.go 0.00% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master   #20144   +/-   ##
=======================================
  Coverage   55.97%   55.97%           
=======================================
  Files         322      322           
  Lines       44546    44548    +2     
=======================================
+ Hits        24933    24937    +4     
- Misses      17042    17047    +5     
+ Partials     2571     2564    -7     

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

Copy link
Member

@crenshaw-dev crenshaw-dev left a comment

Choose a reason for hiding this comment

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

Good stuff! Just a couple small requests.

@@ -1242,13 +1243,14 @@ func NewApplicationDiffCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
proj := getProject(c, clientOpts, ctx, app.Spec.Project)
foundDiffs := findandPrintDiff(ctx, app, proj.Project, resources, argoSettings, diffOption, ignoreNormalizerOpts)
if foundDiffs && exitCode {
os.Exit(1)
os.Exit(diffExitCode)
}
},
}
command.Flags().BoolVar(&refresh, "refresh", false, "Refresh application data when retrieving")
command.Flags().BoolVar(&hardRefresh, "hard-refresh", false, "Refresh application data as well as target manifests cache")
command.Flags().BoolVar(&exitCode, "exit-code", true, "Return non-zero exit code when there is a diff")
Copy link
Member

Choose a reason for hiding this comment

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

Want to update this flag's description to point out that it returns non-zero when there's an error?

}
},
}
command.Flags().BoolVar(&refresh, "refresh", false, "Refresh application data when retrieving")
command.Flags().BoolVar(&hardRefresh, "hard-refresh", false, "Refresh application data as well as target manifests cache")
command.Flags().BoolVar(&exitCode, "exit-code", true, "Return non-zero exit code when there is a diff")
command.Flags().IntVar(&diffExitCode, "diff-exit-code", 1, "Return specified exit code when there is a diff")
Copy link
Member

Choose a reason for hiding this comment

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

If I recall correctly, 20 is the typical exit code for errors. Would it make sense to mention that here so that the user can pick an exit code which is unlikely to conflict with exit codes for other conditions?

The argocd app diff command returns 1 if a difference is found. In related issues,
they want to return an error code that is distinguishable from common errors.
However, changing the existing behavior is likely to break user's automation code.
So we want to provide an explicit option(--diff-exit-code) to specify an error code.

Related: argoproj#3588

Signed-off-by: Eugene Kim <[email protected]>
@eugene70
Copy link
Contributor Author

eugene70 commented Oct 4, 2024

@crenshaw-dev PTAL again!!

@crenshaw-dev crenshaw-dev merged commit 4c29c33 into argoproj:master Oct 5, 2024
26 checks passed
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.

2 participants