From bd3838c059ba9cea5e6356a4973dd138d0d32dcd Mon Sep 17 00:00:00 2001 From: Jason Witkowski Date: Tue, 23 Feb 2021 22:47:27 -0500 Subject: [PATCH] Add ability to specify and override helmDefaults.wait via cli (#1678) --- main.go | 12 ++++++++++++ pkg/app/app.go | 6 +++++- pkg/app/app_test.go | 5 +++++ pkg/app/config.go | 2 ++ pkg/state/state.go | 6 ++++++ 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 7e04e0ce..a978b89d 100644 --- a/main.go +++ b/main.go @@ -353,6 +353,10 @@ func main() { Name: "skip-deps", Usage: `skip running "helm repo update" and "helm dependency build"`, }, + cli.BoolFlag{ + Name: "wait", + Usage: `Override helmDefaults.wait setting "helm upgrade --install --wait"`, + }, }, Action: action(func(run *app.App, c configImpl) error { return run.Sync(c) @@ -417,6 +421,10 @@ func main() { Name: "skip-deps", Usage: `skip running "helm repo update" and "helm dependency build"`, }, + cli.BoolFlag{ + Name: "wait", + Usage: `Override helmDefaults.wait setting "helm upgrade --install --wait"`, + }, }, Action: action(func(run *app.App, c configImpl) error { return run.Apply(c) @@ -603,6 +611,10 @@ func (c configImpl) SkipRepos() bool { return c.c.Bool("skip-repos") } +func (c configImpl) Wait() bool { + return c.c.Bool("wait") +} + func (c configImpl) Values() []string { return c.c.StringSlice("values") } diff --git a/pkg/app/app.go b/pkg/app/app.go index 65bc998d..b935b7d8 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -294,6 +294,7 @@ func (a *App) Sync(c SyncConfigProvider) error { prepErr := run.withPreparedCharts("sync", state.ChartPrepareOptions{ SkipRepos: c.SkipDeps(), SkipDeps: c.SkipDeps(), + Wait: c.Wait(), }, func() { ok, errs = a.sync(run, c) }) @@ -319,6 +320,7 @@ func (a *App) Apply(c ApplyConfigProvider) error { prepErr := run.withPreparedCharts("apply", state.ChartPrepareOptions{ SkipRepos: c.SkipDeps(), SkipDeps: c.SkipDeps(), + Wait: c.Wait(), }, func() { matched, updated, es := a.apply(run, c) @@ -1179,6 +1181,7 @@ Do you really want to apply? syncOpts := state.SyncOpts{ Set: c.Set(), SkipCleanup: c.RetainValuesFiles() || c.SkipCleanup(), + Wait: c.Wait(), } return subst.SyncReleases(&affectedReleases, helm, c.Values(), c.Concurrency(), &syncOpts) })) @@ -1393,7 +1396,8 @@ func (a *App) sync(r *Run, c SyncConfigProvider) (bool, []error) { subst.Releases = rs opts := &state.SyncOpts{ - Set: c.Set(), + Set: c.Set(), + Wait: c.Wait(), } return subst.SyncReleases(&affectedReleases, helm, c.Values(), c.Concurrency(), opts) })) diff --git a/pkg/app/app_test.go b/pkg/app/app_test.go index b8e6f072..110b9c24 100644 --- a/pkg/app/app_test.go +++ b/pkg/app/app_test.go @@ -2315,12 +2315,17 @@ type applyConfig struct { interactive bool skipDiffOnInstall bool logger *zap.SugaredLogger + wait bool } func (a applyConfig) Args() string { return a.args } +func (a applyConfig) Wait() bool { + return a.wait +} + func (a applyConfig) Values() []string { return a.values } diff --git a/pkg/app/config.go b/pkg/app/config.go index 853507dc..1e4d2ba3 100644 --- a/pkg/app/config.go +++ b/pkg/app/config.go @@ -39,6 +39,7 @@ type ApplyConfigProvider interface { Values() []string Set() []string SkipDeps() bool + Wait() bool IncludeTests() bool @@ -65,6 +66,7 @@ type SyncConfigProvider interface { Values() []string Set() []string SkipDeps() bool + Wait() bool concurrencyConfig loggingConfig diff --git a/pkg/state/state.go b/pkg/state/state.go index d4b45bcb..74396ab0 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -504,6 +504,10 @@ func (st *HelmState) prepareSyncReleases(helm helmexec.Interface, additionalValu } } + if opts.Wait { + flags = append(flags, "--wait") + } + if len(errs) > 0 { results <- syncPrepareResult{errors: errs, files: files} continue @@ -578,6 +582,7 @@ func (st *HelmState) DetectReleasesToBeDeleted(helm helmexec.Interface, releases type SyncOpts struct { Set []string SkipCleanup bool + Wait bool } type SyncOpt interface{ Apply(*SyncOpts) } @@ -876,6 +881,7 @@ type ChartPrepareOptions struct { SkipRepos bool SkipDeps bool SkipResolve bool + Wait bool } type chartPrepareResult struct {