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:
parent
f0dd4095ac
commit
5c2e64b487
@ -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
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -5,34 +5,6 @@
|
||||
<div class="header sticky-top">
|
||||
<h2>Preferences</h2>
|
||||
</div>
|
||||
<!-- <div class="row">
|
||||
<div class="col-3" />
|
||||
<div ref="content" class="global-settings col-6">
|
||||
<h2>Kontena Lens PRO License</h2>
|
||||
|
||||
<b-form-group
|
||||
label="No Kontena Lens PRO license assigned. Assign license by entering license key below:"
|
||||
label-for="input-license-key"
|
||||
v-if="!licenceData || licenceData.status !== 'valid'"
|
||||
>
|
||||
<b-form-input
|
||||
id="input-license-key"
|
||||
v-model="licenseKey"
|
||||
trim
|
||||
@blur="onLicenseKeySave"
|
||||
placeholder="Enter license key"
|
||||
:disabled="!isLoggedIn"
|
||||
:state="errors.licenseKey"
|
||||
/>
|
||||
</b-form-group>
|
||||
<div v-if="licenceData">
|
||||
<p v-if="licenceData.status === 'valid'">
|
||||
Valid Kontena Lens PRO license assigned. Valid until {{ licenceData.valid_until }}<span v-if="licenceData.recurring">(renews automatically)</span>.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-3" />
|
||||
</div> -->
|
||||
<div class="row">
|
||||
<div class="col-3" />
|
||||
<div ref="content" class="global-settings col-6">
|
||||
@ -52,6 +24,25 @@
|
||||
</div>
|
||||
<div class="col-3" />
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-3" />
|
||||
<div ref="content" class="global-settings col-6">
|
||||
<h2>Download Mirror</h2>
|
||||
|
||||
<b-form-group
|
||||
label="Download mirror for kubectl/helm:"
|
||||
label-for="input-download-mirror"
|
||||
>
|
||||
<b-form-select
|
||||
id="input-download-mirror"
|
||||
v-model="preferences.downloadMirror"
|
||||
@change="onSave"
|
||||
:options="downloadMirrorOptions"
|
||||
/>
|
||||
</b-form-group>
|
||||
</div>
|
||||
<div class="col-3" />
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-3" />
|
||||
<div ref="content" class="global-settings col-6">
|
||||
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user