mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
allow to remove cluster from icon's context-menu, random fixes
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
1 parent
33d3181113
commit
e11d8582f1
10 files changed
+88
-299
No files matched your search
@@ -5,23 +5,31 @@ import { ClusterId, clusterStore } from "../common/cluster-store"
|
||||
import { handleMessage } from "../common/ipc";
|
||||
import { tracker } from "../common/tracker";
|
||||
import { Cluster, ClusterIpcEvent } from "./cluster"
|
||||
import logger from "./logger";
|
||||
|
||||
export class ClusterManager {
|
||||
constructor(public readonly port: number) {
|
||||
// auto-init clusters
|
||||
autorun(() => {
|
||||
clusterStore.clustersList
|
||||
.filter(cluster => !cluster.initialized)
|
||||
.forEach(cluster => cluster.init(port));
|
||||
clusterStore.clusters.forEach(cluster => {
|
||||
if (cluster.initialized) return;
|
||||
cluster.init(port);
|
||||
logger.info(`[CLUSTER-MANAGER]: initializing cluster`, cluster.getMeta());
|
||||
});
|
||||
});
|
||||
|
||||
// auto-stop removed clusters
|
||||
autorun(() => {
|
||||
clusterStore.removedClusters.forEach(cluster => cluster.stop());
|
||||
clusterStore.removedClusters.clear();
|
||||
const { removedClusters } = clusterStore;
|
||||
const meta = Array.from(removedClusters.values()).map(cluster => cluster.getMeta());
|
||||
logger.info(`[CLUSTER-MANAGER]: removing clusters`, meta);
|
||||
removedClusters.forEach(cluster => cluster.destroy());
|
||||
removedClusters.clear();
|
||||
}, {
|
||||
delay: 250
|
||||
});
|
||||
|
||||
// listen ipc-events which could be handled *only* in main-process (nodeIntegration=true)
|
||||
// listen for ipc-events that must be handled *only* in main-process (nodeIntegration=true)
|
||||
handleMessage(ClusterIpcEvent.STOP, this.stopCluster.bind(this));
|
||||
}
|
||||
|
||||
@@ -37,7 +45,7 @@ export class ClusterManager {
|
||||
|
||||
protected stopCluster(clusterId: ClusterId) {
|
||||
tracker.event("cluster", "stop");
|
||||
this.getCluster(clusterId)?.stop();
|
||||
this.getCluster(clusterId)?.destroy();
|
||||
}
|
||||
|
||||
getClusterForRequest(req: http.IncomingMessage): Cluster {
|
||||
|
||||
+25
-5
@@ -24,6 +24,7 @@ export enum ClusterStatus {
|
||||
}
|
||||
|
||||
export interface ClusterState extends ClusterModel {
|
||||
initialized?: boolean;
|
||||
apiUrl: string;
|
||||
online?: boolean;
|
||||
accessible?: boolean;
|
||||
@@ -98,12 +99,13 @@ export class Cluster implements ClusterModel {
|
||||
|
||||
bindEvents(viewId: number) {
|
||||
if (!this.initialized) return;
|
||||
logger.info(`[CLUSTER]: bind events`, this.getMeta());
|
||||
const refreshStatusTimer = setInterval(() => this.refreshStatus(), 30000); // every 30s
|
||||
const refreshEventsTimer = setInterval(() => this.refreshEvents(), 3000); // every 3s
|
||||
|
||||
this.disposers.push(
|
||||
() => clearTimeout(refreshStatusTimer),
|
||||
() => clearTimeout(refreshEventsTimer),
|
||||
() => clearInterval(refreshStatusTimer),
|
||||
() => clearInterval(refreshEventsTimer),
|
||||
|
||||
reaction(() => this.getState(), clusterState => {
|
||||
sendMessage({
|
||||
@@ -118,15 +120,24 @@ export class Cluster implements ClusterModel {
|
||||
}
|
||||
|
||||
unbindEvents() {
|
||||
if (!this.initialized) return;
|
||||
logger.info(`[CLUSTER]: unbind events`, this.getMeta());
|
||||
this.disposers.forEach(dispose => dispose());
|
||||
this.disposers.length = 0;
|
||||
}
|
||||
|
||||
stop() {
|
||||
if (!this.initialized) return;
|
||||
this.contextHandler.stopServer();
|
||||
this.kubeconfigManager.unlink();
|
||||
this.unbindEvents();
|
||||
}
|
||||
|
||||
destroy() {
|
||||
try {
|
||||
this.stop();
|
||||
this.unbindEvents();
|
||||
this.kubeconfigManager.unlink();
|
||||
} catch (err) {
|
||||
logger.error(`[CLUSTER]: destroy() throws: ${err}`, this.getMeta());
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
@@ -318,6 +329,7 @@ export class Cluster implements ClusterModel {
|
||||
getState(): ClusterState {
|
||||
const state: ClusterState = {
|
||||
...this.toJSON(),
|
||||
initialized: this.initialized,
|
||||
apiUrl: this.apiUrl,
|
||||
online: this.online,
|
||||
accessible: this.accessible,
|
||||
@@ -333,4 +345,12 @@ export class Cluster implements ClusterModel {
|
||||
recurseEverything: true
|
||||
})
|
||||
}
|
||||
|
||||
// get cluster system meta, e.g. use in "logger"
|
||||
getMeta() {
|
||||
return {
|
||||
id: this.id,
|
||||
name: this.contextName,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ export class KubeconfigManager {
|
||||
}
|
||||
|
||||
unlink() {
|
||||
logger.debug('Deleting temporary kubeconfig: ' + this.tempFile)
|
||||
logger.info('Deleting temporary kubeconfig: ' + this.tempFile)
|
||||
fs.unlinkSync(this.tempFile)
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,6 @@ export class WindowManager {
|
||||
}
|
||||
}, {
|
||||
fireImmediately: true,
|
||||
delay: 250,
|
||||
}),
|
||||
|
||||
// auto-destroy views for removed clusters
|
||||
|
||||
Reference in new issue
Block a user