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

shell env modifiers now take a CatalogEntity in ShellEnvContext param

Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com>
This commit is contained in:
Jim Ehrismann 2022-02-03 18:15:23 -05:00
parent f3d009d216
commit 5e27dd7bbb
4 changed files with 15 additions and 8 deletions

View File

@ -8,6 +8,7 @@ import type { Cluster } from "../../../common/cluster/cluster";
import type WebSocket from "ws";
import createKubectlInjectable from "../../kubectl/create-kubectl.injectable";
import shellEnvModifiersInjectable from "../shell-env-modifier/shell-env-modifier.injectable";
import { catalogEntityRegistry } from "../../catalog";
interface InstantiationParameter {
webSocket: WebSocket;
@ -21,8 +22,9 @@ const localShellSessionInjectable = getInjectable({
const shellEnvModifiers = di.inject(shellEnvModifiersInjectable);
const kubectl = createKubectl(cluster.version);
const entity = catalogEntityRegistry.getById(cluster.id);
return new LocalShellSession(kubectl, shellEnvModifiers.get(), webSocket, cluster, tabId);
return new LocalShellSession(kubectl, shellEnvModifiers.get(), entity, webSocket, cluster, tabId);
},
lifecycle: lifecycleEnum.transient,

View File

@ -25,7 +25,7 @@ export class NodeShellSession extends ShellSession {
protected readonly cwd: string | undefined = undefined;
constructor(protected nodeName: string, kubectl: Kubectl, socket: WebSocket, cluster: Cluster, terminalId: string) {
super(kubectl, [], socket, cluster, terminalId);
super(kubectl, [], undefined, socket, cluster, terminalId);
}
public async open() {

View File

@ -3,10 +3,10 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { CatalogEntity } from "../../../common/catalog";
export interface ShellEnvContext {
context: string;
kubeconfigPath: string;
id: string;
catalogEntity: CatalogEntity;
}
export type ShellEnvModifier = (cluster: ShellEnvContext, env: Record<string, string | undefined>) => Record<string, string | undefined>;
export type ShellEnvModifier = (ctx: ShellEnvContext, env: Record<string, string | undefined>) => Record<string, string | undefined>;

View File

@ -20,6 +20,7 @@ import { TerminalChannels, TerminalMessage } from "../../renderer/api/terminal-a
import { deserialize, serialize } from "v8";
import { stat } from "fs/promises";
import type { ShellEnvModifier } from "./shell-env-modifier/shell-env-modifier-registration";
import type { CatalogEntity } from "../../common/catalog";
export class ShellOpenError extends Error {
constructor(message: string, public cause: Error) {
@ -156,7 +157,7 @@ export abstract class ShellSession {
return { shellProcess, resume };
}
constructor(protected kubectl: Kubectl, protected shellEnvModifiers: ShellEnvModifier[], protected websocket: WebSocket, protected cluster: Cluster, terminalId: string) {
constructor(protected kubectl: Kubectl, protected shellEnvModifiers: ShellEnvModifier[], protected entity: CatalogEntity, protected websocket: WebSocket, protected cluster: Cluster, terminalId: string) {
this.kubeconfigPathP = this.cluster.getProxyKubeconfigPath();
this.kubectlBinDirP = this.kubectl.binDir();
this.terminalId = `${cluster.id}:${terminalId}`;
@ -361,8 +362,12 @@ export abstract class ShellSession {
.filter(Boolean)
.join();
const ctx = { context: this.cluster.contextName, kubeconfigPath, id: this.cluster.id };
console.log("entity in shell-session", this.entity);
console.log(this.entity.spec.kubeconfigPath);
console.log(this.entity.spec.kubeconfigContext);
console.log(this.entity.getId());
const ctx = { catalogEntity: this.entity };
const modifiedEnv = this.shellEnvModifiers.reduce((env, modifier) => modifier(ctx, env), env);
return modifiedEnv;