From f8a297bbaccf9c9e9b1224c0810144c3f40b64dd Mon Sep 17 00:00:00 2001 From: yxxhero Date: Tue, 25 Oct 2022 08:24:23 +0800 Subject: [PATCH] fix --debug flag Signed-off-by: yxxhero --- cmd/apply.go | 2 +- cmd/charts.go | 2 +- cmd/delete.go | 2 +- cmd/deps.go | 2 +- cmd/destroy.go | 2 +- cmd/diff.go | 2 +- cmd/lint.go | 2 +- cmd/repos.go | 2 +- cmd/status.go | 2 +- cmd/sync.go | 2 +- cmd/template.go | 2 +- cmd/test.go | 2 +- pkg/config/apply.go | 16 ---------------- pkg/config/build.go | 5 ----- pkg/config/cache.go | 5 ----- pkg/config/charts.go | 7 ------- pkg/config/delete.go | 7 ------- pkg/config/deps.go | 7 ------- pkg/config/destroy.go | 7 ------- pkg/config/diff.go | 7 ------- pkg/config/fetch.go | 5 ----- pkg/config/global.go | 15 +++++++++++++++ pkg/config/lint.go | 7 ------- pkg/config/list.go | 5 ----- pkg/config/repos.go | 10 +--------- pkg/config/status.go | 7 ------- pkg/config/sync.go | 7 ------- pkg/config/template.go | 7 ------- pkg/config/test.go | 7 ------- pkg/config/write-values.go | 5 ----- 30 files changed, 28 insertions(+), 132 deletions(-) diff --git a/cmd/apply.go b/cmd/apply.go index 98fa28e2..862a0377 100644 --- a/cmd/apply.go +++ b/cmd/apply.go @@ -39,7 +39,7 @@ func NewApplyCmd(globalCfg *config.GlobalImpl) *cobra.Command { f.IntVar(&applyOptions.Context, "context", 0, "output NUM lines of context around changes") 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.StringVar(&applyOptions.Args, "args", "", "pass args to helm exec") + f.StringVar(&globalCfg.GlobalOptions.Args, "args", "", "pass args to helm exec") f.BoolVar(&applyOptions.RetainValuesFiles, "retain-values-files", false, "DEPRECATED: Use skip-cleanup instead") // mark retain-values-files as deprecated, but keep it for backward compatibility, will be removed in the future _ = f.MarkDeprecated("retain-values-files", "Use skip-cleanup instead") diff --git a/cmd/charts.go b/cmd/charts.go index 094354ac..44c92207 100644 --- a/cmd/charts.go +++ b/cmd/charts.go @@ -31,7 +31,7 @@ func NewChartsCmd(globalCfg *config.GlobalImpl) *cobra.Command { } f := cmd.Flags() - f.StringVar(&chartsOptions.Args, "args", "", "pass args to helm exec") + f.StringVar(&globalCfg.GlobalOptions.Args, "args", "", "pass args to helm exec") f.StringArrayVar(&chartsOptions.Set, "set", nil, "additional values to be merged into the command") f.StringArrayVar(&chartsOptions.Values, "values", nil, "additional value files to be merged into the command") f.IntVar(&chartsOptions.Concurrency, "concurrency", 0, "maximum number of concurrent helm processes to run, 0 is unlimited") diff --git a/cmd/delete.go b/cmd/delete.go index 3044c394..1329bcaa 100644 --- a/cmd/delete.go +++ b/cmd/delete.go @@ -31,7 +31,7 @@ func NewDeleteCmd(globalCfg *config.GlobalImpl) *cobra.Command { } f := cmd.Flags() - f.StringVar(&deleteOptions.Args, "args", "", "pass args to helm exec") + f.StringVar(&globalCfg.GlobalOptions.Args, "args", "", "pass args to helm exec") f.IntVar(&deleteOptions.Concurrency, "concurrency", 0, "maximum number of concurrent helm processes to run, 0 is unlimited") f.BoolVar(&deleteOptions.Purge, "purge", false, "purge releases i.e. free release names and histories") f.BoolVar(&deleteOptions.SkipDeps, "skip-deps", false, `skip running "helm repo update" and "helm dependency build"`) diff --git a/cmd/deps.go b/cmd/deps.go index b34524b9..0a84e26b 100644 --- a/cmd/deps.go +++ b/cmd/deps.go @@ -31,7 +31,7 @@ func NewDepsCmd(globalCfg *config.GlobalImpl) *cobra.Command { } f := cmd.Flags() - f.StringVar(&depsOptions.Args, "args", "", "pass args to helm exec") + f.StringVar(&globalCfg.GlobalOptions.Args, "args", "", "pass args to helm exec") f.BoolVar(&depsOptions.SkipRepos, "skip-repos", false, `skip running "helm repo update" and "helm dependency build"`) f.IntVar(&depsOptions.Concurrency, "concurrency", 0, "maximum number of concurrent helm processes to run, 0 is unlimited") diff --git a/cmd/destroy.go b/cmd/destroy.go index c78789ef..8492e608 100644 --- a/cmd/destroy.go +++ b/cmd/destroy.go @@ -31,7 +31,7 @@ func NewDestroyCmd(globalCfg *config.GlobalImpl) *cobra.Command { } f := cmd.Flags() - f.StringVar(&destroyOptions.Args, "args", "", "pass args to helm exec") + f.StringVar(&globalCfg.GlobalOptions.Args, "args", "", "pass args to helm exec") f.IntVar(&destroyOptions.Concurrency, "concurrency", 0, "maximum number of concurrent helm processes to run, 0 is unlimited") f.BoolVar(&destroyOptions.SkipDeps, "skip-deps", false, `skip running "helm repo update" and "helm dependency build"`) diff --git a/cmd/diff.go b/cmd/diff.go index 99a4d155..18ac5a18 100644 --- a/cmd/diff.go +++ b/cmd/diff.go @@ -31,7 +31,7 @@ func NewDiffCmd(globalCfg *config.GlobalImpl) *cobra.Command { } f := cmd.Flags() - f.StringVar(&diffOptions.Args, "args", "", "pass args to 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 command") f.StringArrayVar(&diffOptions.Values, "values", nil, "additional value files to be merged into the command") f.IntVar(&diffOptions.Concurrency, "concurrency", 0, "maximum number of concurrent helm processes to run, 0 is unlimited") diff --git a/cmd/lint.go b/cmd/lint.go index 2e01d314..d928adfd 100644 --- a/cmd/lint.go +++ b/cmd/lint.go @@ -33,7 +33,7 @@ func NewLintCmd(globalCfg *config.GlobalImpl) *cobra.Command { f := cmd.Flags() f.IntVar(&lintOptions.Concurrency, "concurrency", 0, "maximum number of concurrent helm processes to run, 0 is unlimited") f.BoolVar(&lintOptions.SkipDeps, "skip-deps", false, `skip running "helm repo update" and "helm dependency build"`) - f.StringVar(&lintOptions.Args, "args", "", "pass args to helm exec") + f.StringVar(&globalCfg.GlobalOptions.Args, "args", "", "pass args to helm exec") f.StringArrayVar(&lintOptions.Set, "set", nil, "additional values to be merged into the command") f.StringArrayVar(&lintOptions.Values, "values", nil, "additional value files to be merged into the command") f.BoolVar(&lintOptions.SkipNeeds, "skip-needs", true, `do not automatically include releases from the target release's "needs" when --selector/-l flag is provided. Does nothing when --selector/-l flag is not provided. Defaults to true when --include-needs or --include-transitive-needs is not provided`) diff --git a/cmd/repos.go b/cmd/repos.go index e3ef221a..9ff2ba61 100644 --- a/cmd/repos.go +++ b/cmd/repos.go @@ -31,7 +31,7 @@ func NewReposCmd(globalCfg *config.GlobalImpl) *cobra.Command { } f := cmd.Flags() - f.StringVar(&reposOptions.Args, "args", "", "pass args to helm exec") + f.StringVar(&globalCfg.GlobalOptions.Args, "args", "", "pass args to helm exec") return cmd } diff --git a/cmd/status.go b/cmd/status.go index 3f8e332f..37254e02 100644 --- a/cmd/status.go +++ b/cmd/status.go @@ -31,7 +31,7 @@ func NewStatusCmd(globalCfg *config.GlobalImpl) *cobra.Command { } f := cmd.Flags() - f.StringVar(&statusOptions.Args, "args", "", "pass args to helm exec") + f.StringVar(&globalCfg.GlobalOptions.Args, "args", "", "pass args to helm exec") f.IntVar(&statusOptions.Concurrency, "concurrency", 0, "maximum number of concurrent helm processes to run, 0 is unlimited") return cmd diff --git a/cmd/sync.go b/cmd/sync.go index 2dab8476..de0632aa 100644 --- a/cmd/sync.go +++ b/cmd/sync.go @@ -31,7 +31,7 @@ func NewSyncCmd(globalCfg *config.GlobalImpl) *cobra.Command { } f := cmd.Flags() - f.StringVar(&syncOptions.Args, "args", "", "pass args to helm sync") + f.StringVar(&globalCfg.GlobalOptions.Args, "args", "", "pass args to helm sync") f.StringArrayVar(&syncOptions.Set, "set", nil, "additional values to be merged into the command") f.StringArrayVar(&syncOptions.Values, "values", nil, "additional value files to be merged into the command") f.IntVar(&syncOptions.Concurrency, "concurrency", 0, "maximum number of concurrent helm processes to run, 0 is unlimited") diff --git a/cmd/template.go b/cmd/template.go index 31693f11..35193f94 100644 --- a/cmd/template.go +++ b/cmd/template.go @@ -31,7 +31,7 @@ func NewTemplateCmd(globalCfg *config.GlobalImpl) *cobra.Command { } f := cmd.Flags() - f.StringVar(&templateOptions.Args, "args", "", "pass args to helm template") + f.StringVar(&globalCfg.GlobalOptions.Args, "args", "", "pass args to helm template") f.StringArrayVar(&templateOptions.Set, "set", nil, "additional values to be merged into the command") f.StringArrayVar(&templateOptions.Values, "values", nil, "additional value files to be merged into the command") f.StringVar(&templateOptions.OutputDir, "output-dir", "", "output directory to pass to helm template (helm template --output-dir)") diff --git a/cmd/test.go b/cmd/test.go index 0f6d06e5..a3188e23 100644 --- a/cmd/test.go +++ b/cmd/test.go @@ -36,7 +36,7 @@ func NewTestCmd(globalCfg *config.GlobalImpl) *cobra.Command { f.BoolVar(&testOptions.SkipDeps, "skip-deps", false, `skip running "helm repo update" and "helm dependency build"`) f.BoolVar(&testOptions.Cleanup, "cleanup", false, "delete test pods upon completion") f.BoolVar(&testOptions.Logs, "logs", false, "Dump the logs from test pods (this runs after all tests are complete, but before any cleanup)") - f.StringVar(&testOptions.Args, "args", "", "pass args to helm exec") + f.StringVar(&globalCfg.GlobalOptions.Args, "args", "", "pass args to helm exec") f.IntVar(&testOptions.Timeout, "timeout", 300, "maximum time for tests to run before being considered failed") return cmd diff --git a/pkg/config/apply.go b/pkg/config/apply.go index 2f6fc3da..c3e0559f 100644 --- a/pkg/config/apply.go +++ b/pkg/config/apply.go @@ -1,7 +1,5 @@ package config -import "fmt" - // ApplyOptoons is the options for the apply command type ApplyOptions struct { // Set is a list of key value pairs to be merged into the command @@ -18,8 +16,6 @@ type ApplyOptions struct { Output string // DetailedExitcode is true if the exit code should be 2 instead of 0 if there were changes detected and the changes were synced successfully DetailedExitcode bool - // Args is the arguments to pass to helm exec - Args string // DEPRECATED: Use skip-cleanup instead RetainValuesFiles bool // SkipCleanup is true if the cleanup of temporary values files should be skipped @@ -80,18 +76,6 @@ func (a *ApplyImpl) Set() []string { return a.ApplyOptions.Set } -// Args returns the args. -func (a *ApplyImpl) Args() string { - args := a.ApplyOptions.Args - enableHelmDebug := a.GlobalImpl.Debug - - if enableHelmDebug { - args = fmt.Sprintf("%s %s", args, "--debug") - } - - return args -} - // Concurrency returns the concurrency. func (a *ApplyImpl) Concurrency() int { return a.ApplyOptions.Concurrency diff --git a/pkg/config/build.go b/pkg/config/build.go index 6c3562cc..26bb6bea 100644 --- a/pkg/config/build.go +++ b/pkg/config/build.go @@ -25,11 +25,6 @@ func NewBuildImpl(g *GlobalImpl, b *BuildOptions) *BuildImpl { } } -// Args returns the args. -func (b *BuildImpl) Args() string { - return "" -} - // EmbedValues returns the embed values. func (b *BuildImpl) EmbedValues() bool { return b.BuildOptions.EmbedValues diff --git a/pkg/config/cache.go b/pkg/config/cache.go index bf9b68fa..b4e4010a 100644 --- a/pkg/config/cache.go +++ b/pkg/config/cache.go @@ -21,8 +21,3 @@ func NewCacheImpl(g *GlobalImpl, b *CacheOptions) *CacheImpl { CacheOptions: b, } } - -// Args returns the args. -func (b *CacheImpl) Args() string { - return "" -} diff --git a/pkg/config/charts.go b/pkg/config/charts.go index e615b1c2..00650beb 100644 --- a/pkg/config/charts.go +++ b/pkg/config/charts.go @@ -2,8 +2,6 @@ package config // ChartsOptions is the options for the build command type ChartsOptions struct { - // Args is the args to pass to helm exec - Args string // Set is the additional values to be merged into the command Set []string // Values is the additional value files to be merged into the command @@ -36,11 +34,6 @@ func (c *ChartsImpl) Concurrency() int { return c.ChartsOptions.Concurrency } -// Args returns the args -func (c *ChartsImpl) Args() string { - return c.ChartsOptions.Args -} - // IncludeTransitiveNeeds returns the includeTransitiveNeeds func (c *ChartsImpl) IncludeTransitiveNeeds() bool { return false diff --git a/pkg/config/delete.go b/pkg/config/delete.go index 3778512f..5ef3be47 100644 --- a/pkg/config/delete.go +++ b/pkg/config/delete.go @@ -2,8 +2,6 @@ package config // DeleteOptions is the options for the build command type DeleteOptions struct { - // Args is the args to pass to helm exec - Args string // Concurrency is the maximum number of concurrent helm processes to run, 0 is unlimited Concurrency int // Purge is the purge flag @@ -36,11 +34,6 @@ func (c *DeleteImpl) Concurrency() int { return c.DeleteOptions.Concurrency } -// Args returns the args -func (c *DeleteImpl) Args() string { - return c.DeleteOptions.Args -} - // Purge returns the purge func (c *DeleteImpl) Purge() bool { return c.DeleteOptions.Purge diff --git a/pkg/config/deps.go b/pkg/config/deps.go index 5d99c9a7..f4dd4608 100644 --- a/pkg/config/deps.go +++ b/pkg/config/deps.go @@ -2,8 +2,6 @@ package config // DepsOptions is the options for the build command type DepsOptions struct { - // Args is the args to pass to helm exec - Args string // SkipRepos is the skip repos flag SkipRepos bool // Concurrency is the maximum number of concurrent helm processes to run @@ -29,11 +27,6 @@ func NewDepsImpl(g *GlobalImpl, b *DepsOptions) *DepsImpl { } } -// Args returns the args -func (d *DepsImpl) Args() string { - return d.DepsOptions.Args -} - // SkipRepos returns the skip deps func (d *DepsImpl) SkipRepos() bool { return d.DepsOptions.SkipRepos diff --git a/pkg/config/destroy.go b/pkg/config/destroy.go index 5cfbaf26..e4878ed8 100644 --- a/pkg/config/destroy.go +++ b/pkg/config/destroy.go @@ -2,8 +2,6 @@ package config // DestroyOptions is the options for the build command type DestroyOptions struct { - // Args is the args to pass to helm exec - Args string // Concurrency is the maximum number of concurrent helm processes to run, 0 is unlimited Concurrency int // SkipDeps is the skip deps flag @@ -34,11 +32,6 @@ func (c *DestroyImpl) Concurrency() int { return c.DestroyOptions.Concurrency } -// Args returns the args -func (c *DestroyImpl) Args() string { - return c.DestroyOptions.Args -} - // SkipDeps returns the skip deps func (c *DestroyImpl) SkipDeps() bool { return c.DestroyOptions.SkipDeps diff --git a/pkg/config/diff.go b/pkg/config/diff.go index b84909ca..24cc77f5 100644 --- a/pkg/config/diff.go +++ b/pkg/config/diff.go @@ -2,8 +2,6 @@ package config // DiffOptions is the options for the build command type DiffOptions struct { - // Args is the args to pass to helm template - Args string // Set is the set flag Set []string // Values is the values flag @@ -61,11 +59,6 @@ func NewDiffImpl(g *GlobalImpl, t *DiffOptions) *DiffImpl { } } -// Args returns the args -func (t *DiffImpl) Args() string { - return t.DiffOptions.Args -} - // Concurrency returns the concurrency func (t *DiffImpl) Concurrency() int { return t.DiffOptions.Concurrency diff --git a/pkg/config/fetch.go b/pkg/config/fetch.go index 1b2d9ccb..30483b70 100644 --- a/pkg/config/fetch.go +++ b/pkg/config/fetch.go @@ -39,11 +39,6 @@ func (c *FetchImpl) SkipDeps() bool { return c.FetchOptions.SkipDeps } -// Args returns the args -func (c *FetchImpl) Args() string { - return "" -} - // OutputDir returns the args func (c *FetchImpl) OutputDir() string { return c.FetchOptions.OutputDir diff --git a/pkg/config/global.go b/pkg/config/global.go index 174db85b..94a897dd 100644 --- a/pkg/config/global.go +++ b/pkg/config/global.go @@ -2,6 +2,7 @@ package config import ( "errors" + "fmt" "os" "go.uber.org/zap" @@ -48,6 +49,8 @@ type GlobalOptions struct { EnableLiveOutput bool // Interactive is true if the user should be prompted for input. Interactive bool + // Args is the list of arguments to pass to the Helm binary. + Args string } // Logger returns the logger to use. @@ -186,3 +189,15 @@ func (g *GlobalImpl) ValidateConfig() error { func (g *GlobalImpl) Interactive() bool { return g.GlobalOptions.Interactive } + +// Args returns the args to use for helm +func (g *GlobalImpl) Args() string { + args := g.GlobalOptions.Args + enableHelmDebug := g.GlobalOptions.Debug + + if enableHelmDebug { + args = fmt.Sprintf("%s %s", args, "--debug") + } + + return args +} diff --git a/pkg/config/lint.go b/pkg/config/lint.go index 45ea0973..7123ded4 100644 --- a/pkg/config/lint.go +++ b/pkg/config/lint.go @@ -6,8 +6,6 @@ type LintOptions struct { Concurrency int // SkipDeps is the skip deps flag SkipDeps bool - // Args is the args to pass to helm lint - Args string // Set is the set flags to pass to helm lint Set []string // Values is the values flags to pass to helm lint @@ -50,11 +48,6 @@ func (l *LintImpl) SkipDeps() bool { return l.LintOptions.SkipDeps } -// Args returns the args -func (l *LintImpl) Args() string { - return l.LintOptions.Args -} - // Set returns the Set func (l *LintImpl) Set() []string { return l.LintOptions.Set diff --git a/pkg/config/list.go b/pkg/config/list.go index b4e76f8a..0410a5ac 100644 --- a/pkg/config/list.go +++ b/pkg/config/list.go @@ -29,11 +29,6 @@ func NewListImpl(g *GlobalImpl, b *ListOptions) *ListImpl { } } -// Args returns the args -func (c *ListImpl) Args() string { - return "" -} - // Output returns the output func (c *ListImpl) Output() string { return c.ListOptions.Output diff --git a/pkg/config/repos.go b/pkg/config/repos.go index 78838db1..090b8cdf 100644 --- a/pkg/config/repos.go +++ b/pkg/config/repos.go @@ -1,10 +1,7 @@ package config // ReposOptions is the options for the build command -type ReposOptions struct { - // Args is the args - Args string -} +type ReposOptions struct{} // NewReposOptions creates a new Apply func NewReposOptions() *ReposOptions { @@ -25,11 +22,6 @@ func NewReposImpl(g *GlobalImpl, b *ReposOptions) *ReposImpl { } } -// Args returns the args -func (r *ReposImpl) Args() string { - return r.ReposOptions.Args -} - // IncludeTransitiveNeeds returns the include transitive needs func (r *ReposImpl) IncludeTransitiveNeeds() bool { return false diff --git a/pkg/config/status.go b/pkg/config/status.go index 63afadd3..d7b5b772 100644 --- a/pkg/config/status.go +++ b/pkg/config/status.go @@ -2,8 +2,6 @@ package config // StatusOptions is the options for the build command type StatusOptions struct { - // Args is the args - Args string // Concurrency is the concurrent flag Concurrency int } @@ -27,11 +25,6 @@ func NewStatusImpl(g *GlobalImpl, b *StatusOptions) *StatusImpl { } } -// Args returns the args -func (s *StatusImpl) Args() string { - return s.StatusOptions.Args -} - // IncludeTransitiveNeeds returns the include transitive needs func (s *StatusImpl) IncludeTransitiveNeeds() bool { return false diff --git a/pkg/config/sync.go b/pkg/config/sync.go index b849442e..14a3f4f9 100644 --- a/pkg/config/sync.go +++ b/pkg/config/sync.go @@ -2,8 +2,6 @@ package config // SyncOptions is the options for the build command type SyncOptions struct { - // Args is the args to pass to helm template - Args string // Set is the set flag Set []string // Values is the values flag @@ -49,11 +47,6 @@ func NewSyncImpl(g *GlobalImpl, t *SyncOptions) *SyncImpl { } } -// Args returns the args -func (t *SyncImpl) Args() string { - return t.SyncOptions.Args -} - // Concurrency returns the concurrency func (t *SyncImpl) Concurrency() int { return t.SyncOptions.Concurrency diff --git a/pkg/config/template.go b/pkg/config/template.go index 5810a86b..1e61cdef 100644 --- a/pkg/config/template.go +++ b/pkg/config/template.go @@ -8,8 +8,6 @@ import ( // TemplateOptions is the options for the build command type TemplateOptions struct { - // Args is the args to pass to helm template - Args string // Set is the set flag Set []string // Values is the values flag @@ -57,11 +55,6 @@ func NewTemplateImpl(g *GlobalImpl, t *TemplateOptions) *TemplateImpl { } } -// Args returns the args -func (t *TemplateImpl) Args() string { - return t.TemplateOptions.Args -} - // Concurrency returns the concurrency func (t *TemplateImpl) Concurrency() int { return t.TemplateOptions.Concurrency diff --git a/pkg/config/test.go b/pkg/config/test.go index f856bbaf..e2e205cd 100644 --- a/pkg/config/test.go +++ b/pkg/config/test.go @@ -12,8 +12,6 @@ type TestOptions struct { Concurrency int // SkipDeps is the skip deps flag SkipDeps bool - // Args is the args to pass to helm lint - Args string // Cleanup is the cleanup flag Cleanup bool // Logs is the logs flagj @@ -52,11 +50,6 @@ func (t *TestImpl) SkipDeps() bool { return t.TestOptions.SkipDeps } -// Args returns the args -func (t *TestImpl) Args() string { - return t.TestOptions.Args -} - // Cleanup returns the cleanup func (t *TestImpl) Cleanup() bool { return t.TestOptions.Cleanup diff --git a/pkg/config/write-values.go b/pkg/config/write-values.go index 3539b782..92e2b691 100644 --- a/pkg/config/write-values.go +++ b/pkg/config/write-values.go @@ -67,8 +67,3 @@ func (c *WriteValuesImpl) IncludeTransitiveNeeds() bool { func (c *WriteValuesImpl) OutputFileTemplate() string { return c.WriteValuesOptions.OutputFileTemplate } - -// Args returns the args -func (c *WriteValuesImpl) Args() string { - return "" -}