From c9eafddfe096d37bd0e58ffb5b926f46af17f5df Mon Sep 17 00:00:00 2001 From: Colin Walker Date: Sat, 21 Sep 2019 02:54:26 +0000 Subject: [PATCH] fix: Helm3 compatibility on deletes Issue with using helm3 is that namespaces must be specified when removing releases. Added this value in. --- .github/workflows/test.yml | 4 ++-- index.js | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6efd6d24..0666f55c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,7 +19,7 @@ jobs: uses: 'actions/checkout@v1' - name: 'Deploy Canary' - uses: 'deliverybot/helm@ci-v2' + uses: 'deliverybot/helm@master' with: helm: helm3 token: '${{ github.token }}' @@ -39,7 +39,7 @@ jobs: KUBECONFIG_FILE: '${{ secrets.KUBECONFIG }}' - name: 'Deploy Production' - uses: 'deliverybot/helm@ci-v2' + uses: 'deliverybot/helm@master' with: helm: helm3 token: '${{ github.token }}' diff --git a/index.js b/index.js index 3fdd8939..308eae79 100644 --- a/index.js +++ b/index.js @@ -128,6 +128,20 @@ function renderFiles(files, data) { return Promise.all(promises); } +/** + * Makes a delete command for compatibility between helm 2 and 3. + * + * @param {string} helm + * @param {string} namespace + * @param {string} release + */ +function deleteCmd(helm, namespace, release) { + if (helm === "helm3") { + return ["delete", "-n", namespace, release]; + } + return ["delete", release]; +} + /** * Run executes the helm deployment. */ @@ -206,7 +220,7 @@ async function run() { // Remove the canary deployment before continuing. if (removeCanary) { core.debug(`removing canary ${appName}-canary`); - await exec.exec(helm, ["delete", `${appName}-canary`], { + await exec.exec(helm, deleteCmd(helm, namespace, `${appName}-canary`), { ...opts, ignoreReturnCode: true }); @@ -214,7 +228,7 @@ async function run() { // Actually execute the deployment here. if (task === "remove") { - await exec.exec(helm, ["delete", release], { + await exec.exec(helm, deleteCmd(helm, namespace, release), { ...opts, ignoreReturnCode: true });