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