mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
remove removedClusters from ClusterStore
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
9e75016247
commit
b102ac7d9f
@ -111,7 +111,6 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@observable activeCluster: ClusterId;
|
@observable activeCluster: ClusterId;
|
||||||
@observable removedClusters = observable.map<ClusterId, Cluster>();
|
|
||||||
@observable clusters = observable.map<ClusterId, Cluster>();
|
@observable clusters = observable.map<ClusterId, Cluster>();
|
||||||
|
|
||||||
private static stateRequestChannel = "cluster:states";
|
private static stateRequestChannel = "cluster:states";
|
||||||
@ -290,7 +289,6 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
protected fromStore({ activeCluster, clusters = [] }: ClusterStoreModel = {}) {
|
protected fromStore({ activeCluster, clusters = [] }: ClusterStoreModel = {}) {
|
||||||
const currentClusters = this.clusters.toJS();
|
const currentClusters = this.clusters.toJS();
|
||||||
const newClusters = new Map<ClusterId, Cluster>();
|
const newClusters = new Map<ClusterId, Cluster>();
|
||||||
const removedClusters = new Map<ClusterId, Cluster>();
|
|
||||||
|
|
||||||
// update new clusters
|
// update new clusters
|
||||||
for (const clusterModel of clusters) {
|
for (const clusterModel of clusters) {
|
||||||
@ -308,16 +306,8 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// update removed clusters
|
|
||||||
currentClusters.forEach(cluster => {
|
|
||||||
if (!newClusters.has(cluster.id)) {
|
|
||||||
removedClusters.set(cluster.id, cluster);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.setActive(activeCluster);
|
this.setActive(activeCluster);
|
||||||
this.clusters.replace(newClusters);
|
this.clusters.replace(newClusters);
|
||||||
this.removedClusters.replace(removedClusters);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toJSON(): ClusterStoreModel {
|
toJSON(): ClusterStoreModel {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import "../common/cluster-ipc";
|
import "../common/cluster-ipc";
|
||||||
import type http from "http";
|
import type http from "http";
|
||||||
import { ipcMain } from "electron";
|
import { ipcMain } from "electron";
|
||||||
import { action, autorun, reaction, toJS } from "mobx";
|
import { action, reaction, toJS } from "mobx";
|
||||||
import { ClusterStore, getClusterIdFromHost } from "../common/cluster-store";
|
import { ClusterStore, getClusterIdFromHost } from "../common/cluster-store";
|
||||||
import { Cluster } from "./cluster";
|
import { Cluster } from "./cluster";
|
||||||
import logger from "./logger";
|
import logger from "./logger";
|
||||||
@ -22,22 +22,6 @@ export class ClusterManager extends Singleton {
|
|||||||
this.syncClustersFromCatalog(entities);
|
this.syncClustersFromCatalog(entities);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// auto-stop removed clusters
|
|
||||||
autorun(() => {
|
|
||||||
const removedClusters = Array.from(ClusterStore.getInstance().removedClusters.values());
|
|
||||||
|
|
||||||
if (removedClusters.length > 0) {
|
|
||||||
const meta = removedClusters.map(cluster => cluster.getMeta());
|
|
||||||
|
|
||||||
logger.info(`[CLUSTER-MANAGER]: removing clusters`, meta);
|
|
||||||
removedClusters.forEach(cluster => cluster.disconnect());
|
|
||||||
ClusterStore.getInstance().removedClusters.clear();
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
delay: 250
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMain.on("network:offline", () => { this.onNetworkOffline(); });
|
ipcMain.on("network:offline", () => { this.onNetworkOffline(); });
|
||||||
ipcMain.on("network:online", () => { this.onNetworkOnline(); });
|
ipcMain.on("network:online", () => { this.onNetworkOnline(); });
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import { app, remote } from "electron";
|
|||||||
import { observable, reaction, when } from "mobx";
|
import { observable, reaction, when } from "mobx";
|
||||||
import fse from "fs-extra";
|
import fse from "fs-extra";
|
||||||
import { StorageHelper } from "./storageHelper";
|
import { StorageHelper } from "./storageHelper";
|
||||||
import { ClusterStore, getHostedClusterId } from "../../common/cluster-store";
|
import { getHostedClusterId } from "../../common/cluster-store";
|
||||||
import logger from "../../main/logger";
|
import logger from "../../main/logger";
|
||||||
|
|
||||||
let initialized = false;
|
let initialized = false;
|
||||||
@ -31,10 +31,8 @@ export function createStorage<T>(key: string, defaultValue: T, observableOptions
|
|||||||
// bind auto-saving
|
// bind auto-saving
|
||||||
reaction(() => storage.toJSON(), saveFile, { delay: 250 });
|
reaction(() => storage.toJSON(), saveFile, { delay: 250 });
|
||||||
|
|
||||||
// remove json-file when cluster deleted
|
// We don't clean up the cluster because it might come back in the future
|
||||||
if (clusterId !== undefined) {
|
// as cluster IDs are now deterministic based on "path" + "contextName"
|
||||||
when(() => ClusterStore.getInstance(false)?.removedClusters.has(clusterId)).then(removeFile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveFile(json = {}) {
|
async function saveFile(json = {}) {
|
||||||
@ -46,11 +44,6 @@ export function createStorage<T>(key: string, defaultValue: T, observableOptions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeFile() {
|
|
||||||
logger.debug("[remove]:", jsonFilePath);
|
|
||||||
fse.unlink(jsonFilePath).catch(Function);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new StorageHelper<T>(key, {
|
return new StorageHelper<T>(key, {
|
||||||
autoInit: true,
|
autoInit: true,
|
||||||
observable: observableOptions,
|
observable: observableOptions,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user