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

diff: Add --no-error-on-diff flag #282

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, "don't 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