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 Sep 28, 2024
1 parent fa54ce2 commit 298fa12
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion 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().IntVar(&diffExitCode, "diff-exit-code", 1, "Return specified exit code when there is a diff")
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
1 change: 1 addition & 0 deletions 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 298fa12

Please sign in to comment.