From a1254d9d85111c5b3448b640c7b9111c5bc3e2e0 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Thu, 17 Jun 2021 10:26:36 -0400 Subject: [PATCH] Fix circular dep Signed-off-by: Sebastian Malton --- src/main/index.ts | 7 +++++-- src/main/proxy/lens-proxy.ts | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 3afec9a51b..aba3d73ce1 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -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(); diff --git a/src/main/proxy/lens-proxy.ts b/src/main/proxy/lens-proxy.ts index 199d48398b..00ef5fbb48 100644 --- a/src/main/proxy/lens-proxy.ts +++ b/src/main/proxy/lens-proxy.ts @@ -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);