From 04c963d050ab759833a8378271008bf71a71d6a9 Mon Sep 17 00:00:00 2001 From: KUOKA Yusuke Date: Sat, 4 Apr 2020 16:24:01 +0900 Subject: [PATCH] feat: Complete `helmfile diff` output when diff exists (#1173) Fixes #874 --- pkg/app/app.go | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/pkg/app/app.go b/pkg/app/app.go index 22007bf3..a3947c35 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -116,9 +116,42 @@ func (a *App) DeprecatedSyncCharts(c DeprecatedChartsConfigProvider) error { } func (a *App) Diff(c DiffConfigProvider) error { - return a.ForEachStateFiltered(func(run *Run) []error { - return run.Diff(c) + var deferredErrs []error + + err := a.ForEachStateFiltered(func(run *Run) []error { + var criticalErrs []error + + errs := run.Diff(c) + + for i := range errs { + switch e := errs[i].(type) { + case *state.ReleaseError: + switch e.Code { + case 2: + // See https://github.com/roboll/helmfile/issues/874 + deferredErrs = append(deferredErrs, e) + default: + criticalErrs = append(criticalErrs, e) + } + default: + criticalErrs = append(criticalErrs, e) + } + } + + return criticalErrs }) + + if err != nil { + return err + } + + if len(deferredErrs) > 0 { + // We take the first release error w/ exit status 2 (although all the defered errs should have exit status 2) + // to just let helmfile itself to exit with 2 + return deferredErrs[0] + } + + return nil } func (a *App) Template(c TemplateConfigProvider) error {