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

Commit 5b6d6de

Browse files
committed
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.
1 parent 3f7b5b5 commit 5b6d6de

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

cmd/diff.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ import (
2222
)
2323

2424
const (
25-
flagDiffStrategy = "diff-strategy"
26-
flagOmitSecrets = "omit-secrets"
25+
flagDiffStrategy = "diff-strategy"
26+
flagNoErrorOnDiff = "no-error-on-diff"
27+
flagOmitSecrets = "omit-secrets"
2728
)
2829

2930
func init() {
3031
diffCmd.PersistentFlags().String(flagDiffStrategy, "all", "Diff strategy, all or subset.")
32+
diffCmd.PersistentFlags().Bool(flagNoErrorOnDiff, false, "don't exit with error if there are differences")
3133
diffCmd.PersistentFlags().Bool(flagOmitSecrets, false, "hide secret details when showing diff")
3234
RootCmd.AddCommand(diffCmd)
3335
}
@@ -47,6 +49,11 @@ var diffCmd = &cobra.Command{
4749
return err
4850
}
4951

52+
c.NoErrorOnDiff, err = flags.GetBool(flagNoErrorOnDiff)
53+
if err != nil {
54+
return err
55+
}
56+
5057
c.OmitSecrets, err = flags.GetBool(flagOmitSecrets)
5158
if err != nil {
5259
return err

pkg/kubecfg/diff.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ type DiffCmd struct {
5050
DefaultNamespace string
5151
OmitSecrets bool
5252

53-
DiffStrategy string
53+
DiffStrategy string
54+
NoErrorOnDiff bool
5455
}
5556

5657
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
112113
}
113114
}
114115

115-
if diffFound {
116+
if diffFound && !c.NoErrorOnDiff {
116117
return ErrDiffFound
117118
}
118119
return nil

0 commit comments

Comments
 (0)