1
0
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:
Sebastian Malton 2021-10-13 16:31:45 -04:00
parent 3988229a6c
commit f21e4124b2
3 changed files with 22 additions and 16 deletions

View File

@ -59,13 +59,7 @@ export interface KubernetesClusterMetadata extends CatalogEntityMetadata {
kubeVersion?: string; kubeVersion?: string;
} }
export type KubernetesClusterStatusPhase = "connected" | "connecting" | "disconnected" | "deleting"; export class KubernetesCluster extends CatalogEntity<KubernetesClusterMetadata, CatalogEntityStatus, KubernetesClusterSpec> {
export interface KubernetesClusterStatus extends CatalogEntityStatus {
phase: KubernetesClusterStatusPhase;
}
export class KubernetesCluster extends CatalogEntity<KubernetesClusterMetadata, KubernetesClusterStatus, KubernetesClusterSpec> {
public static readonly apiVersion = "entity.k8slens.dev/v1alpha1"; public static readonly apiVersion = "entity.k8slens.dev/v1alpha1";
public static readonly kind = "KubernetesCluster"; public static readonly kind = "KubernetesCluster";

View File

@ -27,7 +27,7 @@ import logger from "./logger";
import { apiKubePrefix } from "../common/vars"; import { apiKubePrefix } from "../common/vars";
import { getClusterIdFromHost, Singleton } from "../common/utils"; import { getClusterIdFromHost, Singleton } from "../common/utils";
import { catalogEntityRegistry } from "./catalog"; 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 { ipcMainOn } from "../common/ipc";
import { once } from "lodash"; import { once } from "lodash";
import { ClusterStore } from "../common/cluster-store"; import { ClusterStore } from "../common/cluster-store";
@ -35,6 +35,15 @@ import type { ClusterId } from "../common/cluster-types";
const logPrefix = "[CLUSTER-MANAGER]:"; 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 { export class ClusterManager extends Singleton {
private store = ClusterStore.getInstance(); private store = ClusterStore.getInstance();
deleting = observable.set<ClusterId>(); deleting = observable.set<ClusterId>();
@ -90,6 +99,8 @@ export class ClusterManager extends Singleton {
@action @action
protected updateCatalog(clusters: Cluster[]) { protected updateCatalog(clusters: Cluster[]) {
logger.debug("[CLUSTER-MANAGER]: updating catalog from cluster store");
for (const cluster of clusters) { for (const cluster of clusters) {
this.updateEntityFromCluster(cluster); this.updateEntityFromCluster(cluster);
} }
@ -144,27 +155,28 @@ export class ClusterManager extends Singleton {
@action @action
protected updateEntityStatus(entity: KubernetesCluster, cluster?: Cluster) { protected updateEntityStatus(entity: KubernetesCluster, cluster?: Cluster) {
if (this.deleting.has(entity.getId())) { if (this.deleting.has(entity.getId())) {
entity.status.phase = "deleting"; entity.status.phase = LensClusterStatus.DELETING;
entity.status.enabled = false; entity.status.enabled = false;
} else { } else {
entity.status.phase = ((): KubernetesClusterStatusPhase => { entity.status.phase = (() => {
if (!cluster) { if (!cluster) {
return "disconnected"; return LensClusterStatus.DISCONNECTED;
} }
if (cluster.accessible) { if (cluster.accessible) {
return "connected"; return LensClusterStatus.CONNECTED;
} }
if (!cluster.disconnected) { 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 entity.status.phase;
} }
return "disconnected"; return LensClusterStatus.DISCONNECTED;
})(); })();
entity.status.enabled = true; entity.status.enabled = true;

View File

@ -394,7 +394,6 @@ export class Cluster implements ClusterModel, ClusterState {
* @internal * @internal
*/ */
@action disconnect() { @action disconnect() {
logger.info(`[CLUSTER]: disconnect`, this.getMeta());
this.unbindEvents(); this.unbindEvents();
this.contextHandler?.stopServer(); this.contextHandler?.stopServer();
this.disconnected = true; this.disconnected = true;
@ -405,6 +404,7 @@ export class Cluster implements ClusterModel, ClusterState {
this.allowedNamespaces = []; this.allowedNamespaces = [];
this.resourceAccessStatuses.clear(); this.resourceAccessStatuses.clear();
this.pushState(); this.pushState();
logger.info(`[CLUSTER]: disconnect`, this.getMeta());
} }
/** /**