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

Prevent initializing clusters multiple times

Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
Lauri Nevala 2021-01-13 11:25:45 +02:00
parent 11595abc93
commit 0f89d93e67
2 changed files with 6 additions and 1 deletions

View File

@ -14,7 +14,7 @@ export class ClusterManager extends Singleton {
// auto-init clusters // auto-init clusters
autorun(() => { autorun(() => {
clusterStore.enabledClustersList.forEach(cluster => { clusterStore.enabledClustersList.forEach(cluster => {
if (!cluster.initialized) { if (!cluster.initialized && !cluster.initializing) {
logger.info(`[CLUSTER-MANAGER]: init cluster`, cluster.getMeta()); logger.info(`[CLUSTER-MANAGER]: init cluster`, cluster.getMeta());
cluster.init(port); cluster.init(port);
} }

View File

@ -37,6 +37,7 @@ export type ClusterRefreshOptions = {
}; };
export interface ClusterState { export interface ClusterState {
initializing: boolean;
initialized: boolean; initialized: boolean;
enabled: boolean; enabled: boolean;
apiUrl: string; 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) * If extension sets this it needs to also mark cluster as enabled on activate (or when added to a store)
*/ */
public ownerRef: string; public ownerRef: string;
public initializing = false;
protected kubeconfigManager: KubeconfigManager; protected kubeconfigManager: KubeconfigManager;
protected eventDisposers: Function[] = []; protected eventDisposers: Function[] = [];
protected activated = false; protected activated = false;
@ -273,10 +275,12 @@ export class Cluster implements ClusterModel, ClusterState {
*/ */
@action async init(port: number) { @action async init(port: number) {
try { try {
this.initializing = true;
this.contextHandler = new ContextHandler(this); this.contextHandler = new ContextHandler(this);
this.kubeconfigManager = await KubeconfigManager.create(this, this.contextHandler, port); this.kubeconfigManager = await KubeconfigManager.create(this, this.contextHandler, port);
this.kubeProxyUrl = `http://localhost:${port}${apiKubePrefix}`; this.kubeProxyUrl = `http://localhost:${port}${apiKubePrefix}`;
this.initialized = true; this.initialized = true;
this.initializing = false;
logger.info(`[CLUSTER]: "${this.contextName}" init success`, { logger.info(`[CLUSTER]: "${this.contextName}" init success`, {
id: this.id, id: this.id,
context: this.contextName, context: this.contextName,
@ -575,6 +579,7 @@ export class Cluster implements ClusterModel, ClusterState {
*/ */
getState(): ClusterState { getState(): ClusterState {
const state: ClusterState = { const state: ClusterState = {
initializing: this.initializing,
initialized: this.initialized, initialized: this.initialized,
enabled: this.enabled, enabled: this.enabled,
apiUrl: this.apiUrl, apiUrl: this.apiUrl,