From f47d8ea256a5d8ae60c9b6daefd0c8a3dd20162c Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Sat, 2 Nov 2019 14:45:50 +0900 Subject: [PATCH 1/3] Integration tests with Helm v3.0.0-rc.2 --- .circleci/config.yml | 53 +++++++++++++++++++++++++++++++++++++---- test/integration/run.sh | 11 +++++++-- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 61f1ec00..50db586f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -103,6 +103,51 @@ jobs: export TERM=xterm make integration + integration_tests_helmv3: + machine: + image: circleci/classic:201808-01 + environment: + CHANGE_MINIKUBE_NONE_USER: true + MINIKUBE_WANTUPDATENOTIFICATION: false + MINIKUBE_WANTREPORTERRORPROMPT: false + steps: + - checkout + - run: mkdir ~/build + - attach_workspace: + at: ~/build + - run: cp ~/build/helmfile ~/project/helmfile + - run: + name: Install helm + environment: + HELM_VERSION: v3.0.0-rc.2 + command: | + HELM_FILENAME="helm-${HELM_VERSION}-linux-amd64.tar.gz" + curl -Lo ${HELM_FILENAME} "https://get.helm.sh/${HELM_FILENAME}" + tar zxf ${HELM_FILENAME} linux-amd64/helm + chmod +x linux-amd64/helm + sudo mv linux-amd64/helm /usr/local/bin/ + - run: + name: Deploy minikube + environment: + CHANGE_MINIKUBE_NONE_USER: true + K8S_VERSION: v1.12.3 + MINIKUBE_VERSION: v0.30.0 + command: | + curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl + chmod +x kubectl && sudo mv kubectl /usr/local/bin/ + curl -Lo minikube https://storage.googleapis.com/minikube/releases/${MINIKUBE_VERSION}/minikube-linux-amd64 + chmod +x minikube && sudo mv minikube /usr/local/bin/ + sudo -E minikube start --vm-driver=none --kubernetes-version=${K8S_VERSION} + sudo -E minikube update-context + - run: + name: Wait for nodes to become ready + command: JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'; until kubectl get nodes -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do sleep 1; done + - run: + name: Execute integration tests + command: | + export TERM=xterm + HELMFILE_HELM3=1 make integration + # GITHUB_TOKEN env var must be setup in circleci console release: @@ -133,11 +178,9 @@ workflows: - integration_tests: requires: - build - filters: - branches: - only: - - master - - /pull.*/ + - integration_tests_helmv3: + requires: + - build - release: filters: branches: diff --git a/test/integration/run.sh b/test/integration/run.sh index 3b16c130..65771bcf 100755 --- a/test/integration/run.sh +++ b/test/integration/run.sh @@ -45,8 +45,14 @@ function retry() { set -e info "Using namespace: ${test_ns}" -info "Using Helm version: $(helm version --short --client | grep -o v.*$)" -${helm} init --wait --override spec.template.spec.automountServiceAccountToken=true +# helm v2 +if helm version --client 1>/dev/null 2>/dev/null; then + info "Using Helm version: $(helm version --short --client | grep -o v.*$)" + ${helm} init --wait --override spec.template.spec.automountServiceAccountToken=true +# helm v3 +else + info "Using Helm version: $(helm version --short | grep -o v.*$)" +fi ${helm} plugin install https://github.com/databus23/helm-diff --version master ${kubectl} get namespace ${test_ns} &> /dev/null && warn "Namespace ${test_ns} exists, from a previous test run?" $kubectl create namespace ${test_ns} || fail "Could not create namespace ${test_ns}" @@ -91,6 +97,7 @@ info "Applying ${dir}/happypath.yaml with locked dependencies" ${helmfile} -f ${dir}/happypath.yaml apply code=$? [ ${code} -eq 0 ] || fail "unexpected exit code returned by helmfile apply: ${code}" +${helm} list --namespace=${test_ns} || fail "unable to list releases" info "Deleting release" ${helmfile} -f ${dir}/happypath.yaml delete From 30751e94f780fb909b209ec513a952e31775e267 Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Sat, 2 Nov 2019 15:21:54 +0900 Subject: [PATCH 2/3] Fix `helmfile --namespace ns delete` to not fail consistently Until now `helmfile delete` with helm v3 had been failing when `--namespace` is provided. Helmfile was missing the fact that in helm v3 namespace must be passed instead of tiller-namespace to scope releases to be deleted. ``` err: release "b-1" failed: helm3rc2 exited with status 1: Error: uninstall: Release not loaded: b-1: release: not found in ./helmfile.yaml: release "b-1" failed: helm3rc2 exited with status 1: Error: uninstall: Release not loaded: b-1: release: not found ``` --- pkg/state/state.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/state/state.go b/pkg/state/state.go index 075f9c2f..e9191545 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -1143,6 +1143,8 @@ func (st *HelmState) DeleteReleases(affectedReleases *AffectedReleases, helm hel return nil } + st.ApplyOverrides(&release) + flags := []string{} if purge && !isHelm3() { flags = append(flags, "--purge") From fbbd7630e79fbba145b2ba639d2d98b833e6682a Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Sat, 2 Nov 2019 15:46:44 +0900 Subject: [PATCH 3/3] 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 }