mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Move activating cluster into injectable IPC (#7355)
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
121a50ecf3
commit
497f63fde6
@ -9,11 +9,12 @@ import { broadcastMessage } from "../ipc";
|
|||||||
import { app } from "electron";
|
import { app } from "electron";
|
||||||
import type { CatalogEntityConstructor, CatalogEntitySpec } from "../catalog/catalog-entity";
|
import type { CatalogEntityConstructor, CatalogEntitySpec } from "../catalog/catalog-entity";
|
||||||
import { IpcRendererNavigationEvents } from "../ipc/navigation-events";
|
import { IpcRendererNavigationEvents } from "../ipc/navigation-events";
|
||||||
import { requestClusterActivation, requestClusterDisconnection } from "../../renderer/ipc";
|
import { requestClusterDisconnection } from "../../renderer/ipc";
|
||||||
import KubeClusterCategoryIcon from "./icons/kubernetes.svg";
|
import KubeClusterCategoryIcon from "./icons/kubernetes.svg";
|
||||||
import getClusterByIdInjectable from "../cluster-store/get-by-id.injectable";
|
import getClusterByIdInjectable from "../cluster-store/get-by-id.injectable";
|
||||||
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||||
import clusterConnectionInjectable from "../../main/cluster/cluster-connection.injectable";
|
import clusterConnectionInjectable from "../../main/cluster/cluster-connection.injectable";
|
||||||
|
import { requestClusterActivationInjectionToken } from "../../features/cluster/activation/common/request-token";
|
||||||
|
|
||||||
export interface KubernetesClusterPrometheusMetrics {
|
export interface KubernetesClusterPrometheusMetrics {
|
||||||
address?: {
|
address?: {
|
||||||
@ -77,21 +78,12 @@ export class KubernetesCluster<
|
|||||||
public readonly kind = KubernetesCluster.kind;
|
public readonly kind = KubernetesCluster.kind;
|
||||||
|
|
||||||
async connect(): Promise<void> {
|
async connect(): Promise<void> {
|
||||||
if (app) {
|
|
||||||
const di = getLegacyGlobalDiForExtensionApi();
|
const di = getLegacyGlobalDiForExtensionApi();
|
||||||
const getClusterById = di.inject(getClusterByIdInjectable);
|
const requestClusterActivation = di.inject(requestClusterActivationInjectionToken);
|
||||||
const cluster = getClusterById(this.getId());
|
|
||||||
|
|
||||||
if (!cluster) {
|
await requestClusterActivation({
|
||||||
return;
|
clusterId: this.getId(),
|
||||||
}
|
});
|
||||||
|
|
||||||
const connectionCluster = di.inject(clusterConnectionInjectable, cluster);
|
|
||||||
|
|
||||||
await connectionCluster.activate();
|
|
||||||
} else {
|
|
||||||
await requestClusterActivation(this.getId(), false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async disconnect(): Promise<void> {
|
async disconnect(): Promise<void> {
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const clusterActivateHandler = "cluster:activate";
|
|
||||||
export const clusterSetFrameIdHandler = "cluster:set-frame-id";
|
export const clusterSetFrameIdHandler = "cluster:set-frame-id";
|
||||||
export const clusterVisibilityHandler = "cluster:visibility";
|
export const clusterVisibilityHandler = "cluster:visibility";
|
||||||
export const clusterDisconnectHandler = "cluster:disconnect";
|
export const clusterDisconnectHandler = "cluster:disconnect";
|
||||||
|
|||||||
@ -10,6 +10,10 @@ export interface RequestFromChannel {
|
|||||||
<Response>(channel: RequestChannel<void, Response>): Promise<Awaited<Response>>;
|
<Response>(channel: RequestChannel<void, Response>): Promise<Awaited<Response>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ChannelRequester<Channel> = Channel extends RequestChannel<infer Request, infer Response>
|
||||||
|
? (req: Request) => Promise<Awaited<Response>>
|
||||||
|
: never;
|
||||||
|
|
||||||
export const requestFromChannelInjectionToken = getInjectionToken<RequestFromChannel>({
|
export const requestFromChannelInjectionToken = getInjectionToken<RequestFromChannel>({
|
||||||
id: "request-from-request-channel",
|
id: "request-from-request-channel",
|
||||||
});
|
});
|
||||||
|
|||||||
@ -0,0 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { ClusterId } from "../../../../common/cluster-types";
|
||||||
|
import { getRequestChannel } from "../../../../common/utils/channel/get-request-channel";
|
||||||
|
|
||||||
|
export interface ActivateCluster {
|
||||||
|
clusterId: ClusterId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
force?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const activateClusterChannel = getRequestChannel<ActivateCluster, void>("activate-cluster");
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||||
|
import type { ChannelRequester } from "../../../../common/utils/channel/request-from-channel-injection-token";
|
||||||
|
import type { activateClusterChannel } from "./channels";
|
||||||
|
|
||||||
|
export type RequestClusterActivation = ChannelRequester<typeof activateClusterChannel>;
|
||||||
|
|
||||||
|
export const requestClusterActivationInjectionToken = getInjectionToken<RequestClusterActivation>({
|
||||||
|
id: "request-cluster-activation-token",
|
||||||
|
});
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getRequestChannelListenerInjectable } from "../../../../main/utils/channel/channel-listeners/listener-tokens";
|
||||||
|
import { activateClusterChannel } from "../common/channels";
|
||||||
|
import requestClusterActivationInjectable from "./request-activation.injectable";
|
||||||
|
|
||||||
|
const activateClusterRequestChannelListenerInjectable = getRequestChannelListenerInjectable({
|
||||||
|
channel: activateClusterChannel,
|
||||||
|
handler: (di) => di.inject(requestClusterActivationInjectable),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default activateClusterRequestChannelListenerInjectable;
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import getClusterByIdInjectable from "../../../../common/cluster-store/get-by-id.injectable";
|
||||||
|
import clusterConnectionInjectable from "../../../../main/cluster/cluster-connection.injectable";
|
||||||
|
import { requestClusterActivationInjectionToken } from "../common/request-token";
|
||||||
|
|
||||||
|
const requestClusterActivationInjectable = getInjectable({
|
||||||
|
id: "request-cluster-activation",
|
||||||
|
instantiate: (di) => {
|
||||||
|
const getClusterById = di.inject(getClusterByIdInjectable);
|
||||||
|
|
||||||
|
return async ({ clusterId, force = false }) => {
|
||||||
|
const cluster = getClusterById(clusterId);
|
||||||
|
|
||||||
|
if (!cluster) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const connection = di.inject(clusterConnectionInjectable, cluster);
|
||||||
|
|
||||||
|
await connection.activate(force);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
injectionToken: requestClusterActivationInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default requestClusterActivationInjectable;
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import requestFromChannelInjectable from "../../../../renderer/utils/channel/request-from-channel.injectable";
|
||||||
|
import { activateClusterChannel } from "../common/channels";
|
||||||
|
import { requestClusterActivationInjectionToken } from "../common/request-token";
|
||||||
|
|
||||||
|
const requestClusterActivationInjectable = getInjectable({
|
||||||
|
id: "request-cluster-activation",
|
||||||
|
instantiate: (di) => {
|
||||||
|
const requestFromChannel = di.inject(requestFromChannelInjectable);
|
||||||
|
|
||||||
|
return (req) => requestFromChannel(activateClusterChannel, req);
|
||||||
|
},
|
||||||
|
injectionToken: requestClusterActivationInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default requestClusterActivationInjectable;
|
||||||
@ -5,7 +5,7 @@
|
|||||||
import type { IpcMainInvokeEvent } from "electron";
|
import type { IpcMainInvokeEvent } from "electron";
|
||||||
import { BrowserWindow, Menu } from "electron";
|
import { BrowserWindow, Menu } from "electron";
|
||||||
import { clusterFrameMap } from "../../../../common/cluster-frames";
|
import { clusterFrameMap } from "../../../../common/cluster-frames";
|
||||||
import { clusterActivateHandler, clusterSetFrameIdHandler, clusterDisconnectHandler, clusterStates } from "../../../../common/ipc/cluster";
|
import { clusterSetFrameIdHandler, clusterDisconnectHandler, clusterStates } from "../../../../common/ipc/cluster";
|
||||||
import type { ClusterId } from "../../../../common/cluster-types";
|
import type { ClusterId } from "../../../../common/cluster-types";
|
||||||
import type { ClusterStore } from "../../../../common/cluster-store/cluster-store";
|
import type { ClusterStore } from "../../../../common/cluster-store/cluster-store";
|
||||||
import { broadcastMainChannel, broadcastMessage, ipcMainHandle, ipcMainOn } from "../../../../common/ipc";
|
import { broadcastMainChannel, broadcastMessage, ipcMainHandle, ipcMainOn } from "../../../../common/ipc";
|
||||||
@ -37,18 +37,6 @@ export const setupIpcMainHandlers = ({
|
|||||||
pushCatalogToRenderer,
|
pushCatalogToRenderer,
|
||||||
getClusterConnection,
|
getClusterConnection,
|
||||||
}: Dependencies) => {
|
}: Dependencies) => {
|
||||||
ipcMainHandle(clusterActivateHandler, async (event, clusterId: ClusterId, force = false) => {
|
|
||||||
const cluster = getClusterById(clusterId);
|
|
||||||
|
|
||||||
if (!cluster) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const clusterConnection = getClusterConnection(cluster);
|
|
||||||
|
|
||||||
await clusterConnection.activate(force);
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMainHandle(clusterSetFrameIdHandler, (event: IpcMainInvokeEvent, clusterId: ClusterId) => {
|
ipcMainHandle(clusterSetFrameIdHandler, (event: IpcMainInvokeEvent, clusterId: ClusterId) => {
|
||||||
const cluster = getClusterById(clusterId);
|
const cluster = getClusterById(clusterId);
|
||||||
|
|
||||||
|
|||||||
@ -17,11 +17,12 @@ import { Icon } from "../icon";
|
|||||||
import { Spinner } from "../spinner";
|
import { Spinner } from "../spinner";
|
||||||
import type { KubeAuthUpdate } from "../../../common/cluster-types";
|
import type { KubeAuthUpdate } from "../../../common/cluster-types";
|
||||||
import type { CatalogEntityRegistry } from "../../api/catalog/entity/registry";
|
import type { CatalogEntityRegistry } from "../../api/catalog/entity/registry";
|
||||||
import { requestClusterActivation } from "../../ipc";
|
|
||||||
import type { NavigateToEntitySettings } from "../../../common/front-end-routing/routes/entity-settings/navigate-to-entity-settings.injectable";
|
import type { NavigateToEntitySettings } from "../../../common/front-end-routing/routes/entity-settings/navigate-to-entity-settings.injectable";
|
||||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||||
import navigateToEntitySettingsInjectable from "../../../common/front-end-routing/routes/entity-settings/navigate-to-entity-settings.injectable";
|
import navigateToEntitySettingsInjectable from "../../../common/front-end-routing/routes/entity-settings/navigate-to-entity-settings.injectable";
|
||||||
import catalogEntityRegistryInjectable from "../../api/catalog/entity/registry.injectable";
|
import catalogEntityRegistryInjectable from "../../api/catalog/entity/registry.injectable";
|
||||||
|
import type { RequestClusterActivation } from "../../../features/cluster/activation/common/request-token";
|
||||||
|
import requestClusterActivationInjectable from "../../../features/cluster/activation/renderer/request-activation.injectable";
|
||||||
|
|
||||||
export interface ClusterStatusProps {
|
export interface ClusterStatusProps {
|
||||||
className?: IClassName;
|
className?: IClassName;
|
||||||
@ -31,6 +32,7 @@ export interface ClusterStatusProps {
|
|||||||
interface Dependencies {
|
interface Dependencies {
|
||||||
navigateToEntitySettings: NavigateToEntitySettings;
|
navigateToEntitySettings: NavigateToEntitySettings;
|
||||||
entityRegistry: CatalogEntityRegistry;
|
entityRegistry: CatalogEntityRegistry;
|
||||||
|
requestClusterActivation: RequestClusterActivation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
@ -83,7 +85,10 @@ class NonInjectedClusterStatus extends React.Component<ClusterStatusProps & Depe
|
|||||||
this.isReconnecting = true;
|
this.isReconnecting = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await requestClusterActivation(this.cluster.id, true);
|
await this.props.requestClusterActivation({
|
||||||
|
clusterId: this.cluster.id,
|
||||||
|
force: true,
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.authOutput.push({
|
this.authOutput.push({
|
||||||
message: String(error),
|
message: String(error),
|
||||||
@ -173,5 +178,6 @@ export const ClusterStatus = withInjectables<Dependencies, ClusterStatusProps>(N
|
|||||||
...props,
|
...props,
|
||||||
navigateToEntitySettings: di.inject(navigateToEntitySettingsInjectable),
|
navigateToEntitySettings: di.inject(navigateToEntitySettingsInjectable),
|
||||||
entityRegistry: di.inject(catalogEntityRegistryInjectable),
|
entityRegistry: di.inject(catalogEntityRegistryInjectable),
|
||||||
|
requestClusterActivation: di.inject(requestClusterActivationInjectable),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@ -11,7 +11,6 @@ import { disposeOnUnmount, observer } from "mobx-react";
|
|||||||
import { ClusterStatus } from "./cluster-status";
|
import { ClusterStatus } from "./cluster-status";
|
||||||
import type { ClusterFrameHandler } from "./cluster-frame-handler";
|
import type { ClusterFrameHandler } from "./cluster-frame-handler";
|
||||||
import type { Cluster } from "../../../common/cluster/cluster";
|
import type { Cluster } from "../../../common/cluster/cluster";
|
||||||
import { requestClusterActivation } from "../../ipc";
|
|
||||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||||
import type { NavigateToCatalog } from "../../../common/front-end-routing/routes/catalog/navigate-to-catalog.injectable";
|
import type { NavigateToCatalog } from "../../../common/front-end-routing/routes/catalog/navigate-to-catalog.injectable";
|
||||||
import navigateToCatalogInjectable from "../../../common/front-end-routing/routes/catalog/navigate-to-catalog.injectable";
|
import navigateToCatalogInjectable from "../../../common/front-end-routing/routes/catalog/navigate-to-catalog.injectable";
|
||||||
@ -21,6 +20,8 @@ import type { CatalogEntityRegistry } from "../../api/catalog/entity/registry";
|
|||||||
import catalogEntityRegistryInjectable from "../../api/catalog/entity/registry.injectable";
|
import catalogEntityRegistryInjectable from "../../api/catalog/entity/registry.injectable";
|
||||||
import type { GetClusterById } from "../../../common/cluster-store/get-by-id.injectable";
|
import type { GetClusterById } from "../../../common/cluster-store/get-by-id.injectable";
|
||||||
import getClusterByIdInjectable from "../../../common/cluster-store/get-by-id.injectable";
|
import getClusterByIdInjectable from "../../../common/cluster-store/get-by-id.injectable";
|
||||||
|
import type { RequestClusterActivation } from "../../../features/cluster/activation/common/request-token";
|
||||||
|
import requestClusterActivationInjectable from "../../../features/cluster/activation/renderer/request-activation.injectable";
|
||||||
|
|
||||||
interface Dependencies {
|
interface Dependencies {
|
||||||
clusterId: IComputedValue<string>;
|
clusterId: IComputedValue<string>;
|
||||||
@ -28,6 +29,7 @@ interface Dependencies {
|
|||||||
navigateToCatalog: NavigateToCatalog;
|
navigateToCatalog: NavigateToCatalog;
|
||||||
entityRegistry: CatalogEntityRegistry;
|
entityRegistry: CatalogEntityRegistry;
|
||||||
getClusterById: GetClusterById;
|
getClusterById: GetClusterById;
|
||||||
|
requestClusterActivation: RequestClusterActivation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
@ -83,7 +85,7 @@ class NonInjectedClusterView extends React.Component<Dependencies> {
|
|||||||
|
|
||||||
this.props.clusterFrames.setVisibleCluster(clusterId);
|
this.props.clusterFrames.setVisibleCluster(clusterId);
|
||||||
this.props.clusterFrames.initView(clusterId);
|
this.props.clusterFrames.initView(clusterId);
|
||||||
requestClusterActivation(clusterId, false); // activate and fetch cluster's state from main
|
this.props.requestClusterActivation({ clusterId });
|
||||||
this.props.entityRegistry.activeEntity = clusterId;
|
this.props.entityRegistry.activeEntity = clusterId;
|
||||||
}, {
|
}, {
|
||||||
fireImmediately: true,
|
fireImmediately: true,
|
||||||
@ -117,6 +119,7 @@ export const ClusterView = withInjectables<Dependencies>(NonInjectedClusterView,
|
|||||||
clusterFrames: di.inject(clusterFrameHandlerInjectable),
|
clusterFrames: di.inject(clusterFrameHandlerInjectable),
|
||||||
entityRegistry: di.inject(catalogEntityRegistryInjectable),
|
entityRegistry: di.inject(catalogEntityRegistryInjectable),
|
||||||
getClusterById: di.inject(getClusterByIdInjectable),
|
getClusterById: di.inject(getClusterByIdInjectable),
|
||||||
|
requestClusterActivation: di.inject(requestClusterActivationInjectable),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { clusterActivateHandler, clusterDisconnectHandler, clusterSetFrameIdHandler, clusterStates } from "../../common/ipc/cluster";
|
import { clusterDisconnectHandler, clusterSetFrameIdHandler, clusterStates } from "../../common/ipc/cluster";
|
||||||
import type { ClusterId, ClusterState } from "../../common/cluster-types";
|
import type { ClusterId, ClusterState } from "../../common/cluster-types";
|
||||||
import { windowActionHandleChannel, windowLocationChangedChannel, windowOpenAppMenuAsContextMenuChannel, type WindowAction } from "../../common/ipc/window";
|
import { windowActionHandleChannel, windowLocationChangedChannel, windowOpenAppMenuAsContextMenuChannel, type WindowAction } from "../../common/ipc/window";
|
||||||
import { extensionDiscoveryStateChannel, extensionLoaderFromMainChannel } from "../../common/ipc/extension-handling";
|
import { extensionDiscoveryStateChannel, extensionLoaderFromMainChannel } from "../../common/ipc/extension-handling";
|
||||||
@ -46,10 +46,6 @@ export function requestSetClusterFrameId(clusterId: ClusterId): Promise<void> {
|
|||||||
return requestMain(clusterSetFrameIdHandler, clusterId);
|
return requestMain(clusterSetFrameIdHandler, clusterId);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function requestClusterActivation(clusterId: ClusterId, force?: boolean): Promise<void> {
|
|
||||||
return requestMain(clusterActivateHandler, clusterId, force);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function requestClusterDisconnection(clusterId: ClusterId, force?: boolean): Promise<void> {
|
export function requestClusterDisconnection(clusterId: ClusterId, force?: boolean): Promise<void> {
|
||||||
return requestMain(clusterDisconnectHandler, clusterId, force);
|
return requestMain(clusterDisconnectHandler, clusterId, force);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user