Skip to content

Commit

Permalink
fix(k8s): ensure helm migration works on Windows
Browse files Browse the repository at this point in the history
Apparently, the Helm plugin system doesn't work on Windows (except in
bash-like shells). So instead of installing the 2to3 plugin via the Helm
CLI (as one would expect), we instead have to download it manually and
execute it directly.
  • Loading branch information
eysi09 committed Jan 13, 2020
1 parent 3c50d57 commit 2771a98
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
30 changes: 30 additions & 0 deletions garden-service/src/plugins/kubernetes/helm/helm-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,36 @@ const helm3 = new BinaryCmd({
},
})

export const helmPlugin2to3 = new BinaryCmd({
name: "helm-plugin-2to3",
specs: {
darwin: {
url: "https://github.com/helm/helm-2to3/releases/download/v0.2.1/helm-2to3_0.2.1_darwin_amd64.tar.gz",
sha256: "b0ab2f81da90aa3d53731784a4c93ceb5c316d86098425aac0f09c8014acc2c1",
extract: {
format: "tar",
targetPath: ["2to3"],
},
},
linux: {
url: "https://github.com/helm/helm-2to3/releases/download/v0.2.1/helm-2to3_0.2.1_linux_amd64.tar.gz",
sha256: "f90c6cc3f4670be71d89d2f74739f53fd4b1b190d4b1dd4af5fa8002978a41f6",
extract: {
format: "tar",
targetPath: ["2to3"],
},
},
win32: {
url: "https://github.com/helm/helm-2to3/releases/download/v0.2.1/helm-2to3_0.2.1_windows_amd64.tar.gz",
sha256: "01b2671103b05b6b0d698dbec89ea09ee99d83380fc70c1e89324b2c8615cd0f",
extract: {
format: "tar",
targetPath: ["2to3.exe"],
},
},
},
})

export async function helm({
ctx,
namespace,
Expand Down
33 changes: 6 additions & 27 deletions garden-service/src/plugins/kubernetes/helm/tiller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { LogEntry } from "../../../logger/log-entry"
import { KubernetesResource } from "../types"
import { helm } from "./helm-cli"
import { helm, helmPlugin2to3 } from "./helm-cli"
import { safeLoadAll, safeDump } from "js-yaml"
import { KubeApi, getKubeConfig } from "../api"
import { checkResourceStatuses } from "../status/status"
Expand Down Expand Up @@ -127,28 +127,6 @@ export async function migrateToHelm3({
)
const helm3ReleaseNames = listFromHelm3.map((r: any) => r.name)

// Install the 2to3 plugin
try {
await helm({
ctx,
namespace,
log,
args: ["plugin", "install", "https://github.com/helm/helm-2to3"],
})
} catch (err) {
// Ugh ffs...
if (err.message.includes("plugin already exists")) {
await helm({
ctx,
namespace,
log,
args: ["plugin", "update", "2to3"],
})
} else {
throw err
}
}

// Convert each release from Tiller that isn't already in Helm 3
for (const releaseName of tillerReleaseNames) {
if (helm3ReleaseNames.includes(releaseName)) {
Expand Down Expand Up @@ -212,11 +190,12 @@ export async function migrateToHelm3({
await writeFile(configPath, safeDump(resolvedConfig))

log.debug(
await helm({
ctx,
namespace,
// It's not possible to install/update/execute Helm plugins on Windows because of this:
// https://github.com/helm/helm-2to3/issues/55
// So instead we download and execute the plugin binary directly, without passing it through the Helm CLI.
await helmPlugin2to3.stdout({
log,
args: ["2to3", "convert", releaseName, "--tiller-ns", namespace],
args: ["convert", releaseName, "--tiller-ns", namespace],
env: {
KUBECONFIG: configPath,
},
Expand Down

0 comments on commit 2771a98

Please sign in to comment.