diff --git a/cmd/apply.go b/cmd/apply.go index 1f5b73b8..e5cbbca0 100644 --- a/cmd/apply.go +++ b/cmd/apply.go @@ -41,6 +41,7 @@ func NewApplyCmd(globalCfg *config.GlobalImpl) *cobra.Command { f.StringVar(&applyOptions.Output, "output", "", "output format for diff plugin") f.BoolVar(&applyOptions.DetailedExitcode, "detailed-exitcode", false, "return a non-zero exit code 2 instead of 0 when there were changes detected AND the changes are synced successfully") f.BoolVar(&applyOptions.StripTrailingCR, "strip-trailing-cr", false, "strip trailing carriage return on input") + f.StringVar(&applyOptions.DiffArgs, "diff-args", "", `pass args to helm helm-diff`) f.StringVar(&globalCfg.GlobalOptions.Args, "args", "", "pass args to helm exec") if !runtime.V1Mode { // TODO: Remove this function once Helmfile v0.x diff --git a/cmd/diff.go b/cmd/diff.go index c269d94b..d6efab94 100644 --- a/cmd/diff.go +++ b/cmd/diff.go @@ -31,6 +31,7 @@ func NewDiffCmd(globalCfg *config.GlobalImpl) *cobra.Command { } f := cmd.Flags() + f.StringVar(&diffOptions.DiffArgs, "diff-args", "", `pass args to helm helm-diff`) f.StringVar(&globalCfg.GlobalOptions.Args, "args", "", "pass args to helm diff") f.StringArrayVar(&diffOptions.Set, "set", nil, "additional values to be merged into the helm command --set flag") f.StringArrayVar(&diffOptions.Values, "values", nil, "additional value files to be merged into the helm command --values flag") diff --git a/pkg/app/app.go b/pkg/app/app.go index 93e28926..c529926c 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -1369,11 +1369,17 @@ func (a *App) apply(r *Run, c ApplyConfigProvider) (bool, bool, []error) { PostRenderer: c.PostRenderer(), } + // join --args and --diff-args together to one string. + args := strings.Join([]string{c.Args(), c.DiffArgs()}, " ") + helm.SetExtraArgs(argparser.GetArgs(args, r.state)...) + infoMsg, releasesToBeUpdated, releasesToBeDeleted, errs := r.diff(false, detailedExitCode, c, diffOpts) if len(errs) > 0 { return false, false, errs } + helm.SetExtraArgs() + var toDelete []state.ReleaseSpec for _, r := range releasesToBeDeleted { toDelete = append(toDelete, r) @@ -1586,7 +1592,8 @@ func (a *App) diff(r *Run, c DiffConfigProvider) (*string, bool, bool, []error) ok, errs := a.withNeeds(r, c, true, func(st *state.HelmState) []error { helm := r.helm - helm.SetExtraArgs(argparser.GetArgs(c.Args(), r.state)...) + args := strings.Join([]string{c.Args(), c.DiffArgs()}, " ") + helm.SetExtraArgs(argparser.GetArgs(args, r.state)...) var errs []error @@ -1610,6 +1617,7 @@ func (a *App) diff(r *Run, c DiffConfigProvider) (*string, bool, bool, []error) } infoMsg, updated, deleted, errs = filtered.diff(true, c.DetailedExitcode(), c, opts) + helm.SetExtraArgs(argparser.GetArgs(c.Args(), r.state)...) return errs }) diff --git a/pkg/app/app_test.go b/pkg/app/app_test.go index d0e02481..d0e5746c 100644 --- a/pkg/app/app_test.go +++ b/pkg/app/app_test.go @@ -2215,6 +2215,7 @@ type applyConfig struct { stripTrailingCR bool interactive bool skipDiffOnInstall bool + diffArgs string logger *zap.SugaredLogger wait bool waitForJobs bool @@ -2348,6 +2349,10 @@ func (a applyConfig) SkipDiffOnInstall() bool { return a.skipDiffOnInstall } +func (a applyConfig) DiffArgs() string { + return a.diffArgs +} + // helmfile-template-only flags func (a applyConfig) IncludeCRDs() bool { diff --git a/pkg/app/config.go b/pkg/app/config.go index 5205275e..712ab130 100644 --- a/pkg/app/config.go +++ b/pkg/app/config.go @@ -79,6 +79,8 @@ type ApplyConfigProvider interface { SkipCleanup() bool SkipDiffOnInstall() bool + DiffArgs() string + DAGConfig concurrencyConfig @@ -130,6 +132,7 @@ type DiffConfigProvider interface { NoHooks() bool SuppressDiff() bool SkipDiffOnInstall() bool + DiffArgs() string DAGConfig diff --git a/pkg/app/diff_test.go b/pkg/app/diff_test.go index b2b5d739..11d7a766 100644 --- a/pkg/app/diff_test.go +++ b/pkg/app/diff_test.go @@ -16,6 +16,7 @@ import ( type diffConfig struct { args string + diffArgs string values []string retainValuesFiles bool set []string @@ -47,6 +48,10 @@ func (a diffConfig) Args() string { return a.args } +func (a diffConfig) DiffArgs() string { + return a.diffArgs +} + func (a diffConfig) Values() []string { return a.values } diff --git a/pkg/config/apply.go b/pkg/config/apply.go index 8b2d93b4..f4dcabf3 100644 --- a/pkg/config/apply.go +++ b/pkg/config/apply.go @@ -34,6 +34,8 @@ type ApplyOptions struct { IncludeTransitiveNeeds bool // SkipDiffOnInstall is true if the diff should be skipped on install SkipDiffOnInstall bool + // DiffArgs is the list of arguments to pass to the helm-diff. + DiffArgs string // IncludeTests is true if the tests should be included IncludeTests bool // Suppress is true if the output should be suppressed @@ -155,6 +157,11 @@ func (a *ApplyImpl) SkipDiffOnInstall() bool { return a.ApplyOptions.SkipDiffOnInstall } +// DiffArgs is the list of arguments to pass to helm-diff. +func (a *ApplyImpl) DiffArgs() string { + return a.ApplyOptions.DiffArgs +} + // SkipNeeds returns the skip needs. func (a *ApplyImpl) SkipNeeds() bool { if !a.IncludeNeeds() { diff --git a/pkg/config/diff.go b/pkg/config/diff.go index 4c118798..5212c8a9 100644 --- a/pkg/config/diff.go +++ b/pkg/config/diff.go @@ -42,6 +42,8 @@ type DiffOptions struct { ResetValues bool // Propagate '--post-renderer' to helmv3 template and helm install PostRenderer string + // DiffArgs is the list of arguments to pass to helm-diff. + DiffArgs string } // NewDiffOptions creates a new Apply @@ -147,6 +149,11 @@ func (t *DiffImpl) SkipDiffOnInstall() bool { return t.DiffOptions.SkipDiffOnInstall } +// DiffArgs returns the list of arguments to pass to helm-diff. +func (t *DiffImpl) DiffArgs() string { + return t.DiffOptions.DiffArgs +} + // Suppress returns the suppress func (t *DiffImpl) Suppress() []string { return t.DiffOptions.Suppress diff --git a/pkg/state/state.go b/pkg/state/state.go index 7a6368d6..13344b08 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -1910,6 +1910,7 @@ type DiffOpts struct { Set []string SkipCleanup bool SkipDiffOnInstall bool + DiffArgs string ReuseValues bool ResetValues bool PostRenderer string