diff --git a/main.go b/main.go index c05b9104..7cbcbcf8 100644 --- a/main.go +++ b/main.go @@ -75,6 +75,10 @@ func main() { Name: "kube-context", Usage: "Set kubectl context. Uses current context by default", }, + cli.BoolFlag{ + Name: "no-color", + Usage: "Output without color", + }, cli.StringFlag{ Name: "log-level", Usage: "Set log level, default info", @@ -537,6 +541,10 @@ func (c configImpl) Interactive() bool { return c.c.GlobalBool("interactive") } +func (c configImpl) NoColor() bool { + return c.c.GlobalBool("no-color") +} + func (c configImpl) Logger() *zap.SugaredLogger { return c.c.App.Metadata["logger"].(*zap.SugaredLogger) } diff --git a/pkg/app/config.go b/pkg/app/config.go index fbac5c64..f6df1ed7 100644 --- a/pkg/app/config.go +++ b/pkg/app/config.go @@ -40,6 +40,8 @@ type ApplyConfigProvider interface { SuppressSecrets() bool + NoColor() bool + concurrencyConfig interactive loggingConfig @@ -64,6 +66,7 @@ type DiffConfigProvider interface { SuppressSecrets() bool DetailedExitcode() bool + NoColor() bool concurrencyConfig } diff --git a/pkg/app/run.go b/pkg/app/run.go index a47c8176..46d405cb 100644 --- a/pkg/app/run.go +++ b/pkg/app/run.go @@ -137,7 +137,11 @@ func (r *Run) Apply(c ApplyConfigProvider) []error { // helm must be 2.11+ and helm-diff should be provided `--detailed-exitcode` in order for `helmfile apply` to work properly detailedExitCode := true - releases, errs := st.DiffReleases(helm, c.Values(), c.Concurrency(), detailedExitCode, c.SuppressSecrets(), false) + diffOpts := &state.DiffOpts{ + NoColor: c.NoColor(), + } + + releases, errs := st.DiffReleases(helm, c.Values(), c.Concurrency(), detailedExitCode, c.SuppressSecrets(), false, diffOpts) releasesToBeDeleted, err := st.DetectReleasesToBeDeleted(helm) if err != nil { diff --git a/pkg/state/state.go b/pkg/state/state.go index 81dbe812..fce77d0e 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -705,7 +705,12 @@ type diffPrepareResult struct { errors []*ReleaseError } -func (st *HelmState) prepareDiffReleases(helm helmexec.Interface, additionalValues []string, concurrency int, detailedExitCode, suppressSecrets bool) ([]diffPrepareResult, []error) { +func (st *HelmState) prepareDiffReleases(helm helmexec.Interface, additionalValues []string, concurrency int, detailedExitCode, suppressSecrets bool, opt ...DiffOpt) ([]diffPrepareResult, []error) { + opts := &DiffOpts{} + for _, o := range opt { + o.Apply(opts) + } + releases := []*ReleaseSpec{} for i, _ := range st.Releases { if !st.Releases[i].Desired() { @@ -767,6 +772,10 @@ func (st *HelmState) prepareDiffReleases(helm helmexec.Interface, additionalValu flags = append(flags, "--suppress-secrets") } + if opts.NoColor { + flags = append(flags, "--no-color") + } + if len(errs) > 0 { rsErrs := make([]*ReleaseError, len(errs)) for i, e := range errs { @@ -812,10 +821,25 @@ func (st *HelmState) createHelmContext(spec *ReleaseSpec, workerIndex int) helme } } +type DiffOpts struct { + NoColor bool +} + +func (o *DiffOpts) Apply(opts *DiffOpts) { + *opts = *o +} + +type DiffOpt interface{ Apply(*DiffOpts) } + // DiffReleases wrapper for executing helm diff on the releases // It returns releases that had any changes -func (st *HelmState) DiffReleases(helm helmexec.Interface, additionalValues []string, workerLimit int, detailedExitCode, suppressSecrets bool, triggerCleanupEvents bool) ([]*ReleaseSpec, []error) { - preps, prepErrs := st.prepareDiffReleases(helm, additionalValues, workerLimit, detailedExitCode, suppressSecrets) +func (st *HelmState) DiffReleases(helm helmexec.Interface, additionalValues []string, workerLimit int, detailedExitCode, suppressSecrets bool, triggerCleanupEvents bool, opt ...DiffOpt) ([]*ReleaseSpec, []error) { + opts := &DiffOpts{} + for _, o := range opt { + o.Apply(opts) + } + + preps, prepErrs := st.prepareDiffReleases(helm, additionalValues, workerLimit, detailedExitCode, suppressSecrets, opts) if len(prepErrs) > 0 { return []*ReleaseSpec{}, prepErrs } diff --git a/test/integration/run.sh b/test/integration/run.sh index 86007cfd..bfca8bcf 100755 --- a/test/integration/run.sh +++ b/test/integration/run.sh @@ -60,6 +60,9 @@ test_start "happypath - simple rollout of httpbin chart" info "Diffing ${dir}/happypath.yaml" bash -c "${helmfile} -f ${dir}/happypath.yaml diff --detailed-exitcode; code="'$?'"; [ "'${code}'" -eq 2 ]" || fail "unexpected exit code returned by helmfile diff" +info "Diffing ${dir}/happypath.yaml without color" +bash -c "${helmfile} -f ${dir}/happypath.yaml --no-color diff --detailed-exitcode; code="'$?'"; [ "'${code}'" -eq 2 ]" || fail "unexpected exit code returned by helmfile diff" + info "Templating ${dir}/happypath.yaml" ${helmfile} -f ${dir}/happypath.yaml template code=$?