Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Commit

Permalink
diff: Add --no-error-on-diff flag
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
camh- committed Feb 7, 2020
1 parent 3f7b5b5 commit aa27319
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 9 additions & 2 deletions cmd/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "dont exit with error if there are differences")
diffCmd.PersistentFlags().Bool(flagOmitSecrets, false, "hide secret details when showing diff")
RootCmd.AddCommand(diffCmd)
}
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pkg/kubecfg/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit aa27319

Please sign in to comment.