cluster-manager view

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman committed 2020-07-10 12:47:50 +03:00
1 parent b05ed9822d
commit 6df56b5471
24 files changed
+167 -141

No files matched your search

+1 -2
View File
@@ -78,8 +78,7 @@ export class Cluster implements ClusterModel {
this.contextHandler = new ContextHandler(this);
const proxyPort = await this.contextHandler.resolveProxyPort();
this.kubeconfigManager = new KubeconfigManager(this, proxyPort);
this.url = this.contextHandler.url
// todo: verify api url
this.url = this.contextHandler.url;
// this.apiUrl = kubeConfig.getCurrentCluster().server;
this.initialized = true;
logger.debug(`[CLUSTER]: init done (id="${this.id}", context="${this.contextName}")`);
+2 -7
View File
@@ -111,12 +111,7 @@ export class ContextHandler {
async resolveProxyPort(): Promise<number> {
if (!this.proxyPort) {
try {
this.proxyPort = await getFreePort()
} catch (error) {
logger.error(error)
throw(error)
}
this.proxyPort = await getFreePort()
}
return this.proxyPort
}
@@ -133,7 +128,7 @@ export class ContextHandler {
if (!this.proxyServer) {
const proxyPort = await this.resolveProxyPort()
const proxyEnv = Object.assign({}, process.env)
if (this.cluster?.preferences.httpsProxy) {
if (this.cluster.preferences.httpsProxy) {
proxyEnv.HTTPS_PROXY = this.cluster.preferences.httpsProxy
}
this.proxyServer = new KubeAuthProxy(this.cluster, proxyPort, proxyEnv)
+1 -1
View File
@@ -6,7 +6,7 @@ import { app, dialog } from "electron"
import { appName, appProto, isMac, staticDir, staticProto } from "../common/vars";
import path from "path"
import initMenu from "./menu"
import { LensProxy, listen } from "./proxy"
import { LensProxy, listen } from "./lens-proxy"
import { WindowManager } from "./window-manager";
import { ClusterManager } from "./cluster-manager";
import AppUpdater from "./app-updater"
+14 -24
View File
@@ -4,27 +4,20 @@ import { Socket } from "net";
import * as url from "url";
import * as WebSocket from "ws"
import { ContextHandler } from "./context-handler";
import logger from "./logger"
import * as shell from "./node-shell-session"
import { ClusterManager } from "./cluster-manager"
import { Router } from "./router"
import { apiPrefix } from "../common/vars";
import logger from "./logger"
export class LensProxy {
public static readonly localShellSessions = true
public port: number;
protected clusterUrl: url.UrlWithStringQuery
protected clusterManager: ClusterManager
protected retryCounters: Map<string, number> = new Map()
protected router: Router
protected proxyServer: http.Server
protected router: Router
protected closed = false
protected retryCounters = new Map<string, number>()
constructor(port: number, clusterManager: ClusterManager) {
this.port = port
this.clusterManager = clusterManager
this.router = new Router()
constructor(public port: number, protected clusterManager: ClusterManager) {
this.router = new Router();
}
public run() {
@@ -34,7 +27,7 @@ export class LensProxy {
}
public close() {
logger.info("Closing proxy server")
logger.info(`Closing proxy server at port ${this.port}`);
this.proxyServer.close()
this.closed = true
}
@@ -77,9 +70,7 @@ export class LensProxy {
}
})
proxy.on("error", (error, req, res, target) => {
if(this.closed) {
return
}
if (this.closed) return;
if (target) {
logger.debug("Failed proxy to target: " + JSON.stringify(target))
if (req.method === "GET" && (!res.statusCode || res.statusCode >= 500)) {
@@ -142,14 +133,13 @@ export class LensProxy {
return
}
const contextHandler = cluster.contextHandler
contextHandler.ensureServer().then(async () => {
const proxyTarget = await this.getProxyTarget(req, contextHandler)
if (proxyTarget) {
proxy.web(req, res, proxyTarget)
} else {
this.router.route(cluster, req, res)
}
})
await contextHandler.ensureServer();
const proxyTarget = await this.getProxyTarget(req, contextHandler)
if (proxyTarget) {
proxy.web(req, res, proxyTarget)
} else {
this.router.route(cluster, req, res)
}
}
protected async handleWsUpgrade(req: http.IncomingMessage, socket: Socket, head: Buffer) {