mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Use enum for lens specific KubernetesCluster statuses in more places
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
f21e4124b2
commit
e429b91142
@ -19,6 +19,9 @@
|
|||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * from "./general";
|
export { KubernetesCluster, kubernetesClusterCategory } from "./kubernetes-cluster";
|
||||||
export * from "./kubernetes-cluster";
|
export { GeneralEntity } from "./general";
|
||||||
export * from "./web-link";
|
export { WebLink } from "./web-link";
|
||||||
|
|
||||||
|
export type { KubernetesClusterPrometheusMetrics, KubernetesClusterSpec, KubernetesClusterMetadata } from "./kubernetes-cluster";
|
||||||
|
export type { WebLinkSpec, WebLinkStatus, WebLinkStatusPhase } from "./web-link";
|
||||||
|
|||||||
@ -54,6 +54,13 @@ export interface KubernetesClusterSpec extends CatalogEntitySpec {
|
|||||||
accessibleNamespaces?: string[];
|
accessibleNamespaces?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum LensKubernetesClusterStatus {
|
||||||
|
DELETING = "deleting",
|
||||||
|
CONNECTING = "connecting",
|
||||||
|
CONNECTED = "connected",
|
||||||
|
DISCONNECTED = "disconnected"
|
||||||
|
}
|
||||||
|
|
||||||
export interface KubernetesClusterMetadata extends CatalogEntityMetadata {
|
export interface KubernetesClusterMetadata extends CatalogEntityMetadata {
|
||||||
distro?: string;
|
distro?: string;
|
||||||
kubeVersion?: string;
|
kubeVersion?: string;
|
||||||
@ -104,15 +111,15 @@ export class KubernetesCluster extends CatalogEntity<KubernetesClusterMetadata,
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (this.status.phase) {
|
switch (this.status.phase) {
|
||||||
case "connected":
|
case LensKubernetesClusterStatus.CONNECTED:
|
||||||
case "connecting":
|
case LensKubernetesClusterStatus.CONNECTING:
|
||||||
context.menuItems.push({
|
context.menuItems.push({
|
||||||
title: "Disconnect",
|
title: "Disconnect",
|
||||||
icon: "link_off",
|
icon: "link_off",
|
||||||
onClick: () => requestMain(clusterDisconnectHandler, this.metadata.uid)
|
onClick: () => requestMain(clusterDisconnectHandler, this.metadata.uid)
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "disconnected":
|
case LensKubernetesClusterStatus.DISCONNECTED:
|
||||||
context.menuItems.push({
|
context.menuItems.push({
|
||||||
title: "Connect",
|
title: "Connect",
|
||||||
icon: "link",
|
icon: "link",
|
||||||
|
|||||||
@ -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 } from "../common/catalog-entities/kubernetes-cluster";
|
import { KubernetesCluster, KubernetesClusterPrometheusMetrics, LensKubernetesClusterStatus } 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,14 +35,7 @@ import type { ClusterId } from "../common/cluster-types";
|
|||||||
|
|
||||||
const logPrefix = "[CLUSTER-MANAGER]:";
|
const logPrefix = "[CLUSTER-MANAGER]:";
|
||||||
|
|
||||||
enum LensClusterStatus {
|
const lensSpecificClusterStatuses: Set<string> = new Set(Object.values(LensKubernetesClusterStatus));
|
||||||
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();
|
||||||
@ -155,20 +148,20 @@ 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 = LensClusterStatus.DELETING;
|
entity.status.phase = LensKubernetesClusterStatus.DELETING;
|
||||||
entity.status.enabled = false;
|
entity.status.enabled = false;
|
||||||
} else {
|
} else {
|
||||||
entity.status.phase = (() => {
|
entity.status.phase = (() => {
|
||||||
if (!cluster) {
|
if (!cluster) {
|
||||||
return LensClusterStatus.DISCONNECTED;
|
return LensKubernetesClusterStatus.DISCONNECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cluster.accessible) {
|
if (cluster.accessible) {
|
||||||
return LensClusterStatus.CONNECTED;
|
return LensKubernetesClusterStatus.CONNECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cluster.disconnected) {
|
if (!cluster.disconnected) {
|
||||||
return LensClusterStatus.CONNECTING;
|
return LensKubernetesClusterStatus.CONNECTING;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extensions are not allowed to use the Lens specific status phases
|
// Extensions are not allowed to use the Lens specific status phases
|
||||||
@ -176,7 +169,7 @@ export class ClusterManager extends Singleton {
|
|||||||
return entity.status.phase;
|
return entity.status.phase;
|
||||||
}
|
}
|
||||||
|
|
||||||
return LensClusterStatus.DISCONNECTED;
|
return LensKubernetesClusterStatus.DISCONNECTED;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
entity.status.enabled = true;
|
entity.status.enabled = true;
|
||||||
@ -288,7 +281,9 @@ export function catalogEntityFromCluster(cluster: Cluster) {
|
|||||||
icon: {}
|
icon: {}
|
||||||
},
|
},
|
||||||
status: {
|
status: {
|
||||||
phase: cluster.disconnected ? "disconnected" : "connected",
|
phase: cluster.disconnected
|
||||||
|
? LensKubernetesClusterStatus.DISCONNECTED
|
||||||
|
: LensKubernetesClusterStatus.CONNECTED,
|
||||||
reason: "",
|
reason: "",
|
||||||
message: "",
|
message: "",
|
||||||
active: !cluster.disconnected
|
active: !cluster.disconnected
|
||||||
|
|||||||
@ -31,6 +31,7 @@ import { cssNames, IClassName } from "../../utils";
|
|||||||
import { Icon } from "../icon";
|
import { Icon } from "../icon";
|
||||||
import { HotbarIcon } from "./hotbar-icon";
|
import { HotbarIcon } from "./hotbar-icon";
|
||||||
import { HotbarStore } from "../../../common/hotbar-store";
|
import { HotbarStore } from "../../../common/hotbar-store";
|
||||||
|
import { LensKubernetesClusterStatus } from "../../../common/catalog-entities/kubernetes-cluster";
|
||||||
|
|
||||||
interface Props extends DOMAttributes<HTMLElement> {
|
interface Props extends DOMAttributes<HTMLElement> {
|
||||||
entity: CatalogEntity;
|
entity: CatalogEntity;
|
||||||
@ -78,7 +79,7 @@ export class HotbarEntityIcon extends React.Component<Props> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const className = cssNames("led", { online: this.props.entity.status.phase == "connected"}); // TODO: make it more generic
|
const className = cssNames("led", { online: this.props.entity.status.phase === LensKubernetesClusterStatus.CONNECTED}); // TODO: make it more generic
|
||||||
|
|
||||||
return <div className={className} />;
|
return <div className={className} />;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user