diff --git a/docs/parameter_reference.md b/docs/parameter_reference.md index 81f82cf..6ef32a5 100644 --- a/docs/parameter_reference.md +++ b/docs/parameter_reference.md @@ -39,6 +39,7 @@ Installations are triggered when the `helm_command` setting is "upgrade." They c | timeout | duration | | Timeout for any *individual* Kubernetes operation. The installation's full runtime may exceed this duration. | | force | boolean | | Pass `--force` to `helm upgrade`. | | atomic_upgrade | boolean | | Pass `--atomic` to `helm upgrade`. | +| cleanup_failed_upgrade | boolean | | Pass `--cleanup-on-fail` to `helm upgrade`. | | values | list\ | | Chart values to use as the `--set` argument to `helm upgrade`. | | string_values | list\ | | Chart values to use as the `--set-string` argument to `helm upgrade`. | | values_files | list\ | | Values to use as `--values` arguments to `helm upgrade`. | diff --git a/internal/helm/config.go b/internal/helm/config.go index 704e20c..1c8a393 100644 --- a/internal/helm/config.go +++ b/internal/helm/config.go @@ -44,6 +44,7 @@ type Config struct { Release string `` // Release argument to use in applicable helm commands Force bool `` // Pass --force to applicable helm commands AtomicUpgrade bool `split_words:"true"` // Pass --atomic to `helm upgrade` + CleanupOnFail bool `envconfig:"CLEANUP_FAILED_UPGRADE"` // Pass --cleanup-on-fail to `helm upgrade` LintStrictly bool `split_words:"true"` // Pass --strict to `helm lint` Stdout io.Writer `ignored:"true"` diff --git a/internal/helm/plan.go b/internal/helm/plan.go index e167269..48f3f5f 100644 --- a/internal/helm/plan.go +++ b/internal/helm/plan.go @@ -98,18 +98,19 @@ var upgrade = func(cfg Config) []Step { steps = append(steps, depUpdate(cfg)...) } steps = append(steps, &run.Upgrade{ - Chart: cfg.Chart, - Release: cfg.Release, - ChartVersion: cfg.ChartVersion, - DryRun: cfg.DryRun, - Wait: cfg.Wait, - Values: cfg.Values, - StringValues: cfg.StringValues, - ValuesFiles: cfg.ValuesFiles, - ReuseValues: cfg.ReuseValues, - Timeout: cfg.Timeout, - Force: cfg.Force, - Atomic: cfg.AtomicUpgrade, + Chart: cfg.Chart, + Release: cfg.Release, + ChartVersion: cfg.ChartVersion, + DryRun: cfg.DryRun, + Wait: cfg.Wait, + Values: cfg.Values, + StringValues: cfg.StringValues, + ValuesFiles: cfg.ValuesFiles, + ReuseValues: cfg.ReuseValues, + Timeout: cfg.Timeout, + Force: cfg.Force, + Atomic: cfg.AtomicUpgrade, + CleanupOnFail: cfg.CleanupOnFail, }) return steps diff --git a/internal/helm/plan_test.go b/internal/helm/plan_test.go index 28f2886..f6cf9bb 100644 --- a/internal/helm/plan_test.go +++ b/internal/helm/plan_test.go @@ -142,6 +142,7 @@ func (suite *PlanTestSuite) TestUpgrade() { Release: "post_malone_circles", Force: true, AtomicUpgrade: true, + CleanupOnFail: true, } steps := upgrade(cfg) @@ -152,18 +153,19 @@ func (suite *PlanTestSuite) TestUpgrade() { upgrade, _ := steps[1].(*run.Upgrade) expected := &run.Upgrade{ - Chart: cfg.Chart, - Release: cfg.Release, - ChartVersion: cfg.ChartVersion, - DryRun: true, - Wait: cfg.Wait, - Values: "steadfastness,forthrightness", - StringValues: "tensile_strength,flexibility", - ValuesFiles: []string{"/root/price_inventory.yml"}, - ReuseValues: cfg.ReuseValues, - Timeout: cfg.Timeout, - Force: cfg.Force, - Atomic: true, + Chart: cfg.Chart, + Release: cfg.Release, + ChartVersion: cfg.ChartVersion, + DryRun: true, + Wait: cfg.Wait, + Values: "steadfastness,forthrightness", + StringValues: "tensile_strength,flexibility", + ValuesFiles: []string{"/root/price_inventory.yml"}, + ReuseValues: cfg.ReuseValues, + Timeout: cfg.Timeout, + Force: cfg.Force, + Atomic: true, + CleanupOnFail: true, } suite.Equal(expected, upgrade) diff --git a/internal/run/upgrade.go b/internal/run/upgrade.go index 3efd95b..c239807 100644 --- a/internal/run/upgrade.go +++ b/internal/run/upgrade.go @@ -9,16 +9,17 @@ type Upgrade struct { Chart string Release string - ChartVersion string - DryRun bool - Wait bool - Values string - StringValues string - ValuesFiles []string - ReuseValues bool - Timeout string - Force bool - Atomic bool + ChartVersion string + DryRun bool + Wait bool + Values string + StringValues string + ValuesFiles []string + ReuseValues bool + Timeout string + Force bool + Atomic bool + CleanupOnFail bool cmd cmd } @@ -69,6 +70,9 @@ func (u *Upgrade) Prepare(cfg Config) error { if u.Atomic { args = append(args, "--atomic") } + if u.CleanupOnFail { + args = append(args, "--cleanup-on-fail") + } if u.Values != "" { args = append(args, "--set", u.Values) } diff --git a/internal/run/upgrade_test.go b/internal/run/upgrade_test.go index f3a1fdf..886fb3b 100644 --- a/internal/run/upgrade_test.go +++ b/internal/run/upgrade_test.go @@ -89,18 +89,19 @@ func (suite *UpgradeTestSuite) TestPrepareWithUpgradeFlags() { defer suite.ctrl.Finish() u := Upgrade{ - Chart: "hot_ac", - Release: "maroon_5_memories", - ChartVersion: "radio_edit", - DryRun: true, - Wait: true, - Values: "age=35", - StringValues: "height=5ft10in", - ValuesFiles: []string{"/usr/local/stats", "/usr/local/grades"}, - ReuseValues: true, - Timeout: "sit_in_the_corner", - Force: true, - Atomic: true, + Chart: "hot_ac", + Release: "maroon_5_memories", + ChartVersion: "radio_edit", + DryRun: true, + Wait: true, + Values: "age=35", + StringValues: "height=5ft10in", + ValuesFiles: []string{"/usr/local/stats", "/usr/local/grades"}, + ReuseValues: true, + Timeout: "sit_in_the_corner", + Force: true, + Atomic: true, + CleanupOnFail: true, } cfg := Config{} @@ -115,6 +116,7 @@ func (suite *UpgradeTestSuite) TestPrepareWithUpgradeFlags() { "--timeout", "sit_in_the_corner", "--force", "--atomic", + "--cleanup-on-fail", "--set", "age=35", "--set-string", "height=5ft10in", "--values", "/usr/local/stats",