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

purge ContextHandler's cache on disconnect

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-05-04 13:17:49 -04:00
parent f348ca8ff2
commit 529edc46d8
2 changed files with 12 additions and 19 deletions

View File

@ -313,6 +313,7 @@ export class Cluster implements ClusterModel, ClusterState {
if (this.activated && !force) {
return this.pushState();
}
logger.info(`[CLUSTER]: activate`, this.getMeta());
if (!this.eventDisposers.length) {
@ -330,7 +331,7 @@ export class Cluster implements ClusterModel, ClusterState {
}
this.activated = true;
return this.pushState();
this.pushState();
}
/**

View File

@ -9,12 +9,11 @@ import logger from "./logger";
import { KubeAuthProxy } from "./kube-auth-proxy";
export class ContextHandler {
public proxyPort: number;
public clusterUrl: UrlWithStringQuery;
protected kubeAuthProxy: KubeAuthProxy;
protected apiTarget: httpProxy.ServerOptions;
protected kubeAuthProxy?: KubeAuthProxy;
protected apiTarget?: httpProxy.ServerOptions;
protected prometheusProvider: string;
protected prometheusPath: string;
protected prometheusPath: string | null;
constructor(protected cluster: Cluster) {
this.clusterUrl = url.parse(cluster.apiUrl);
@ -83,24 +82,18 @@ export class ContextHandler {
}
async getApiTarget(isWatchRequest = false): Promise<httpProxy.ServerOptions> {
if (this.apiTarget && !isWatchRequest) {
return this.apiTarget;
}
const timeout = isWatchRequest ? 4 * 60 * 60 * 1000 : 30000; // 4 hours for watch request, 30 seconds for the rest
const apiTarget = await this.newApiTarget(timeout);
if (!isWatchRequest) {
this.apiTarget = apiTarget;
if (isWatchRequest) {
return this.newApiTarget(timeout);
}
return apiTarget;
return this.apiTarget ??= await this.newApiTarget(timeout);
}
protected async newApiTarget(timeout: number): Promise<httpProxy.ServerOptions> {
const proxyUrl = await this.resolveAuthProxyUrl();
return {
target: proxyUrl,
target: await this.resolveAuthProxyUrl(),
changeOrigin: true,
timeout,
headers: {
@ -122,10 +115,9 @@ export class ContextHandler {
}
stopServer() {
if (this.kubeAuthProxy) {
this.kubeAuthProxy.exit();
this.kubeAuthProxy = null;
}
this.kubeAuthProxy?.exit();
this.kubeAuthProxy = undefined;
this.apiTarget = undefined;
}
get proxyLastError(): string {