From fbbd7630e79fbba145b2ba639d2d98b833e6682a Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Sat, 2 Nov 2019 15:46:44 +0900 Subject: [PATCH] v3 compatibility: Fix `helmfile delete` to not fail when there was no release to be deleted `helmfile delete` is designed to be idempotent. That is, it is safe to be run when there is nothing to delete. A change in helm v3 broke that behavior. This enhances Helmfile to be able to behave the same for helm v2 and v3. --- pkg/helmexec/exec.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/helmexec/exec.go b/pkg/helmexec/exec.go index 1d51bcac..79b41208 100644 --- a/pkg/helmexec/exec.go +++ b/pkg/helmexec/exec.go @@ -133,6 +133,17 @@ func (helm *execer) List(context HelmContext, filter string, flags ...string) (s } out, err := helm.exec(append(append(preArgs, args...), flags...), env) + // In v2 we have been expecting `helm list FILTER` prints nothing. + // In v3 helm still prints the header like `NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION`, + // which confuses helmfile's existing logic that treats any non-empty output from `helm list` is considered as the indication + // of the release to exist. + // + // This fixes it by removing the header from the v3 output, so that the output is formatted the same as that of v2. + if helm.isHelm3() { + lines := strings.Split(string(out), "\n") + lines = lines[1:] + out = []byte(strings.Join(lines, "\n")) + } helm.write(out) return string(out), err }