diff --git a/src/features/quitting-and-restarting-the-app/quitting-the-app-using-application-menu.test.ts b/src/features/quitting-and-restarting-the-app/quitting-the-app-using-application-menu.test.ts index fe903f93f3..5e0989aa91 100644 --- a/src/features/quitting-and-restarting-the-app/quitting-the-app-using-application-menu.test.ts +++ b/src/features/quitting-and-restarting-the-app/quitting-the-app-using-application-menu.test.ts @@ -5,9 +5,9 @@ import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; -import type { ClusterManager } from "../../main/cluster-manager"; +import type { ClusterManager } from "../../main/cluster/manager"; import exitAppInjectable from "../../main/electron-app/features/exit-app.injectable"; -import clusterManagerInjectable from "../../main/cluster-manager.injectable"; +import clusterManagerInjectable from "../../main/cluster/manager.injectable"; import stopServicesAndExitAppInjectable from "../../main/stop-services-and-exit-app.injectable"; import { advanceFakeTime, useFakeTime } from "../../common/test-utils/use-fake-time"; diff --git a/src/main/catalog-sources/kubeconfig-sync/compute-diff.injectable.ts b/src/main/catalog-sources/kubeconfig-sync/compute-diff.injectable.ts index 31745d116f..fbf4705406 100644 --- a/src/main/catalog-sources/kubeconfig-sync/compute-diff.injectable.ts +++ b/src/main/catalog-sources/kubeconfig-sync/compute-diff.injectable.ts @@ -12,8 +12,8 @@ import type { CatalogEntity } from "../../../common/catalog"; import getClusterByIdInjectable from "../../../common/cluster-store/get-by-id.injectable"; import type { Cluster } from "../../../common/cluster/cluster"; import { loadConfigFromString } from "../../../common/kube-helpers"; -import { catalogEntityFromCluster } from "../../cluster-manager"; -import clusterManagerInjectable from "../../cluster-manager.injectable"; +import { catalogEntityFromCluster } from "../../cluster/manager"; +import clusterManagerInjectable from "../../cluster/manager.injectable"; import createClusterInjectable from "../../create-cluster/create-cluster.injectable"; import configToModelsInjectable from "./config-to-models.injectable"; import kubeconfigSyncLoggerInjectable from "./logger.injectable"; diff --git a/src/main/cluster-manager.injectable.ts b/src/main/cluster-manager.injectable.ts deleted file mode 100644 index 2b55f0e854..0000000000 --- a/src/main/cluster-manager.injectable.ts +++ /dev/null @@ -1,25 +0,0 @@ -/** - * 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 { ClusterManager } from "./cluster-manager"; -import clusterStoreInjectable from "../common/cluster-store/cluster-store.injectable"; -import catalogEntityRegistryInjectable from "./catalog/entity-registry.injectable"; - -const clusterManagerInjectable = getInjectable({ - id: "cluster-manager", - - instantiate: (di) => { - const clusterManager = new ClusterManager({ - store: di.inject(clusterStoreInjectable), - catalogEntityRegistry: di.inject(catalogEntityRegistryInjectable), - }); - - clusterManager.init(); - - return clusterManager; - }, -}); - -export default clusterManagerInjectable; diff --git a/src/main/cluster/initialize-manager.injectable.ts b/src/main/cluster/initialize-manager.injectable.ts new file mode 100644 index 0000000000..37234d3ae9 --- /dev/null +++ b/src/main/cluster/initialize-manager.injectable.ts @@ -0,0 +1,24 @@ +/** + * 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 { onLoadOfApplicationInjectionToken } from "../start-main-application/runnable-tokens/on-load-of-application-injection-token"; +import clusterManagerInjectable from "./manager.injectable"; + +const initializeClusterManagerInjectable = getInjectable({ + id: "initialize-cluster-manager", + instantiate: (di) => { + const clusterManager = di.inject(clusterManagerInjectable); + + return { + run: () => { + clusterManager.init(); + }, + }; + }, + injectionToken: onLoadOfApplicationInjectionToken, + causesSideEffects: true, +}); + +export default initializeClusterManagerInjectable; diff --git a/src/main/cluster/manager.injectable.ts b/src/main/cluster/manager.injectable.ts new file mode 100644 index 0000000000..842c2de9d1 --- /dev/null +++ b/src/main/cluster/manager.injectable.ts @@ -0,0 +1,19 @@ +/** + * 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 clusterStoreInjectable from "../../common/cluster-store/cluster-store.injectable"; +import catalogEntityRegistryInjectable from "../catalog/entity-registry.injectable"; +import { ClusterManager } from "./manager"; + +const clusterManagerInjectable = getInjectable({ + id: "cluster-manager", + + instantiate: (di) => new ClusterManager({ + store: di.inject(clusterStoreInjectable), + catalogEntityRegistry: di.inject(catalogEntityRegistryInjectable), + }), +}); + +export default clusterManagerInjectable; diff --git a/src/main/cluster-manager.ts b/src/main/cluster/manager.ts similarity index 93% rename from src/main/cluster-manager.ts rename to src/main/cluster/manager.ts index 787f2a1618..b04df23fd5 100644 --- a/src/main/cluster-manager.ts +++ b/src/main/cluster/manager.ts @@ -3,20 +3,20 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ -import "../common/ipc/cluster"; +import "../../common/ipc/cluster"; import type http from "http"; import { action, makeObservable, observable, observe, reaction, toJS } from "mobx"; -import type { Cluster } from "../common/cluster/cluster"; -import logger from "./logger"; -import { apiKubePrefix } from "../common/vars"; -import { getClusterIdFromHost, isErrnoException } from "../common/utils"; -import type { KubernetesClusterPrometheusMetrics } from "../common/catalog-entities/kubernetes-cluster"; -import { isKubernetesCluster, KubernetesCluster, LensKubernetesClusterStatus } from "../common/catalog-entities/kubernetes-cluster"; -import { ipcMainOn } from "../common/ipc"; +import type { Cluster } from "../../common/cluster/cluster"; +import logger from "../logger"; +import { apiKubePrefix } from "../../common/vars"; +import { getClusterIdFromHost, isErrnoException } from "../../common/utils"; +import type { KubernetesClusterPrometheusMetrics } from "../../common/catalog-entities/kubernetes-cluster"; +import { isKubernetesCluster, KubernetesCluster, LensKubernetesClusterStatus } from "../../common/catalog-entities/kubernetes-cluster"; +import { ipcMainOn } from "../../common/ipc"; import { once } from "lodash"; -import type { ClusterStore } from "../common/cluster-store/cluster-store"; -import type { ClusterId } from "../common/cluster-types"; -import type { CatalogEntityRegistry } from "./catalog"; +import type { ClusterStore } from "../../common/cluster-store/cluster-store"; +import type { ClusterId } from "../../common/cluster-types"; +import type { CatalogEntityRegistry } from "../catalog"; const logPrefix = "[CLUSTER-MANAGER]:"; diff --git a/src/main/electron-app/runnables/setup-ipc-main-handlers/setup-ipc-main-handlers.injectable.ts b/src/main/electron-app/runnables/setup-ipc-main-handlers/setup-ipc-main-handlers.injectable.ts index 24f90f01b3..f07ac94fec 100644 --- a/src/main/electron-app/runnables/setup-ipc-main-handlers/setup-ipc-main-handlers.injectable.ts +++ b/src/main/electron-app/runnables/setup-ipc-main-handlers/setup-ipc-main-handlers.injectable.ts @@ -6,7 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import directoryForLensLocalStorageInjectable from "../../../../common/directory-for-lens-local-storage/directory-for-lens-local-storage.injectable"; import { setupIpcMainHandlers } from "./setup-ipc-main-handlers"; import loggerInjectable from "../../../../common/logger.injectable"; -import clusterManagerInjectable from "../../../cluster-manager.injectable"; +import clusterManagerInjectable from "../../../cluster/manager.injectable"; import applicationMenuItemsInjectable from "../../../menu/application-menu-items.injectable"; import getAbsolutePathInjectable from "../../../../common/path/get-absolute-path.injectable"; import clusterStoreInjectable from "../../../../common/cluster-store/cluster-store.injectable"; diff --git a/src/main/electron-app/runnables/setup-ipc-main-handlers/setup-ipc-main-handlers.ts b/src/main/electron-app/runnables/setup-ipc-main-handlers/setup-ipc-main-handlers.ts index 9342696c77..c4abc2b2d5 100644 --- a/src/main/electron-app/runnables/setup-ipc-main-handlers/setup-ipc-main-handlers.ts +++ b/src/main/electron-app/runnables/setup-ipc-main-handlers/setup-ipc-main-handlers.ts @@ -12,7 +12,7 @@ import { appEventBus } from "../../../../common/app-event-bus/event-bus"; import { broadcastMainChannel, broadcastMessage, ipcMainHandle, ipcMainOn } from "../../../../common/ipc"; import type { CatalogEntityRegistry } from "../../../catalog"; import { pushCatalogToRenderer } from "../../../catalog-pusher"; -import type { ClusterManager } from "../../../cluster-manager"; +import type { ClusterManager } from "../../../cluster/manager"; import { ResourceApplier } from "../../../resource-applier"; import { remove } from "fs-extra"; import type { IComputedValue } from "mobx"; diff --git a/src/main/getDiForUnitTesting.ts b/src/main/getDiForUnitTesting.ts index 8e08c9b86c..12b3d5317d 100644 --- a/src/main/getDiForUnitTesting.ts +++ b/src/main/getDiForUnitTesting.ts @@ -88,6 +88,9 @@ import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx"; import electronInjectable from "./utils/resolve-system-proxy/electron.injectable"; import type { HotbarStore } from "../common/hotbars/store"; import focusApplicationInjectable from "./electron-app/features/focus-application.injectable"; +import kubectlDownloadingNormalizedArchInjectable from "./kubectl/normalized-arch.injectable"; +import initializeClusterManagerInjectable from "./cluster/initialize-manager.injectable"; +import addKubeconfigSyncAsEntitySourceInjectable from "./start-main-application/runnables/kube-config-sync/add-source.injectable"; import type { GlobalOverride } from "../common/test-utils/get-global-override"; export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {}) { @@ -125,7 +128,7 @@ export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {}) di.override(electronInjectable, () => ({})); di.override(waitUntilBundledExtensionsAreLoadedInjectable, () => async () => {}); di.override(getRandomIdInjectable, () => () => "some-irrelevant-random-id"); - + di.override(kubectlDownloadingNormalizedArchInjectable, () => "amd64"); di.override(hotbarStoreInjectable, () => ({ load: () => {}, getActive: () => ({ name: "some-hotbar", items: [] }), @@ -204,6 +207,8 @@ export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {}) const overrideRunnablesHavingSideEffects = (di: DiContainer) => { [ initializeExtensionsInjectable, + initializeClusterManagerInjectable, + addKubeconfigSyncAsEntitySourceInjectable, setupIpcMainHandlersInjectable, setupLensProxyInjectable, setupShellInjectable, diff --git a/src/main/lens-proxy/lens-proxy.injectable.ts b/src/main/lens-proxy/lens-proxy.injectable.ts index 5138ac191e..45d893514d 100644 --- a/src/main/lens-proxy/lens-proxy.injectable.ts +++ b/src/main/lens-proxy/lens-proxy.injectable.ts @@ -7,7 +7,7 @@ import { LensProxy } from "./lens-proxy"; import { kubeApiUpgradeRequest } from "./proxy-functions"; import routerInjectable from "../router/router.injectable"; import httpProxy from "http-proxy"; -import clusterManagerInjectable from "../cluster-manager.injectable"; +import clusterManagerInjectable from "../cluster/manager.injectable"; import shellApiRequestInjectable from "./proxy-functions/shell-api-request/shell-api-request.injectable"; import lensProxyPortInjectable from "./lens-proxy-port.injectable"; import contentSecurityPolicyInjectable from "../../common/vars/content-security-policy.injectable"; diff --git a/src/main/lens-proxy/proxy-functions/shell-api-request/shell-api-request.injectable.ts b/src/main/lens-proxy/proxy-functions/shell-api-request/shell-api-request.injectable.ts index b491ab5456..a9dc0c6747 100644 --- a/src/main/lens-proxy/proxy-functions/shell-api-request/shell-api-request.injectable.ts +++ b/src/main/lens-proxy/proxy-functions/shell-api-request/shell-api-request.injectable.ts @@ -6,7 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import { shellApiRequest } from "./shell-api-request"; import createShellSessionInjectable from "../../../shell-session/create-shell-session.injectable"; import shellRequestAuthenticatorInjectable from "./shell-request-authenticator/shell-request-authenticator.injectable"; -import clusterManagerInjectable from "../../../cluster-manager.injectable"; +import clusterManagerInjectable from "../../../cluster/manager.injectable"; const shellApiRequestInjectable = getInjectable({ id: "shell-api-request", diff --git a/src/main/lens-proxy/proxy-functions/shell-api-request/shell-api-request.ts b/src/main/lens-proxy/proxy-functions/shell-api-request/shell-api-request.ts index 97b6dedd4c..b01a1db44b 100644 --- a/src/main/lens-proxy/proxy-functions/shell-api-request/shell-api-request.ts +++ b/src/main/lens-proxy/proxy-functions/shell-api-request/shell-api-request.ts @@ -7,7 +7,7 @@ import logger from "../../../logger"; import type WebSocket from "ws"; import { Server as WebSocketServer } from "ws"; import type { ProxyApiRequestArgs } from "../types"; -import type { ClusterManager } from "../../../cluster-manager"; +import type { ClusterManager } from "../../../cluster/manager"; import URLParse from "url-parse"; import type { Cluster } from "../../../../common/cluster/cluster"; import type { ClusterId } from "../../../../common/cluster-types"; diff --git a/src/main/start-main-application/runnables/stop-cluster-manager.injectable.ts b/src/main/start-main-application/runnables/stop-cluster-manager.injectable.ts index d062270dd0..cd736a4586 100644 --- a/src/main/start-main-application/runnables/stop-cluster-manager.injectable.ts +++ b/src/main/start-main-application/runnables/stop-cluster-manager.injectable.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import clusterManagerInjectable from "../../cluster-manager.injectable"; +import clusterManagerInjectable from "../../cluster/manager.injectable"; import { beforeQuitOfFrontEndInjectionToken } from "../runnable-tokens/before-quit-of-front-end-injection-token"; const stopClusterManagerInjectable = getInjectable({ diff --git a/src/main/stop-services-and-exit-app.injectable.ts b/src/main/stop-services-and-exit-app.injectable.ts index 25b4324aec..9ac505fe65 100644 --- a/src/main/stop-services-and-exit-app.injectable.ts +++ b/src/main/stop-services-and-exit-app.injectable.ts @@ -4,7 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import exitAppInjectable from "./electron-app/features/exit-app.injectable"; -import clusterManagerInjectable from "./cluster-manager.injectable"; +import clusterManagerInjectable from "./cluster/manager.injectable"; import appEventBusInjectable from "../common/app-event-bus/app-event-bus.injectable"; import loggerInjectable from "../common/logger.injectable"; import closeAllWindowsInjectable from "./start-main-application/lens-window/hide-all-windows/close-all-windows.injectable"; diff --git a/src/renderer/components/test-utils/get-application-builder.tsx b/src/renderer/components/test-utils/get-application-builder.tsx index 9f9ab7d903..f7e28c7b81 100644 --- a/src/renderer/components/test-utils/get-application-builder.tsx +++ b/src/renderer/components/test-utils/get-application-builder.tsx @@ -54,7 +54,7 @@ import { RootFrame } from "../../frames/root-frame/root-frame"; import { ClusterFrame } from "../../frames/cluster-frame/cluster-frame"; import hostedClusterIdInjectable from "../../cluster-frame-context/hosted-cluster-id.injectable"; import activeKubernetesClusterInjectable from "../../cluster-frame-context/active-kubernetes-cluster.injectable"; -import { catalogEntityFromCluster } from "../../../main/cluster-manager"; +import { catalogEntityFromCluster } from "../../../main/cluster/manager"; import namespaceStoreInjectable from "../+namespaces/store.injectable"; import { isAllowedResource } from "../../../common/cluster/is-allowed-resource"; import createApplicationWindowInjectable from "../../../main/start-main-application/lens-window/application-window/create-application-window.injectable";