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

Use new createKubeJsonApiForClusterInjectable for openNodeShellSession

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-08-09 15:01:15 -04:00
parent a0e15c453f
commit 6cbb87705f
2 changed files with 11 additions and 5 deletions

View File

@ -10,13 +10,17 @@ import type { ShellSessionArgs, ShellSessionDependencies } from "../shell-sessio
import { ShellOpenError, ShellSession } from "../shell-session";
import { get, once } from "lodash";
import { Node, NodeApi } from "../../../common/k8s-api/endpoints";
import { KubeJsonApi } from "../../../common/k8s-api/kube-json-api";
import { TerminalChannels } from "../../../common/terminal/channels";
import type { CreateKubeJsonApiForCluster } from "../../../common/k8s-api/create-kube-json-api-for-cluster.injectable";
export interface NodeShellSessionArgs extends ShellSessionArgs {
nodeName: string;
}
export interface NodeShellSessionDependencies extends ShellSessionDependencies {
createKubeJsonApiForCluster: CreateKubeJsonApiForCluster;
}
export class NodeShellSession extends ShellSession {
ShellType = "node-shell";
@ -24,7 +28,7 @@ export class NodeShellSession extends ShellSession {
protected readonly nodeName: string;
protected readonly cwd: string | undefined = undefined;
constructor(dependencies: ShellSessionDependencies, { nodeName, ...args }: NodeShellSessionArgs) {
constructor(protected readonly dependencies: NodeShellSessionDependencies, { nodeName, ...args }: NodeShellSessionArgs) {
super(dependencies, args);
this.nodeName = nodeName;
}
@ -65,7 +69,7 @@ export class NodeShellSession extends ShellSession {
const args = ["exec", "-i", "-t", "-n", "kube-system", this.podName, "--"];
const nodeApi = new NodeApi({
objectConstructor: Node,
request: KubeJsonApi.forCluster(this.cluster.id),
request: this.dependencies.createKubeJsonApiForCluster(this.cluster.id),
});
const node = await nodeApi.get({ name: this.nodeName });

View File

@ -6,11 +6,12 @@ import { getInjectable } from "@ogre-tools/injectable";
import type { Cluster } from "../../../common/cluster/cluster";
import type WebSocket from "ws";
import createKubectlInjectable from "../../kubectl/create-kubectl.injectable";
import type { NodeShellSessionDependencies } from "./node-shell-session";
import { NodeShellSession } from "./node-shell-session";
import type { ShellSessionDependencies } from "../shell-session";
import isMacInjectable from "../../../common/vars/is-mac.injectable";
import isWindowsInjectable from "../../../common/vars/is-windows.injectable";
import loggerInjectable from "../../../common/logger.injectable";
import createKubeJsonApiForClusterInjectable from "../../../common/k8s-api/create-kube-json-api-for-cluster.injectable";
export interface NodeShellSessionArgs {
websocket: WebSocket;
@ -25,10 +26,11 @@ const openNodeShellSessionInjectable = getInjectable({
id: "open-node-shell-session",
instantiate: (di): OpenNodeShellSession => {
const createKubectl = di.inject(createKubectlInjectable);
const dependencies: ShellSessionDependencies = {
const dependencies: NodeShellSessionDependencies = {
isMac: di.inject(isMacInjectable),
isWindows: di.inject(isWindowsInjectable),
logger: di.inject(loggerInjectable),
createKubeJsonApiForCluster: di.inject(createKubeJsonApiForClusterInjectable),
};
return (args) => {