mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add kubectl/helm download mirror select to preferences (#185)
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
1 parent
f0dd4095ac
commit
5c2e64b487
7 files changed
+73
-81
No files matched your search
+1
-1
@@ -10,7 +10,6 @@ import { PromiseIpc } from "electron-promise-ipc"
|
||||
import * as request from "request-promise-native"
|
||||
import { KubeconfigManager } from "./kubeconfig-manager"
|
||||
|
||||
|
||||
enum ClusterStatus {
|
||||
AccessGranted = 2,
|
||||
AccessDenied = 1,
|
||||
@@ -134,6 +133,7 @@ export class Cluster implements ClusterInfo {
|
||||
this.nodes = await this.getNodeCount()
|
||||
}
|
||||
this.kubeCtl = new Kubectl(this.version)
|
||||
this.kubeCtl.ensureKubectl()
|
||||
}
|
||||
this.eventCount = await this.getEventCount();
|
||||
}
|
||||
|
||||
+16
-2
@@ -1,5 +1,12 @@
|
||||
import * as path from "path"
|
||||
import { LensBinary, LensBinaryOpts } from "./lens-binary"
|
||||
import { userStore } from "../common/user-store"
|
||||
|
||||
const helmVersion = "3.1.2"
|
||||
const packageMirrors: Map<string, string> = new Map([
|
||||
["default", "https://get.helm.sh"],
|
||||
["china", "https://mirror.azure.cn/kubernetes/helm"]
|
||||
])
|
||||
|
||||
export class HelmCli extends LensBinary {
|
||||
|
||||
@@ -16,7 +23,14 @@ export class HelmCli extends LensBinary {
|
||||
}
|
||||
|
||||
protected getUrl() {
|
||||
return `https://get.helm.sh/helm-v${this.binaryVersion}-${this.platformName}-${this.arch}.tar.gz`
|
||||
return `${this.getDownloadMirror()}/helm-v${this.binaryVersion}-${this.platformName}-${this.arch}.tar.gz`
|
||||
}
|
||||
|
||||
protected getDownloadMirror() {
|
||||
const mirror = packageMirrors.get(userStore.getPreferences().downloadMirror)
|
||||
if (mirror) { return mirror }
|
||||
|
||||
return packageMirrors.get("default")
|
||||
}
|
||||
|
||||
protected getBinaryPath() {
|
||||
@@ -28,4 +42,4 @@ export class HelmCli extends LensBinary {
|
||||
}
|
||||
}
|
||||
|
||||
export const helmCli = new HelmCli("3.1.2")
|
||||
export const helmCli = new HelmCli(helmVersion)
|
||||
+5
-2
@@ -15,7 +15,7 @@ import { shellSync } from "./shell-sync"
|
||||
import { getFreePort } from "./port"
|
||||
import { mangleProxyEnv } from "./proxy-env"
|
||||
import { findMainWebContents } from "./webcontents"
|
||||
import { HelmRepoManager, HelmRepo } from "./helm-repo-manager"
|
||||
import { helmCli } from "./helm-cli"
|
||||
|
||||
mangleProxyEnv()
|
||||
if (app.commandLine.getSwitchValue("proxy-server") !== "") {
|
||||
@@ -99,7 +99,10 @@ async function main() {
|
||||
logger.debug("navigate: cluster-settings-page IPC sent");
|
||||
})
|
||||
},
|
||||
}, promiseIpc);
|
||||
}, promiseIpc)
|
||||
|
||||
// download helm cli
|
||||
helmCli.ensureBinary()
|
||||
}
|
||||
|
||||
app.on("ready", main)
|
||||
|
||||
+22
-6
@@ -9,6 +9,7 @@ import * as md5File from "md5-file"
|
||||
import { globalRequestOpts } from "../common/request"
|
||||
import * as lockFile from "proper-lockfile"
|
||||
import { helmCli } from "./helm-cli"
|
||||
import { userStore } from "../common/user-store"
|
||||
|
||||
const kubectlMap: Map<string, string> = new Map([
|
||||
["1.7", "1.8.15"],
|
||||
@@ -19,10 +20,15 @@ const kubectlMap: Map<string, string> = new Map([
|
||||
["1.12", "1.13.12"],
|
||||
["1.13", "1.13.12"],
|
||||
["1.14", "1.14.10"],
|
||||
["1.15", "1.15.10"],
|
||||
["1.16", "1.16.7"],
|
||||
["1.17", "1.17.3"],
|
||||
["1.18", "1.18.0-beta.1"]
|
||||
["1.15", "1.15.11"],
|
||||
["1.16", "1.16.8"],
|
||||
["1.17", "1.17.4"],
|
||||
["1.18", "1.18.0"]
|
||||
])
|
||||
|
||||
const packageMirrors: Map<string, string> = new Map([
|
||||
["default", "https://storage.googleapis.com/kubernetes-release/release"],
|
||||
["china", "https://mirror.azure.cn/kubernetes/kubectl"]
|
||||
])
|
||||
|
||||
const initScriptVersionString = "# lens-initscript v3\n"
|
||||
@@ -83,7 +89,7 @@ export class Kubectl {
|
||||
const platformName = process.platform === "win32" ? "windows" : process.platform
|
||||
const binaryName = process.platform === "win32" ? "kubectl.exe" : "kubectl"
|
||||
|
||||
this.url = `https://storage.googleapis.com/kubernetes-release/release/v${this.kubectlVersion}/bin/${platformName}/${arch}/${binaryName}`
|
||||
this.url = `${this.getDownloadMirror()}/v${this.kubectlVersion}/bin/${platformName}/${arch}/${binaryName}`
|
||||
|
||||
this.dirname = path.normalize(path.join(Kubectl.kubectlDir, this.kubectlVersion))
|
||||
this.path = path.join(this.dirname, binaryName)
|
||||
@@ -167,7 +173,7 @@ export class Kubectl {
|
||||
}
|
||||
}
|
||||
|
||||
protected async ensureKubectl(): Promise<boolean> {
|
||||
public async ensureKubectl(): Promise<boolean> {
|
||||
await ensureDir(this.dirname, 0o755)
|
||||
return lockFile.lock(this.dirname).then(async (release) => {
|
||||
logger.debug(`Acquired a lock for ${this.kubectlVersion}`)
|
||||
@@ -287,6 +293,16 @@ export class Kubectl {
|
||||
url: this.url
|
||||
})
|
||||
}
|
||||
|
||||
protected getDownloadMirror() {
|
||||
if (process.platform == "darwin") {
|
||||
return packageMirrors.get("default") // MacOS packages are only available from default
|
||||
}
|
||||
const mirror = packageMirrors.get(userStore.getPreferences().downloadMirror)
|
||||
if (mirror) { return mirror }
|
||||
|
||||
return packageMirrors.get("default")
|
||||
}
|
||||
}
|
||||
|
||||
const bundledKubectl = Kubectl.bundled()
|
||||
|
||||
@@ -95,7 +95,7 @@ export class LensBinary {
|
||||
return exists
|
||||
}
|
||||
|
||||
protected async ensureBinary() {
|
||||
public async ensureBinary() {
|
||||
const isValid = await this.checkBinary()
|
||||
if(!isValid) {
|
||||
await this.downloadBinary().catch((error) => { logger.error(error) });
|
||||
@@ -129,7 +129,7 @@ export class LensBinary {
|
||||
})
|
||||
}
|
||||
|
||||
public async downloadBinary() {
|
||||
protected async downloadBinary() {
|
||||
const binaryPath = this.tarPath || this.getBinaryPath()
|
||||
await ensureDir(this.getBinaryDir(), 0o755)
|
||||
|
||||
|
||||
Reference in new issue
Block a user