diff --git a/package.json b/package.json index be3e2896bf..fc202e4810 100644 --- a/package.json +++ b/package.json @@ -223,7 +223,7 @@ "mobx-react": "^6.2.2", "mock-fs": "^4.12.0", "moment": "^2.26.0", - "node-pty": "^0.9.0", + "node-pty": "^0.10.0", "npm": "^6.14.8", "openid-client": "^3.15.2", "p-limit": "^3.1.0", diff --git a/src/main/__test__/shell-session.test.ts b/src/main/__test__/shell-session.test.ts new file mode 100644 index 0000000000..fe1b0c4288 --- /dev/null +++ b/src/main/__test__/shell-session.test.ts @@ -0,0 +1,19 @@ +/** + * @jest-environment jsdom + */ + +import { clearKubeconfigEnvVars } from "../shell-session"; + +describe("clearKubeconfigEnvVars tests", () => { + it("should not touch non kubeconfig keys", () => { + expect(clearKubeconfigEnvVars({ a: 1 })).toStrictEqual({ a: 1 }); + }); + + it("should remove a single kubeconfig key", () => { + expect(clearKubeconfigEnvVars({ a: 1, kubeconfig: "1" })).toStrictEqual({ a: 1 }); + }); + + it("should remove a two kubeconfig key", () => { + expect(clearKubeconfigEnvVars({ a: 1, kubeconfig: "1", kUbeconfig: "1" })).toStrictEqual({ a: 1 }); + }); +}); diff --git a/src/main/shell-session.ts b/src/main/shell-session.ts index 10a2f9ed47..76f807a2a5 100644 --- a/src/main/shell-session.ts +++ b/src/main/shell-session.ts @@ -12,6 +12,23 @@ import { isWindows } from "../common/vars"; import { appEventBus } from "../common/event-bus"; import { userStore } from "../common/user-store"; +const anyKubeconfig = /^kubeconfig$/i; + +/** + * This function deletes all keys of the form /^kubeconfig$/i, returning a new + * object. + * + * This is needed because `kubectl` checks for other version of kubeconfig + * before KUBECONFIG and we only set KUBECONFIG. + * @param env The current copy of env + */ +export function clearKubeconfigEnvVars(env: Record): Record { + return Object.fromEntries( + Object.entries(env) + .filter(([key]) => anyKubeconfig.exec(key) === null) + ); +} + export class ShellSession extends EventEmitter { static shellEnvs: Map = new Map(); @@ -103,7 +120,7 @@ export class ShellSession extends EventEmitter { } protected async getShellEnv() { - const env = JSON.parse(JSON.stringify(await shellEnv())); + const env = clearKubeconfigEnvVars(JSON.parse(JSON.stringify(await shellEnv()))); const pathStr = [this.kubectlBinDir, this.helmBinDir, process.env.PATH].join(path.delimiter); if(isWindows) { @@ -132,6 +149,7 @@ export class ShellSession extends EventEmitter { } env["PTYPID"] = process.pid.toString(); + env["KUBECONFIG"] = this.kubeconfigPath; env["TERM_PROGRAM"] = app.getName(); env["TERM_PROGRAM_VERSION"] = app.getVersion(); diff --git a/yarn.lock b/yarn.lock index bc2e606b71..381440b6e4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9533,10 +9533,10 @@ node-notifier@^7.0.0: uuid "^7.0.3" which "^2.0.2" -node-pty@^0.9.0: - version "0.9.0" - resolved "https://registry.yarnpkg.com/node-pty/-/node-pty-0.9.0.tgz#8f9bcc0d1c5b970a3184ffd533d862c7eb6590a6" - integrity sha512-MBnCQl83FTYOu7B4xWw10AW77AAh7ThCE1VXEv+JeWj8mSpGo+0bwgsV+b23ljBFwEM9OmsOv3kM27iUPPm84g== +node-pty@^0.10.0: + version "0.10.0" + resolved "https://registry.yarnpkg.com/node-pty/-/node-pty-0.10.0.tgz#c98d23967b076b35c9fb216c542a04d0b5db4821" + integrity sha512-Q65ookKbjhqWUYKmtZ6iPn0nnqNdzpm3YJOBmzwWJde/TrenBxK9FgqGGtSW0Wjz4YsR1grQF4a7RS5nBwuW9A== dependencies: nan "^2.14.0"