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
autorun(() => {
clusterStore.enabledClustersList.forEach(cluster => {
if (!cluster.initialized) {
if (!cluster.initialized && !cluster.initializing) {
logger.info(`[CLUSTER-MANAGER]: init cluster`, cluster.getMeta());
cluster.init(port);
}

View File

@ -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,