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

Fix kube auth proxy race condition (#3458)

* fix race condition by relying on mobx when() to indicate when the kube auth proxy is ready

Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com>

* tweak KubeAuthProxy.run() return behaviour

Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com>
This commit is contained in:
Jim Ehrismann 2021-07-21 11:50:43 -04:00 committed by GitHub
parent cdb7c95b8f
commit b5e6bc36fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -146,8 +146,10 @@ export class ContextHandler {
proxyEnv.HTTPS_PROXY = this.cluster.preferences.httpsProxy;
}
this.kubeAuthProxy = new KubeAuthProxy(this.cluster, proxyEnv);
await this.kubeAuthProxy.run();
this.kubeAuthProxy.run();
}
await this.kubeAuthProxy.whenReady;
}
stopServer() {

View File

@ -27,6 +27,7 @@ import { Kubectl } from "./kubectl";
import logger from "./logger";
import * as url from "url";
import { getPortFrom } from "./utils/get-port";
import { makeObservable, observable, when } from "mobx";
export interface KubeAuthProxyLog {
data: string;
@ -47,8 +48,11 @@ export class KubeAuthProxy {
protected env: NodeJS.ProcessEnv = null;
protected proxyProcess: ChildProcess;
protected kubectl: Kubectl;
@observable protected ready: boolean;
constructor(cluster: Cluster, env: NodeJS.ProcessEnv) {
makeObservable(this);
this.ready = false;
this.env = env;
this.cluster = cluster;
this.kubectl = Kubectl.bundled();
@ -58,9 +62,13 @@ export class KubeAuthProxy {
return url.parse(this.cluster.apiUrl).hostname;
}
get whenReady() {
return when(() => this.ready);
}
public async run(): Promise<void> {
if (this.proxyProcess) {
return;
return this.whenReady;
}
const proxyBin = await this.kubectl.getPath();
@ -103,7 +111,9 @@ export class KubeAuthProxy {
this.sendIpcLogMessage({ data: data.toString() });
});
return waitUntilUsed(this.port, 500, 10000);
await waitUntilUsed(this.port, 500, 10000);
this.ready = true;
}
protected parseError(data: string) {
@ -132,6 +142,7 @@ export class KubeAuthProxy {
}
public exit() {
this.ready = false;
if (!this.proxyProcess) return;
logger.debug("[KUBE-AUTH]: stopping local proxy", this.cluster.getMeta());
this.proxyProcess.kill();