From 17724e701584421e84223d33c717192b4375b73f Mon Sep 17 00:00:00 2001 From: Erin Call Date: Thu, 2 Jan 2020 10:58:58 -0800 Subject: [PATCH] Pass --keep-history when so instructed [#24] --- README.md | 1 + docs/parameter_reference.md | 1 + internal/helm/config.go | 1 + internal/helm/plan.go | 5 +++-- internal/helm/plan_test.go | 6 ++++-- internal/run/uninstall.go | 10 +++++++--- internal/run/uninstall_test.go | 15 +++++++++++++++ 7 files changed, 32 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 14351e1..6900962 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ drone-helm3 is largely backwards-compatible with drone-helm. There are some know * You'll need to migrate the deployments in the cluster [helm-v2-to-helm-v3](https://helm.sh/blog/migrate-from-helm-v2-to-helm-v3/). * EKS is not supported. See [#5](https://github.com/pelotech/drone-helm3/issues/5) for more information. * The `prefix` setting is no longer supported. If you were relying on the `prefix` setting with `secrets: [...]`, you'll need to switch to the `from_secret` syntax. +* During uninstallations, the release history is purged by default. Use `keep_history: true` to return to the old behavior. * Several settings no longer have any effect. The plugin will produce warnings if any of these are present: * `purge` -- this is the default behavior in Helm 3 * `recreate_pods` diff --git a/docs/parameter_reference.md b/docs/parameter_reference.md index 9575d41..bb1c58f 100644 --- a/docs/parameter_reference.md +++ b/docs/parameter_reference.md @@ -54,6 +54,7 @@ Uninstallations are triggered when the `helm_command` setting is "uninstall" or | kubernetes_token | string | yes | Token for authenticating to Kubernetes. | | service_account | string | | Service account for authenticating to Kubernetes. Default is `helm`. | | kubernetes_certificate | string | | Base64 encoded TLS certificate used by the Kubernetes cluster's certificate authority. | +| keep_history | boolean | | Pass `--keep-history` to `helm uninstall`, to retain the release history. | | dry_run | boolean | | Pass `--dry-run` to `helm uninstall`. | | timeout | duration | | Timeout for any *individual* Kubernetes operation. The uninstallation's full runtime may exceed this duration. | | skip_tls_verify | boolean | | Connect to the Kubernetes cluster without checking for a valid TLS certificate. Not recommended in production. | diff --git a/internal/helm/config.go b/internal/helm/config.go index 2365ce2..0a80558 100644 --- a/internal/helm/config.go +++ b/internal/helm/config.go @@ -38,6 +38,7 @@ type Config struct { DryRun bool `split_words:"true"` // Pass --dry-run to applicable helm commands Wait bool `` // Pass --wait to applicable helm commands ReuseValues bool `split_words:"true"` // Pass --reuse-values to `helm upgrade` + KeepHistory bool `split_words:"true"` // Pass --keep-history to `helm uninstall` Timeout string `` // Argument to pass to --timeout in applicable helm commands Chart string `` // Chart argument to use in applicable helm commands Release string `` // Release argument to use in applicable helm commands diff --git a/internal/helm/plan.go b/internal/helm/plan.go index ebd4774..82657ee 100644 --- a/internal/helm/plan.go +++ b/internal/helm/plan.go @@ -120,8 +120,9 @@ var uninstall = func(cfg Config) []Step { steps = append(steps, depUpdate(cfg)...) } steps = append(steps, &run.Uninstall{ - Release: cfg.Release, - DryRun: cfg.DryRun, + Release: cfg.Release, + DryRun: cfg.DryRun, + KeepHistory: cfg.KeepHistory, }) return steps diff --git a/internal/helm/plan_test.go b/internal/helm/plan_test.go index d4e4e82..264e135 100644 --- a/internal/helm/plan_test.go +++ b/internal/helm/plan_test.go @@ -198,6 +198,7 @@ func (suite *PlanTestSuite) TestUninstall() { DryRun: true, Timeout: "think about what you did", Release: "jetta_id_love_to_change_the_world", + KeepHistory: true, } steps := uninstall(cfg) @@ -220,8 +221,9 @@ func (suite *PlanTestSuite) TestUninstall() { suite.Require().IsType(&run.Uninstall{}, steps[1]) actual, _ := steps[1].(*run.Uninstall) expected = &run.Uninstall{ - Release: "jetta_id_love_to_change_the_world", - DryRun: true, + Release: "jetta_id_love_to_change_the_world", + DryRun: true, + KeepHistory: true, } suite.Equal(expected, actual) } diff --git a/internal/run/uninstall.go b/internal/run/uninstall.go index e24daca..5c5c654 100644 --- a/internal/run/uninstall.go +++ b/internal/run/uninstall.go @@ -6,9 +6,10 @@ import ( // Uninstall is an execution step that calls `helm uninstall` when executed. type Uninstall struct { - Release string - DryRun bool - cmd cmd + Release string + DryRun bool + KeepHistory bool + cmd cmd } // Execute executes the `helm uninstall` command. @@ -36,6 +37,9 @@ func (u *Uninstall) Prepare(cfg Config) error { if u.DryRun { args = append(args, "--dry-run") } + if u.KeepHistory { + args = append(args, "--keep-history") + } args = append(args, u.Release) diff --git a/internal/run/uninstall_test.go b/internal/run/uninstall_test.go index fce7fee..6ac7cc9 100644 --- a/internal/run/uninstall_test.go +++ b/internal/run/uninstall_test.go @@ -81,6 +81,21 @@ func (suite *UninstallTestSuite) TestPrepareDryRunFlag() { suite.Equal(expected, suite.actualArgs) } +func (suite *UninstallTestSuite) TestPrepareKeepHistoryFlag() { + u := Uninstall{ + Release: "perturbator_sentient", + KeepHistory: true, + } + cfg := Config{} + + suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes() + suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes() + + suite.NoError(u.Prepare(cfg)) + expected := []string{"uninstall", "--keep-history", "perturbator_sentient"} + suite.Equal(expected, suite.actualArgs) +} + func (suite *UninstallTestSuite) TestPrepareNamespaceFlag() { u := Uninstall{ Release: "carly_simon_run_away_with_me",