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 {
|
export interface User {
|
||||||
id?: string;
|
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 {
|
export interface UserPreferences {
|
||||||
@ -25,6 +11,7 @@ export interface UserPreferences {
|
|||||||
colorTheme?: string;
|
colorTheme?: string;
|
||||||
allowUntrustedCAs?: boolean;
|
allowUntrustedCAs?: boolean;
|
||||||
allowTelemetry?: boolean;
|
allowTelemetry?: boolean;
|
||||||
|
downloadMirror?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class UserStore {
|
export class UserStore {
|
||||||
@ -70,6 +57,9 @@ export class UserStore {
|
|||||||
if (!prefs.colorTheme) {
|
if (!prefs.colorTheme) {
|
||||||
prefs.colorTheme = "dark"
|
prefs.colorTheme = "dark"
|
||||||
}
|
}
|
||||||
|
if (!prefs.downloadMirror) {
|
||||||
|
prefs.downloadMirror = "default"
|
||||||
|
}
|
||||||
if (prefs.allowTelemetry === undefined) {
|
if (prefs.allowTelemetry === undefined) {
|
||||||
prefs.allowTelemetry = true
|
prefs.allowTelemetry = true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import { PromiseIpc } from "electron-promise-ipc"
|
|||||||
import * as request from "request-promise-native"
|
import * as request from "request-promise-native"
|
||||||
import { KubeconfigManager } from "./kubeconfig-manager"
|
import { KubeconfigManager } from "./kubeconfig-manager"
|
||||||
|
|
||||||
|
|
||||||
enum ClusterStatus {
|
enum ClusterStatus {
|
||||||
AccessGranted = 2,
|
AccessGranted = 2,
|
||||||
AccessDenied = 1,
|
AccessDenied = 1,
|
||||||
@ -134,6 +133,7 @@ export class Cluster implements ClusterInfo {
|
|||||||
this.nodes = await this.getNodeCount()
|
this.nodes = await this.getNodeCount()
|
||||||
}
|
}
|
||||||
this.kubeCtl = new Kubectl(this.version)
|
this.kubeCtl = new Kubectl(this.version)
|
||||||
|
this.kubeCtl.ensureKubectl()
|
||||||
}
|
}
|
||||||
this.eventCount = await this.getEventCount();
|
this.eventCount = await this.getEventCount();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,12 @@
|
|||||||
import * as path from "path"
|
import * as path from "path"
|
||||||
import { LensBinary, LensBinaryOpts } from "./lens-binary"
|
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 {
|
export class HelmCli extends LensBinary {
|
||||||
|
|
||||||
@ -16,7 +23,14 @@ export class HelmCli extends LensBinary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected getUrl() {
|
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() {
|
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 { getFreePort } from "./port"
|
||||||
import { mangleProxyEnv } from "./proxy-env"
|
import { mangleProxyEnv } from "./proxy-env"
|
||||||
import { findMainWebContents } from "./webcontents"
|
import { findMainWebContents } from "./webcontents"
|
||||||
import { HelmRepoManager, HelmRepo } from "./helm-repo-manager"
|
import { helmCli } from "./helm-cli"
|
||||||
|
|
||||||
mangleProxyEnv()
|
mangleProxyEnv()
|
||||||
if (app.commandLine.getSwitchValue("proxy-server") !== "") {
|
if (app.commandLine.getSwitchValue("proxy-server") !== "") {
|
||||||
@ -99,7 +99,10 @@ async function main() {
|
|||||||
logger.debug("navigate: cluster-settings-page IPC sent");
|
logger.debug("navigate: cluster-settings-page IPC sent");
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
}, promiseIpc);
|
}, promiseIpc)
|
||||||
|
|
||||||
|
// download helm cli
|
||||||
|
helmCli.ensureBinary()
|
||||||
}
|
}
|
||||||
|
|
||||||
app.on("ready", main)
|
app.on("ready", main)
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import * as md5File from "md5-file"
|
|||||||
import { globalRequestOpts } from "../common/request"
|
import { globalRequestOpts } from "../common/request"
|
||||||
import * as lockFile from "proper-lockfile"
|
import * as lockFile from "proper-lockfile"
|
||||||
import { helmCli } from "./helm-cli"
|
import { helmCli } from "./helm-cli"
|
||||||
|
import { userStore } from "../common/user-store"
|
||||||
|
|
||||||
const kubectlMap: Map<string, string> = new Map([
|
const kubectlMap: Map<string, string> = new Map([
|
||||||
["1.7", "1.8.15"],
|
["1.7", "1.8.15"],
|
||||||
@ -19,10 +20,15 @@ const kubectlMap: Map<string, string> = new Map([
|
|||||||
["1.12", "1.13.12"],
|
["1.12", "1.13.12"],
|
||||||
["1.13", "1.13.12"],
|
["1.13", "1.13.12"],
|
||||||
["1.14", "1.14.10"],
|
["1.14", "1.14.10"],
|
||||||
["1.15", "1.15.10"],
|
["1.15", "1.15.11"],
|
||||||
["1.16", "1.16.7"],
|
["1.16", "1.16.8"],
|
||||||
["1.17", "1.17.3"],
|
["1.17", "1.17.4"],
|
||||||
["1.18", "1.18.0-beta.1"]
|
["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"
|
const initScriptVersionString = "# lens-initscript v3\n"
|
||||||
@ -83,7 +89,7 @@ export class Kubectl {
|
|||||||
const platformName = process.platform === "win32" ? "windows" : process.platform
|
const platformName = process.platform === "win32" ? "windows" : process.platform
|
||||||
const binaryName = process.platform === "win32" ? "kubectl.exe" : "kubectl"
|
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.dirname = path.normalize(path.join(Kubectl.kubectlDir, this.kubectlVersion))
|
||||||
this.path = path.join(this.dirname, binaryName)
|
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)
|
await ensureDir(this.dirname, 0o755)
|
||||||
return lockFile.lock(this.dirname).then(async (release) => {
|
return lockFile.lock(this.dirname).then(async (release) => {
|
||||||
logger.debug(`Acquired a lock for ${this.kubectlVersion}`)
|
logger.debug(`Acquired a lock for ${this.kubectlVersion}`)
|
||||||
@ -287,6 +293,16 @@ export class Kubectl {
|
|||||||
url: this.url
|
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()
|
const bundledKubectl = Kubectl.bundled()
|
||||||
|
|||||||
@ -95,7 +95,7 @@ export class LensBinary {
|
|||||||
return exists
|
return exists
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async ensureBinary() {
|
public async ensureBinary() {
|
||||||
const isValid = await this.checkBinary()
|
const isValid = await this.checkBinary()
|
||||||
if(!isValid) {
|
if(!isValid) {
|
||||||
await this.downloadBinary().catch((error) => { logger.error(error) });
|
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()
|
const binaryPath = this.tarPath || this.getBinaryPath()
|
||||||
await ensureDir(this.getBinaryDir(), 0o755)
|
await ensureDir(this.getBinaryDir(), 0o755)
|
||||||
|
|
||||||
|
|||||||
@ -5,34 +5,6 @@
|
|||||||
<div class="header sticky-top">
|
<div class="header sticky-top">
|
||||||
<h2>Preferences</h2>
|
<h2>Preferences</h2>
|
||||||
</div>
|
</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="row">
|
||||||
<div class="col-3" />
|
<div class="col-3" />
|
||||||
<div ref="content" class="global-settings col-6">
|
<div ref="content" class="global-settings col-6">
|
||||||
@ -52,6 +24,25 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-3" />
|
<div class="col-3" />
|
||||||
</div>
|
</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="row">
|
||||||
<div class="col-3" />
|
<div class="col-3" />
|
||||||
<div ref="content" class="global-settings col-6">
|
<div ref="content" class="global-settings col-6">
|
||||||
@ -156,16 +147,16 @@ export default {
|
|||||||
},
|
},
|
||||||
data(){
|
data(){
|
||||||
return {
|
return {
|
||||||
licenseKey: "",
|
|
||||||
hubRepositories: [],
|
hubRepositories: [],
|
||||||
selectedHubRepo: "",
|
selectedHubRepo: "",
|
||||||
colorThemeOptions: [
|
colorThemeOptions: [
|
||||||
{ value: "dark", text: "Dark" },
|
{ value: "dark", text: "Dark" },
|
||||||
{ value: "light", text: "Light" },
|
{ value: "light", text: "Light" },
|
||||||
],
|
],
|
||||||
errors: {
|
downloadMirrorOptions: [
|
||||||
licenseKey: null
|
{ value: "default", text: "Default (Google)" },
|
||||||
},
|
{ value: "china", text: "China (Azure)" },
|
||||||
|
],
|
||||||
isHelmProcessing: null,
|
isHelmProcessing: null,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -176,33 +167,11 @@ export default {
|
|||||||
preferences: function() {
|
preferences: function() {
|
||||||
return this.$store.getters.preferences;
|
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: {
|
methods: {
|
||||||
onSave: function() {
|
onSave: function() {
|
||||||
this.$store.commit("savePreferences", this.preferences);
|
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) {
|
request: async function(opts) {
|
||||||
const o = Object.assign({
|
const o = Object.assign({
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user