mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Allow users to disconnect from clusters that fail to connect (#3231)
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
020acd1c40
commit
223dadc073
@ -55,8 +55,10 @@ export interface KubernetesClusterSpec extends CatalogEntitySpec {
|
||||
};
|
||||
}
|
||||
|
||||
export type KubernetesClusterStatusPhase = "connected" | "connecting" | "disconnected" | "deleting";
|
||||
|
||||
export interface KubernetesClusterStatus extends CatalogEntityStatus {
|
||||
phase: "connected" | "disconnected" | "deleting";
|
||||
phase: KubernetesClusterStatusPhase;
|
||||
}
|
||||
|
||||
export class KubernetesCluster extends CatalogEntity<CatalogEntityMetadata, KubernetesClusterStatus, KubernetesClusterSpec> {
|
||||
@ -65,34 +67,18 @@ export class KubernetesCluster extends CatalogEntity<CatalogEntityMetadata, Kube
|
||||
|
||||
async connect(): Promise<void> {
|
||||
if (app) {
|
||||
const cluster = ClusterStore.getInstance().getById(this.metadata.uid);
|
||||
|
||||
if (!cluster) return;
|
||||
|
||||
await cluster.activate();
|
||||
|
||||
return;
|
||||
await ClusterStore.getInstance().getById(this.metadata.uid)?.activate();
|
||||
} else {
|
||||
await requestMain(clusterActivateHandler, this.metadata.uid, false);
|
||||
}
|
||||
|
||||
await requestMain(clusterActivateHandler, this.metadata.uid, false);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
async disconnect(): Promise<void> {
|
||||
if (app) {
|
||||
const cluster = ClusterStore.getInstance().getById(this.metadata.uid);
|
||||
|
||||
if (!cluster) return;
|
||||
|
||||
cluster.disconnect();
|
||||
|
||||
return;
|
||||
ClusterStore.getInstance().getById(this.metadata.uid)?.disconnect();
|
||||
} else {
|
||||
await requestMain(clusterDisconnectHandler, this.metadata.uid, false);
|
||||
}
|
||||
|
||||
await requestMain(clusterDisconnectHandler, this.metadata.uid, false);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
async onRun(context: CatalogEntityActionContext) {
|
||||
@ -130,23 +116,27 @@ export class KubernetesCluster extends CatalogEntity<CatalogEntityMetadata, Kube
|
||||
);
|
||||
}
|
||||
|
||||
if (this.status.phase == "connected") {
|
||||
context.menuItems.push({
|
||||
title: "Disconnect",
|
||||
icon: "link_off",
|
||||
onClick: () => requestMain(clusterDisconnectHandler, this.metadata.uid)
|
||||
});
|
||||
} else {
|
||||
context.menuItems.push({
|
||||
title: "Connect",
|
||||
icon: "link",
|
||||
onClick: () => context.navigate(`/cluster/${this.metadata.uid}`)
|
||||
});
|
||||
switch (this.status.phase) {
|
||||
case "connected":
|
||||
case "connecting":
|
||||
context.menuItems.push({
|
||||
title: "Disconnect",
|
||||
icon: "link_off",
|
||||
onClick: () => requestMain(clusterDisconnectHandler, this.metadata.uid)
|
||||
});
|
||||
break;
|
||||
case "disconnected":
|
||||
context.menuItems.push({
|
||||
title: "Connect",
|
||||
icon: "link",
|
||||
onClick: () => context.navigate(`/cluster/${this.metadata.uid}`)
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
const category = catalogCategoryRegistry.getCategoryForEntity<KubernetesClusterCategory>(this);
|
||||
|
||||
if (category) category.emit("contextMenuOpen", this, context);
|
||||
catalogCategoryRegistry
|
||||
.getCategoryForEntity<KubernetesClusterCategory>(this)
|
||||
?.emit("contextMenuOpen", this, context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ import logger from "./logger";
|
||||
import { apiKubePrefix } from "../common/vars";
|
||||
import { Singleton } from "../common/utils";
|
||||
import { catalogEntityRegistry } from "./catalog";
|
||||
import { KubernetesCluster, KubernetesClusterPrometheusMetrics } from "../common/catalog-entities/kubernetes-cluster";
|
||||
import { KubernetesCluster, KubernetesClusterPrometheusMetrics, KubernetesClusterStatusPhase } from "../common/catalog-entities/kubernetes-cluster";
|
||||
import { ipcMainOn } from "../common/ipc";
|
||||
import { once } from "lodash";
|
||||
|
||||
@ -136,7 +136,22 @@ export class ClusterManager extends Singleton {
|
||||
entity.status.phase = "deleting";
|
||||
entity.status.enabled = false;
|
||||
} else {
|
||||
entity.status.phase = cluster?.accessible ? "connected" : "disconnected";
|
||||
entity.status.phase = ((): KubernetesClusterStatusPhase => {
|
||||
if (!cluster) {
|
||||
return "disconnected";
|
||||
}
|
||||
|
||||
if (cluster.accessible) {
|
||||
return "connected";
|
||||
}
|
||||
|
||||
if (!cluster.disconnected) {
|
||||
return "connecting";
|
||||
}
|
||||
|
||||
return "disconnected";
|
||||
})();
|
||||
|
||||
entity.status.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user