From 6cbb87705fbb20f87a6f61e4fbe7491bf66d473b Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Tue, 9 Aug 2022 15:01:15 -0400 Subject: [PATCH] Use new createKubeJsonApiForClusterInjectable for openNodeShellSession Signed-off-by: Sebastian Malton --- .../node-shell-session/node-shell-session.ts | 10 +++++++--- .../node-shell-session/open.injectable.ts | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/shell-session/node-shell-session/node-shell-session.ts b/src/main/shell-session/node-shell-session/node-shell-session.ts index 7a2ab09cd7..6a8af4c09e 100644 --- a/src/main/shell-session/node-shell-session/node-shell-session.ts +++ b/src/main/shell-session/node-shell-session/node-shell-session.ts @@ -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 }); diff --git a/src/main/shell-session/node-shell-session/open.injectable.ts b/src/main/shell-session/node-shell-session/open.injectable.ts index bc9224eb8f..e0b5ddb65c 100644 --- a/src/main/shell-session/node-shell-session/open.injectable.ts +++ b/src/main/shell-session/node-shell-session/open.injectable.ts @@ -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) => {