From 0f89d93e67fb5ecbf18e7fd9e51bf917722c1fed Mon Sep 17 00:00:00 2001 From: Lauri Nevala Date: Wed, 13 Jan 2021 11:25:45 +0200 Subject: [PATCH] Prevent initializing clusters multiple times Signed-off-by: Lauri Nevala --- src/main/cluster-manager.ts | 2 +- src/main/cluster.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/cluster-manager.ts b/src/main/cluster-manager.ts index 5717c7278d..1b468e3bb6 100644 --- a/src/main/cluster-manager.ts +++ b/src/main/cluster-manager.ts @@ -14,7 +14,7 @@ export class ClusterManager extends Singleton { // auto-init clusters autorun(() => { clusterStore.enabledClustersList.forEach(cluster => { - if (!cluster.initialized) { + if (!cluster.initialized && !cluster.initializing) { logger.info(`[CLUSTER-MANAGER]: init cluster`, cluster.getMeta()); cluster.init(port); } diff --git a/src/main/cluster.ts b/src/main/cluster.ts index b9ff62e8ac..176264f8b8 100644 --- a/src/main/cluster.ts +++ b/src/main/cluster.ts @@ -37,6 +37,7 @@ export type ClusterRefreshOptions = { }; export interface ClusterState { + initializing: boolean; initialized: boolean; enabled: boolean; apiUrl: string; @@ -76,6 +77,7 @@ export class Cluster implements ClusterModel, ClusterState { * If extension sets this it needs to also mark cluster as enabled on activate (or when added to a store) */ public ownerRef: string; + public initializing = false; protected kubeconfigManager: KubeconfigManager; protected eventDisposers: Function[] = []; protected activated = false; @@ -273,10 +275,12 @@ export class Cluster implements ClusterModel, ClusterState { */ @action async init(port: number) { try { + this.initializing = true; this.contextHandler = new ContextHandler(this); this.kubeconfigManager = await KubeconfigManager.create(this, this.contextHandler, port); this.kubeProxyUrl = `http://localhost:${port}${apiKubePrefix}`; this.initialized = true; + this.initializing = false; logger.info(`[CLUSTER]: "${this.contextName}" init success`, { id: this.id, context: this.contextName, @@ -575,6 +579,7 @@ export class Cluster implements ClusterModel, ClusterState { */ getState(): ClusterState { const state: ClusterState = { + initializing: this.initializing, initialized: this.initialized, enabled: this.enabled, apiUrl: this.apiUrl,