diff --git a/src/main/kubectl.ts b/src/main/kubectl.ts index 1842d46307..91b024e292 100644 --- a/src/main/kubectl.ts +++ b/src/main/kubectl.ts @@ -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 { - if (!userStore.preferences.downloadKubectlBinaries) { + if (userStore.preferences?.downloadKubectlBinaries === false) { return this.getPathFromPreferences() } @@ -193,7 +193,7 @@ export class Kubectl { } public async ensureKubectl(): Promise { - 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') diff --git a/src/main/shell-session.ts b/src/main/shell-session.ts index 77f767cfea..80a55f46db 100644 --- a/src/main/shell-session.ts +++ b/src/main/shell-session.ts @@ -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> { 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: