From 1afc3baddf2c6e67adaca3255b57da3593dcdba3 Mon Sep 17 00:00:00 2001 From: Arpan Adhikari Date: Tue, 9 Aug 2022 00:41:34 +1000 Subject: [PATCH] added option for --no-hooks for helm diff and apply --- main.go | 12 ++++++++++++ pkg/app/app_test.go | 5 +++++ pkg/app/config.go | 2 ++ pkg/app/diff_test.go | 5 +++++ pkg/app/run.go | 2 +- pkg/state/state.go | 10 +++++++--- pkg/state/state_test.go | 4 ++-- 7 files changed, 34 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 5d975d30..7f328cc5 100644 --- a/main.go +++ b/main.go @@ -223,6 +223,10 @@ func main() { Name: "show-secrets", Usage: "do not redact secret values in the output. should be used for debug purpose only", }, + cli.BoolFlag{ + Name: "no-hooks", + Usage: `Do not diff changes made by hooks.`, + }, cli.IntFlag{ Name: "concurrency", Value: 0, @@ -533,6 +537,10 @@ func main() { Name: "show-secrets", Usage: "do not redact secret values in the diff output. should be used for debug purpose only", }, + cli.BoolFlag{ + Name: "no-hooks", + Usage: `Do not diff changes made by hooks.`, + }, cli.BoolFlag{ Name: "suppress-diff", Usage: "suppress diff in the output. Usable in new installs", @@ -867,6 +875,10 @@ func (c configImpl) ShowSecrets() bool { return c.c.Bool("show-secrets") } +func (c configImpl) NoHooks() bool { + return c.c.Bool("no-hooks") +} + func (c configImpl) SuppressDiff() bool { return c.c.Bool("suppress-diff") } diff --git a/pkg/app/app_test.go b/pkg/app/app_test.go index 0c2713fd..db975c8a 100644 --- a/pkg/app/app_test.go +++ b/pkg/app/app_test.go @@ -2345,6 +2345,7 @@ type applyConfig struct { suppress []string suppressSecrets bool showSecrets bool + noHooks bool suppressDiff bool noColor bool context int @@ -2422,6 +2423,10 @@ func (a applyConfig) ShowSecrets() bool { return a.showSecrets } +func (a applyConfig) NoHooks() bool { + return a.noHooks +} + func (a applyConfig) SuppressDiff() bool { return a.suppressDiff } diff --git a/pkg/app/config.go b/pkg/app/config.go index e39281fb..a8f6e514 100644 --- a/pkg/app/config.go +++ b/pkg/app/config.go @@ -52,6 +52,7 @@ type ApplyConfigProvider interface { Suppress() []string SuppressSecrets() bool ShowSecrets() bool + NoHooks() bool SuppressDiff() bool DetailedExitcode() bool @@ -106,6 +107,7 @@ type DiffConfigProvider interface { Suppress() []string SuppressSecrets() bool ShowSecrets() bool + NoHooks() bool SuppressDiff() bool SkipDiffOnInstall() bool diff --git a/pkg/app/diff_test.go b/pkg/app/diff_test.go index af801a97..a63a86f5 100644 --- a/pkg/app/diff_test.go +++ b/pkg/app/diff_test.go @@ -30,6 +30,7 @@ type diffConfig struct { suppress []string suppressSecrets bool showSecrets bool + noHooks bool suppressDiff bool noColor bool context int @@ -89,6 +90,10 @@ func (a diffConfig) ShowSecrets() bool { return a.showSecrets } +func (a diffConfig) NoHooks() bool { + return a.noHooks +} + func (a diffConfig) SuppressDiff() bool { return a.suppressDiff } diff --git a/pkg/app/run.go b/pkg/app/run.go index ed680138..e1fc4e9c 100644 --- a/pkg/app/run.go +++ b/pkg/app/run.go @@ -127,7 +127,7 @@ func (r *Run) diff(triggerCleanupEvent bool, detailedExitCode bool, c DiffConfig // TODO Better way to detect diff on only filtered releases { - changedReleases, planningErrs = st.DiffReleases(helm, c.Values(), c.Concurrency(), detailedExitCode, c.IncludeTests(), c.Suppress(), c.SuppressSecrets(), c.ShowSecrets(), c.SuppressDiff(), triggerCleanupEvent, diffOpts) + changedReleases, planningErrs = st.DiffReleases(helm, c.Values(), c.Concurrency(), detailedExitCode, c.IncludeTests(), c.Suppress(), c.SuppressSecrets(), c.ShowSecrets(), c.NoHooks(), c.SuppressDiff(), triggerCleanupEvent, diffOpts) var err error deletingReleases, err = st.DetectReleasesToBeDeletedForSync(helm, st.Releases) diff --git a/pkg/state/state.go b/pkg/state/state.go index fae56776..f1f3ab70 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -1604,7 +1604,7 @@ type diffPrepareResult struct { upgradeDueToSkippedDiff bool } -func (st *HelmState) prepareDiffReleases(helm helmexec.Interface, additionalValues []string, concurrency int, detailedExitCode bool, includeTests bool, suppress []string, suppressSecrets bool, showSecrets bool, opt ...DiffOpt) ([]diffPrepareResult, []error) { +func (st *HelmState) prepareDiffReleases(helm helmexec.Interface, additionalValues []string, concurrency int, detailedExitCode bool, includeTests bool, suppress []string, suppressSecrets bool, showSecrets bool, noHooks bool, opt ...DiffOpt) ([]diffPrepareResult, []error) { opts := &DiffOpts{} for _, o := range opt { o.Apply(opts) @@ -1717,6 +1717,10 @@ func (st *HelmState) prepareDiffReleases(helm helmexec.Interface, additionalValu flags = append(flags, "--show-secrets") } + if noHooks { + flags = append(flags, "--no-hooks") + } + if opts.NoColor { flags = append(flags, "--no-color") } @@ -1825,13 +1829,13 @@ type DiffOpt interface{ Apply(*DiffOpts) } // For example, terraform-provider-helmfile runs a helmfile-diff on `terraform plan` and another on `terraform apply`. // `terraform`, by design, fails when helmfile-diff outputs were not equivalent. // Stabilized helmfile-diff output rescues that. -func (st *HelmState) DiffReleases(helm helmexec.Interface, additionalValues []string, workerLimit int, detailedExitCode bool, includeTests bool, suppress []string, suppressSecrets, showSecrets, suppressDiff, triggerCleanupEvents bool, opt ...DiffOpt) ([]ReleaseSpec, []error) { +func (st *HelmState) DiffReleases(helm helmexec.Interface, additionalValues []string, workerLimit int, detailedExitCode bool, includeTests bool, suppress []string, suppressSecrets, showSecrets, noHooks bool, suppressDiff, triggerCleanupEvents bool, opt ...DiffOpt) ([]ReleaseSpec, []error) { opts := &DiffOpts{} for _, o := range opt { o.Apply(opts) } - preps, prepErrs := st.prepareDiffReleases(helm, additionalValues, workerLimit, detailedExitCode, includeTests, suppress, suppressSecrets, showSecrets, opts) + preps, prepErrs := st.prepareDiffReleases(helm, additionalValues, workerLimit, detailedExitCode, includeTests, suppress, suppressSecrets, showSecrets, noHooks, opts) if !opts.SkipCleanup { defer func() { diff --git a/pkg/state/state_test.go b/pkg/state/state_test.go index e35d6fc0..3c34e08d 100644 --- a/pkg/state/state_test.go +++ b/pkg/state/state_test.go @@ -1604,7 +1604,7 @@ func TestHelmState_DiffReleases(t *testing.T) { valsRuntime: valsRuntime, RenderedValues: map[string]interface{}{}, } - _, errs := state.DiffReleases(tt.helm, []string{}, 1, false, false, []string{}, false, false, false, false) + _, errs := state.DiffReleases(tt.helm, []string{}, 1, false, false, []string{}, false, false, false, false, false) if len(errs) > 0 { t.Errorf("unexpected error: %v", errs) } @@ -1775,7 +1775,7 @@ func TestHelmState_DiffReleasesCleanup(t *testing.T) { `, }) state = injectFs(state, testfs) - if _, errs := state.DiffReleases(tt.helm, []string{}, 1, false, false, []string{}, false, false, false, false); len(errs) > 0 { + if _, errs := state.DiffReleases(tt.helm, []string{}, 1, false, false, []string{}, false, false, false, false, false); len(errs) > 0 { t.Errorf("unexpected errors: %v", errs) }