mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Only allow extensions to use non-lens specific cluster phases
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
3988229a6c
commit
f21e4124b2
@ -59,13 +59,7 @@ export interface KubernetesClusterMetadata extends CatalogEntityMetadata {
|
||||
kubeVersion?: string;
|
||||
}
|
||||
|
||||
export type KubernetesClusterStatusPhase = "connected" | "connecting" | "disconnected" | "deleting";
|
||||
|
||||
export interface KubernetesClusterStatus extends CatalogEntityStatus {
|
||||
phase: KubernetesClusterStatusPhase;
|
||||
}
|
||||
|
||||
export class KubernetesCluster extends CatalogEntity<KubernetesClusterMetadata, KubernetesClusterStatus, KubernetesClusterSpec> {
|
||||
export class KubernetesCluster extends CatalogEntity<KubernetesClusterMetadata, CatalogEntityStatus, KubernetesClusterSpec> {
|
||||
public static readonly apiVersion = "entity.k8slens.dev/v1alpha1";
|
||||
public static readonly kind = "KubernetesCluster";
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@ import logger from "./logger";
|
||||
import { apiKubePrefix } from "../common/vars";
|
||||
import { getClusterIdFromHost, Singleton } from "../common/utils";
|
||||
import { catalogEntityRegistry } from "./catalog";
|
||||
import { KubernetesCluster, KubernetesClusterPrometheusMetrics, KubernetesClusterStatusPhase } from "../common/catalog-entities/kubernetes-cluster";
|
||||
import { KubernetesCluster, KubernetesClusterPrometheusMetrics } from "../common/catalog-entities/kubernetes-cluster";
|
||||
import { ipcMainOn } from "../common/ipc";
|
||||
import { once } from "lodash";
|
||||
import { ClusterStore } from "../common/cluster-store";
|
||||
@ -35,6 +35,15 @@ import type { ClusterId } from "../common/cluster-types";
|
||||
|
||||
const logPrefix = "[CLUSTER-MANAGER]:";
|
||||
|
||||
enum LensClusterStatus {
|
||||
DELETING = "deleting",
|
||||
CONNECTING = "connecting",
|
||||
CONNECTED = "connected",
|
||||
DISCONNECTED = "disconnected"
|
||||
}
|
||||
|
||||
const lensSpecificClusterStatuses: Set<string> = new Set(Object.values(LensClusterStatus));
|
||||
|
||||
export class ClusterManager extends Singleton {
|
||||
private store = ClusterStore.getInstance();
|
||||
deleting = observable.set<ClusterId>();
|
||||
@ -90,6 +99,8 @@ export class ClusterManager extends Singleton {
|
||||
|
||||
@action
|
||||
protected updateCatalog(clusters: Cluster[]) {
|
||||
logger.debug("[CLUSTER-MANAGER]: updating catalog from cluster store");
|
||||
|
||||
for (const cluster of clusters) {
|
||||
this.updateEntityFromCluster(cluster);
|
||||
}
|
||||
@ -144,27 +155,28 @@ export class ClusterManager extends Singleton {
|
||||
@action
|
||||
protected updateEntityStatus(entity: KubernetesCluster, cluster?: Cluster) {
|
||||
if (this.deleting.has(entity.getId())) {
|
||||
entity.status.phase = "deleting";
|
||||
entity.status.phase = LensClusterStatus.DELETING;
|
||||
entity.status.enabled = false;
|
||||
} else {
|
||||
entity.status.phase = ((): KubernetesClusterStatusPhase => {
|
||||
entity.status.phase = (() => {
|
||||
if (!cluster) {
|
||||
return "disconnected";
|
||||
return LensClusterStatus.DISCONNECTED;
|
||||
}
|
||||
|
||||
if (cluster.accessible) {
|
||||
return "connected";
|
||||
return LensClusterStatus.CONNECTED;
|
||||
}
|
||||
|
||||
if (!cluster.disconnected) {
|
||||
return "connecting";
|
||||
return LensClusterStatus.CONNECTING;
|
||||
}
|
||||
|
||||
if (entity?.status?.phase) {
|
||||
// Extensions are not allowed to use the Lens specific status phases
|
||||
if (!lensSpecificClusterStatuses.has(entity?.status?.phase)) {
|
||||
return entity.status.phase;
|
||||
}
|
||||
|
||||
return "disconnected";
|
||||
return LensClusterStatus.DISCONNECTED;
|
||||
})();
|
||||
|
||||
entity.status.enabled = true;
|
||||
|
||||
@ -394,7 +394,6 @@ export class Cluster implements ClusterModel, ClusterState {
|
||||
* @internal
|
||||
*/
|
||||
@action disconnect() {
|
||||
logger.info(`[CLUSTER]: disconnect`, this.getMeta());
|
||||
this.unbindEvents();
|
||||
this.contextHandler?.stopServer();
|
||||
this.disconnected = true;
|
||||
@ -405,6 +404,7 @@ export class Cluster implements ClusterModel, ClusterState {
|
||||
this.allowedNamespaces = [];
|
||||
this.resourceAccessStatuses.clear();
|
||||
this.pushState();
|
||||
logger.info(`[CLUSTER]: disconnect`, this.getMeta());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user