mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix Lens not clearing other KUBECONFIG env vars
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
1b0f56f417
commit
043f4d1966
@ -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",
|
||||
|
||||
19
src/main/__test__/shell-session.test.ts
Normal file
19
src/main/__test__/shell-session.test.ts
Normal file
@ -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 });
|
||||
});
|
||||
});
|
||||
@ -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<string, any>): Record<string, any> {
|
||||
return Object.fromEntries(
|
||||
Object.entries(env)
|
||||
.filter(([key]) => anyKubeconfig.exec(key) === null)
|
||||
);
|
||||
}
|
||||
|
||||
export class ShellSession extends EventEmitter {
|
||||
static shellEnvs: Map<string, any> = 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();
|
||||
|
||||
@ -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"
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user