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

Fix circular dep

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-06-17 10:26:36 -04:00
parent 3cffaaab43
commit a1254d9d85
2 changed files with 9 additions and 6 deletions

View File

@ -146,8 +146,11 @@ app.on("ready", async () => {
filesystemStore.load(),
]);
const lensProxy = LensProxy.createInstance(handleWsUpgrade);
const lensProxy = LensProxy.createInstance(
handleWsUpgrade,
req => ClusterManager.getInstance().getClusterForRequest(req),
);
ClusterManager.createInstance().init();
KubeconfigSyncManager.createInstance();

View File

@ -29,7 +29,7 @@ import { Router } from "../router";
import type { ContextHandler } from "../context-handler";
import logger from "../logger";
import { Singleton } from "../../common/utils";
import { ClusterManager } from "../cluster-manager";
import type { Cluster } from "../cluster";
type WSUpgradeHandler = (req: http.IncomingMessage, socket: net.Socket, head: Buffer) => void;
@ -42,7 +42,7 @@ export class LensProxy extends Singleton {
public port: number;
constructor(handleWsUpgrade: WSUpgradeHandler) {
constructor(handleWsUpgrade: WSUpgradeHandler, protected getClusterForRequest: (req: http.IncomingMessage) => Cluster | undefined) {
super();
const proxy = this.createProxy();
@ -104,7 +104,7 @@ export class LensProxy extends Singleton {
}
protected async handleProxyUpgrade(proxy: httpProxy, req: http.IncomingMessage, socket: net.Socket, head: Buffer) {
const cluster = ClusterManager.getInstance().getClusterForRequest(req);
const cluster = this.getClusterForRequest(req);
if (cluster) {
const proxyUrl = await cluster.contextHandler.resolveAuthProxyUrl() + req.url.replace(apiKubePrefix, "");
@ -220,7 +220,7 @@ export class LensProxy extends Singleton {
}
protected async handleRequest(proxy: httpProxy, req: http.IncomingMessage, res: http.ServerResponse) {
const cluster = ClusterManager.getInstance().getClusterForRequest(req);
const cluster = this.getClusterForRequest(req);
if (cluster) {
const proxyTarget = await this.getProxyTarget(req, cluster.contextHandler);