From 5b6d6de2b94f951626c96e54fba81dd40c7c65d1 Mon Sep 17 00:00:00 2001 From: Cam Hutchison Date: Fri, 7 Feb 2020 14:04:04 +1100 Subject: [PATCH] diff: Add --no-error-on-diff flag Add a `--no-error-on-diff` flag to the `diff` subcommand so as to not exit with an error when there are diffs present. It will still exit with an error if the configs are not valid, so `kubecfg diff` can be a useful command to run on a branch of a CI system to show diffs and still validate the configs. --- cmd/diff.go | 11 +++++++++-- pkg/kubecfg/diff.go | 5 +++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cmd/diff.go b/cmd/diff.go index d741b37d..6fcf618f 100644 --- a/cmd/diff.go +++ b/cmd/diff.go @@ -22,12 +22,14 @@ import ( ) const ( - flagDiffStrategy = "diff-strategy" - flagOmitSecrets = "omit-secrets" + flagDiffStrategy = "diff-strategy" + flagNoErrorOnDiff = "no-error-on-diff" + flagOmitSecrets = "omit-secrets" ) func init() { diffCmd.PersistentFlags().String(flagDiffStrategy, "all", "Diff strategy, all or subset.") + diffCmd.PersistentFlags().Bool(flagNoErrorOnDiff, false, "don't exit with error if there are differences") diffCmd.PersistentFlags().Bool(flagOmitSecrets, false, "hide secret details when showing diff") RootCmd.AddCommand(diffCmd) } @@ -47,6 +49,11 @@ var diffCmd = &cobra.Command{ return err } + c.NoErrorOnDiff, err = flags.GetBool(flagNoErrorOnDiff) + if err != nil { + return err + } + c.OmitSecrets, err = flags.GetBool(flagOmitSecrets) if err != nil { return err diff --git a/pkg/kubecfg/diff.go b/pkg/kubecfg/diff.go index 9f87e807..22a73853 100644 --- a/pkg/kubecfg/diff.go +++ b/pkg/kubecfg/diff.go @@ -50,7 +50,8 @@ type DiffCmd struct { DefaultNamespace string OmitSecrets bool - DiffStrategy string + DiffStrategy string + NoErrorOnDiff bool } func (c DiffCmd) Run(apiObjects []*unstructured.Unstructured, out io.Writer) error { @@ -112,7 +113,7 @@ func (c DiffCmd) Run(apiObjects []*unstructured.Unstructured, out io.Writer) err } } - if diffFound { + if diffFound && !c.NoErrorOnDiff { return ErrDiffFound } return nil