1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Write bash init file to default kubectl bin dir

Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
Lauri Nevala 2020-09-03 22:56:24 +03:00
parent 97aaf79dbc
commit 179a9087e5
2 changed files with 10 additions and 8 deletions

View File

@ -106,15 +106,15 @@ export class Kubectl {
}
public getPathFromPreferences() {
return userStore.preferences.kubectlBinariesPath || this.getBundledPath()
return userStore.preferences?.kubectlBinariesPath || this.getBundledPath()
}
protected getDownloadDir() {
return userStore.preferences.downloadBinariesPath || Kubectl.kubectlDir
return userStore.preferences?.downloadBinariesPath || Kubectl.kubectlDir
}
public async getPath(bundled = false): Promise<string> {
if (!userStore.preferences.downloadKubectlBinaries) {
if (userStore.preferences?.downloadKubectlBinaries === false) {
return this.getPathFromPreferences()
}
@ -193,7 +193,7 @@ export class Kubectl {
}
public async ensureKubectl(): Promise<boolean> {
if (!userStore.preferences.downloadKubectlBinaries) {
if (userStore.preferences?.downloadKubectlBinaries === false) {
return true
}
if (Kubectl.invalidBundle) {
@ -278,7 +278,7 @@ export class Kubectl {
}
protected async writeInitScripts() {
const kubectlPath = userStore.preferences.downloadKubectlBinaries ? this.dirname : path.dirname(this.getPathFromPreferences())
const kubectlPath = userStore.preferences?.downloadKubectlBinaries ? this.dirname : path.dirname(this.getPathFromPreferences())
const helmPath = helmCli.getBinaryDir()
const fsPromises = fs.promises;
const bashScriptPath = path.join(this.dirname, '.bash_set_path')

View File

@ -21,6 +21,7 @@ export class ShellSession extends EventEmitter {
protected nodeShellPod: string;
protected kubectl: Kubectl;
protected kubectlBinDir: string;
protected kubectlPathDir: string;
protected helmBinDir: string;
protected preferences: ClusterPreferences;
protected running = false;
@ -36,8 +37,9 @@ export class ShellSession extends EventEmitter {
}
public async open() {
this.kubectlBinDir = await this.kubectl.binDir()
const pathFromPreferences = userStore.preferences.kubectlBinariesPath || Kubectl.bundledKubectlPath
this.kubectlBinDir = userStore.preferences.downloadKubectlBinaries ? await this.kubectl.binDir() : path.dirname(pathFromPreferences)
this.kubectlPathDir = userStore.preferences.downloadKubectlBinaries ? await this.kubectl.binDir() : path.dirname(pathFromPreferences)
this.helmBinDir = helmCli.getBinaryDir()
const env = await this.getCachedShellEnv()
const shell = env.PTYSHELL
@ -69,11 +71,11 @@ export class ShellSession extends EventEmitter {
protected async getShellArgs(shell: string): Promise<Array<string>> {
switch(path.basename(shell)) {
case "powershell.exe":
return ["-NoExit", "-command", `& {Set-Location $Env:USERPROFILE; $Env:PATH="${this.helmBinDir};${this.kubectlBinDir};$Env:PATH"}`]
return ["-NoExit", "-command", `& {Set-Location $Env:USERPROFILE; $Env:PATH="${this.helmBinDir};${this.kubectlPathDir};$Env:PATH"}`]
case "bash":
return ["--init-file", path.join(this.kubectlBinDir, '.bash_set_path')]
case "fish":
return ["--login", "--init-command", `export PATH="${this.helmBinDir}:${this.kubectlBinDir}:$PATH"; export KUBECONFIG="${this.kubeconfigPath}"`]
return ["--login", "--init-command", `export PATH="${this.helmBinDir}:${this.kubectlPathDir}:$PATH"; export KUBECONFIG="${this.kubeconfigPath}"`]
case "zsh":
return ["--login"]
default: