diff --git a/src/main/cluster-manager.ts b/src/main/cluster-manager.ts index ff5eaae32d..302317e52e 100644 --- a/src/main/cluster-manager.ts +++ b/src/main/cluster-manager.ts @@ -44,7 +44,7 @@ export class ClusterManager { // lens-server is connecting to 127.0.0.1:/ if (req.headers.host.startsWith("127.0.0.1")) { const clusterId = req.url.split("/")[1] - const cluster = clusterStore.getById(clusterId) + cluster = clusterStore.getById(clusterId) if (cluster) { // we need to swap path prefix so that request is proxied to kube api req.url = req.url.replace(`/${clusterId}`, apiKubePrefix) diff --git a/src/main/cluster.ts b/src/main/cluster.ts index a4ba94a75f..e5aa60adfc 100644 --- a/src/main/cluster.ts +++ b/src/main/cluster.ts @@ -92,7 +92,7 @@ export class Cluster implements ClusterModel { async init(port: number) { try { this.contextHandler = new ContextHandler(this); - this.kubeconfigManager = new KubeconfigManager(this, this.contextHandler); + this.kubeconfigManager = new KubeconfigManager(this, this.contextHandler, port); this.kubeProxyUrl = `http://localhost:${port}${apiKubePrefix}`; this.initialized = true; logger.info(`[CLUSTER]: "${this.contextName}" init success`, { diff --git a/src/main/context-handler.ts b/src/main/context-handler.ts index a3cf6185dd..ce8becae4d 100644 --- a/src/main/context-handler.ts +++ b/src/main/context-handler.ts @@ -68,7 +68,7 @@ export class ContextHandler { return this.prometheusPath; } - async resolveAuthProxyUrl() { + protected async resolveAuthProxyUrl() { const proxyPort = await this.ensurePort(); const path = this.clusterUrl.path !== "/" ? this.clusterUrl.path : "" return `http://127.0.0.1:${proxyPort}${path}`; diff --git a/src/main/kubeconfig-manager.ts b/src/main/kubeconfig-manager.ts index f7d85e3a24..59a47c3fbc 100644 --- a/src/main/kubeconfig-manager.ts +++ b/src/main/kubeconfig-manager.ts @@ -11,7 +11,7 @@ export class KubeconfigManager { protected configDir = app.getPath("temp") protected tempFile: string; - constructor(protected cluster: Cluster, protected contextHandler: ContextHandler) { + constructor(protected cluster: Cluster, protected contextHandler: ContextHandler, protected port: number) { this.init(); } @@ -28,6 +28,10 @@ export class KubeconfigManager { return this.tempFile; } + protected resolveProxyUrl() { + return `http://127.0.0.1:${this.port}/${this.cluster.id}` + } + /** * Creates new "temporary" kubeconfig that point to the kubectl-proxy. * This way any user of the config does not need to know anything about the auth etc. details. @@ -42,7 +46,7 @@ export class KubeconfigManager { clusters: [ { name: contextName, - server: await contextHandler.resolveAuthProxyUrl(), + server: this.resolveProxyUrl(), skipTLSVerify: undefined, } ],