Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added option for --no-hooks for helm diff and apply #2155

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 12 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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")
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2345,6 +2345,7 @@ type applyConfig struct {
suppress []string
suppressSecrets bool
showSecrets bool
noHooks bool
suppressDiff bool
noColor bool
context int
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type ApplyConfigProvider interface {
Suppress() []string
SuppressSecrets() bool
ShowSecrets() bool
NoHooks() bool
SuppressDiff() bool

DetailedExitcode() bool
Expand Down Expand Up @@ -106,6 +107,7 @@ type DiffConfigProvider interface {
Suppress() []string
SuppressSecrets() bool
ShowSecrets() bool
NoHooks() bool
SuppressDiff() bool
SkipDiffOnInstall() bool

Expand Down
5 changes: 5 additions & 0 deletions pkg/app/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type diffConfig struct {
suppress []string
suppressSecrets bool
showSecrets bool
noHooks bool
suppressDiff bool
noColor bool
context int
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions pkg/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions pkg/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}

Expand Down