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 {
|
export interface KubernetesClusterStatus extends CatalogEntityStatus {
|
||||||
phase: "connected" | "disconnected" | "deleting";
|
phase: KubernetesClusterStatusPhase;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class KubernetesCluster extends CatalogEntity<CatalogEntityMetadata, KubernetesClusterStatus, KubernetesClusterSpec> {
|
export class KubernetesCluster extends CatalogEntity<CatalogEntityMetadata, KubernetesClusterStatus, KubernetesClusterSpec> {
|
||||||
@ -65,34 +67,18 @@ export class KubernetesCluster extends CatalogEntity<CatalogEntityMetadata, Kube
|
|||||||
|
|
||||||
async connect(): Promise<void> {
|
async connect(): Promise<void> {
|
||||||
if (app) {
|
if (app) {
|
||||||
const cluster = ClusterStore.getInstance().getById(this.metadata.uid);
|
await ClusterStore.getInstance().getById(this.metadata.uid)?.activate();
|
||||||
|
} else {
|
||||||
if (!cluster) return;
|
await requestMain(clusterActivateHandler, this.metadata.uid, false);
|
||||||
|
|
||||||
await cluster.activate();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await requestMain(clusterActivateHandler, this.metadata.uid, false);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async disconnect(): Promise<void> {
|
async disconnect(): Promise<void> {
|
||||||
if (app) {
|
if (app) {
|
||||||
const cluster = ClusterStore.getInstance().getById(this.metadata.uid);
|
ClusterStore.getInstance().getById(this.metadata.uid)?.disconnect();
|
||||||
|
} else {
|
||||||
if (!cluster) return;
|
await requestMain(clusterDisconnectHandler, this.metadata.uid, false);
|
||||||
|
|
||||||
cluster.disconnect();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await requestMain(clusterDisconnectHandler, this.metadata.uid, false);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async onRun(context: CatalogEntityActionContext) {
|
async onRun(context: CatalogEntityActionContext) {
|
||||||
@ -130,23 +116,27 @@ export class KubernetesCluster extends CatalogEntity<CatalogEntityMetadata, Kube
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.status.phase == "connected") {
|
switch (this.status.phase) {
|
||||||
context.menuItems.push({
|
case "connected":
|
||||||
title: "Disconnect",
|
case "connecting":
|
||||||
icon: "link_off",
|
context.menuItems.push({
|
||||||
onClick: () => requestMain(clusterDisconnectHandler, this.metadata.uid)
|
title: "Disconnect",
|
||||||
});
|
icon: "link_off",
|
||||||
} else {
|
onClick: () => requestMain(clusterDisconnectHandler, this.metadata.uid)
|
||||||
context.menuItems.push({
|
});
|
||||||
title: "Connect",
|
break;
|
||||||
icon: "link",
|
case "disconnected":
|
||||||
onClick: () => context.navigate(`/cluster/${this.metadata.uid}`)
|
context.menuItems.push({
|
||||||
});
|
title: "Connect",
|
||||||
|
icon: "link",
|
||||||
|
onClick: () => context.navigate(`/cluster/${this.metadata.uid}`)
|
||||||
|
});
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const category = catalogCategoryRegistry.getCategoryForEntity<KubernetesClusterCategory>(this);
|
catalogCategoryRegistry
|
||||||
|
.getCategoryForEntity<KubernetesClusterCategory>(this)
|
||||||
if (category) category.emit("contextMenuOpen", this, context);
|
?.emit("contextMenuOpen", this, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -28,7 +28,7 @@ import logger from "./logger";
|
|||||||
import { apiKubePrefix } from "../common/vars";
|
import { apiKubePrefix } from "../common/vars";
|
||||||
import { Singleton } from "../common/utils";
|
import { Singleton } from "../common/utils";
|
||||||
import { catalogEntityRegistry } from "./catalog";
|
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 { ipcMainOn } from "../common/ipc";
|
||||||
import { once } from "lodash";
|
import { once } from "lodash";
|
||||||
|
|
||||||
@ -136,7 +136,22 @@ export class ClusterManager extends Singleton {
|
|||||||
entity.status.phase = "deleting";
|
entity.status.phase = "deleting";
|
||||||
entity.status.enabled = false;
|
entity.status.enabled = false;
|
||||||
} else {
|
} 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;
|
entity.status.enabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user