diff --git a/src/common/user-store.ts b/src/common/user-store.ts index c47eb9cf20..3a53122174 100644 --- a/src/common/user-store.ts +++ b/src/common/user-store.ts @@ -4,20 +4,6 @@ import * as version210Beta4 from "./migrations/user-store/2.1.0-beta.4" export interface User { id?: string; - bio?: string; - company?: string; - email?: string; - 'first-name'?: string; - 'is-customer'?: boolean; - 'is-partner'?: boolean; - 'last-name'?: string; - 'lens-invitation-used'?: boolean; - location?: string; - //notifications?: array; - url?: string; - 'user-avatar-src'?: string; - username: string; - verified?: boolean; } export interface UserPreferences { @@ -25,6 +11,7 @@ export interface UserPreferences { colorTheme?: string; allowUntrustedCAs?: boolean; allowTelemetry?: boolean; + downloadMirror?: string; } export class UserStore { @@ -70,6 +57,9 @@ export class UserStore { if (!prefs.colorTheme) { prefs.colorTheme = "dark" } + if (!prefs.downloadMirror) { + prefs.downloadMirror = "default" + } if (prefs.allowTelemetry === undefined) { prefs.allowTelemetry = true } diff --git a/src/main/cluster.ts b/src/main/cluster.ts index 14ae23f122..5f4372997e 100644 --- a/src/main/cluster.ts +++ b/src/main/cluster.ts @@ -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(); } diff --git a/src/main/helm-cli.ts b/src/main/helm-cli.ts index 0327596bae..6486b3c0f5 100644 --- a/src/main/helm-cli.ts +++ b/src/main/helm-cli.ts @@ -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 = 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) diff --git a/src/main/index.ts b/src/main/index.ts index 6edd95e0c3..d668d1e8cf 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -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) diff --git a/src/main/kubectl.ts b/src/main/kubectl.ts index 14aa488100..162a613d69 100644 --- a/src/main/kubectl.ts +++ b/src/main/kubectl.ts @@ -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 = new Map([ ["1.7", "1.8.15"], @@ -19,10 +20,15 @@ const kubectlMap: Map = 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 = 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 { + public async ensureKubectl(): Promise { 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() diff --git a/src/main/lens-binary.ts b/src/main/lens-binary.ts index 9d86bf4e6a..d2599cad4c 100644 --- a/src/main/lens-binary.ts +++ b/src/main/lens-binary.ts @@ -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) diff --git a/src/renderer/components/PreferencesPage.vue b/src/renderer/components/PreferencesPage.vue index 2cb980ddaa..dfb4c2cb51 100644 --- a/src/renderer/components/PreferencesPage.vue +++ b/src/renderer/components/PreferencesPage.vue @@ -5,34 +5,6 @@

Preferences

-
@@ -52,6 +24,25 @@
+
+
+
+

Download Mirror

+ + + + +
+
+
@@ -156,16 +147,16 @@ export default { }, data(){ return { - licenseKey: "", hubRepositories: [], selectedHubRepo: "", colorThemeOptions: [ { value: "dark", text: "Dark" }, { value: "light", text: "Light" }, ], - errors: { - licenseKey: null - }, + downloadMirrorOptions: [ + { value: "default", text: "Default (Google)" }, + { value: "china", text: "China (Azure)" }, + ], isHelmProcessing: null, } }, @@ -176,33 +167,11 @@ export default { preferences: function() { return this.$store.getters.preferences; }, - licenceData: function() { - return this.$store.getters.licenseData; - }, - isLoggedIn: function() { - console.log(this.$store.getters.isLoggedIn) - return this.$store.getters.isLoggedIn; - } }, methods: { onSave: function() { this.$store.commit("savePreferences", this.preferences); }, - onLicenseKeySave: async function() { - if (this.licenseKey !== "") { - try { - await this.$store.dispatch("exhangeKey", { - key: this.licenseKey, - user: this.$store.getters.user - }) - this.errors.licenseKey = true; - } catch(error) { - this.errors.licenseKey = false; - } - } else { - this.errors.licenseKey = null; - } - }, request: async function(opts) { const o = Object.assign({ timeout: 10000,