Skip to content

Commit

Permalink
feat(cli): Add app diff option to specify exit code when diff
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
eugene70 committed Oct 3, 2024
1 parent f506127 commit 7c10f5f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,7 @@ func NewApplicationDiffCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
refresh bool
hardRefresh bool
exitCode bool
diffExitCode int
local string
revision string
localRepoRoot string
Expand Down Expand Up @@ -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")
command.Flags().BoolVar(&exitCode, "exit-code", true, "Return non-zero exit code when there is a diff. May also return non-zero exit code if there is an error.")
command.Flags().IntVar(&diffExitCode, "diff-exit-code", 1, "Return specified exit code when there is a diff. Typical error code is 20.")
command.Flags().StringVar(&local, "local", "", "Compare live app to a local manifests")
command.Flags().StringVar(&revision, "revision", "", "Compare live app to a particular revision")
command.Flags().StringVar(&localRepoRoot, "local-repo-root", "/", "Path to the repository root. Used together with --local allows setting the repository root")
Expand Down
3 changes: 2 additions & 1 deletion docs/user-guide/commands/argocd_app_diff.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7c10f5f

Please sign in to comment.