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 (#2297)
This commit is contained in:
parent
5c373a886c
commit
6c872c1aad
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 { appEventBus } from "../common/event-bus";
|
||||||
import { userStore } from "../common/user-store";
|
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 {
|
export class ShellSession extends EventEmitter {
|
||||||
static shellEnvs: Map<string, any> = new Map();
|
static shellEnvs: Map<string, any> = new Map();
|
||||||
|
|
||||||
@ -103,7 +120,7 @@ export class ShellSession extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async getShellEnv() {
|
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);
|
const pathStr = [this.kubectlBinDir, this.helmBinDir, process.env.PATH].join(path.delimiter);
|
||||||
const shell = userStore.preferences.shell || process.env.SHELL || process.env.PTYSHELL;
|
const shell = userStore.preferences.shell || process.env.SHELL || process.env.PTYSHELL;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user