diff --git a/packages/core/src/common/__tests__/user-store.test.ts b/packages/core/src/common/__tests__/user-store.test.ts index fb8d020fb0..1a2ca14746 100644 --- a/packages/core/src/common/__tests__/user-store.test.ts +++ b/packages/core/src/common/__tests__/user-store.test.ts @@ -6,7 +6,6 @@ import type { UserStore } from "../user-store"; import userStoreInjectable from "../user-store/user-store.injectable"; import type { DiContainer } from "@ogre-tools/injectable"; import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable"; -import type { ClusterStoreModel } from "../cluster-store/cluster-store"; import { defaultThemeId } from "../vars"; import writeFileInjectable from "../fs/write-file.injectable"; import { getDiForUnitTesting } from "../../main/getDiForUnitTesting"; @@ -15,6 +14,7 @@ import releaseChannelInjectable from "../vars/release-channel.injectable"; import defaultUpdateChannelInjectable from "../../features/application-update/common/selected-update-channel/default-update-channel.injectable"; import writeJsonSyncInjectable from "../fs/write-json-sync.injectable"; import writeFileSyncInjectable from "../fs/write-file-sync.injectable"; +import type { ClusterStoreModel } from "../../features/cluster/storage/common/storage.injectable"; describe("user store tests", () => { let userStore: UserStore; diff --git a/packages/core/src/common/cluster-store/cluster-store.injectable.ts b/packages/core/src/common/cluster-store/cluster-store.injectable.ts deleted file mode 100644 index 37bc2e33ca..0000000000 --- a/packages/core/src/common/cluster-store/cluster-store.injectable.ts +++ /dev/null @@ -1,28 +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 { ClusterStore } from "./cluster-store"; -import readClusterConfigSyncInjectable from "./read-cluster-config.injectable"; -import emitAppEventInjectable from "../app-event-bus/emit-event.injectable"; -import loggerInjectable from "../logger.injectable"; -import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable"; -import persistentStorageMigrationsInjectable from "../persistent-storage/migrations.injectable"; -import { clusterStoreMigrationInjectionToken } from "./migration-token"; -import createPersistentStorageInjectable from "../persistent-storage/create.injectable"; - -const clusterStoreInjectable = getInjectable({ - id: "cluster-store", - - instantiate: (di) => new ClusterStore({ - readClusterConfigSync: di.inject(readClusterConfigSyncInjectable), - emitAppEvent: di.inject(emitAppEventInjectable), - logger: di.inject(loggerInjectable), - storeMigrationVersion: di.inject(storeMigrationVersionInjectable), - migrations: di.inject(persistentStorageMigrationsInjectable, clusterStoreMigrationInjectionToken), - createPersistentStorage: di.inject(createPersistentStorageInjectable), - }), -}); - -export default clusterStoreInjectable; diff --git a/packages/core/src/common/cluster-store/cluster-store.ts b/packages/core/src/common/cluster-store/cluster-store.ts deleted file mode 100644 index 9e2f3b3f69..0000000000 --- a/packages/core/src/common/cluster-store/cluster-store.ts +++ /dev/null @@ -1,106 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ - - -import { action, comparer, computed, observable } from "mobx"; -import { Cluster } from "../cluster/cluster"; -import { toJS } from "../utils"; -import type { ClusterModel, ClusterId } from "../cluster-types"; -import type { ReadClusterConfigSync } from "./read-cluster-config.injectable"; -import type { EmitAppEvent } from "../app-event-bus/emit-event.injectable"; -import type { CreatePersistentStorage, PersistentStorage } from "../persistent-storage/create.injectable"; -import type { Migrations } from "conf/dist/source/types"; -import type { Logger } from "../logger"; - -export interface ClusterStoreModel { - clusters?: ClusterModel[]; -} - -interface Dependencies { - readClusterConfigSync: ReadClusterConfigSync; - emitAppEvent: EmitAppEvent; - createPersistentStorage: CreatePersistentStorage; - readonly storeMigrationVersion: string; - readonly migrations: Migrations>; - readonly logger: Logger; -} - -export class ClusterStore { - readonly clusters = observable.map(); - private readonly store: PersistentStorage; - - constructor(protected readonly dependencies: Dependencies) { - this.store = this.dependencies.createPersistentStorage({ - configName: "lens-cluster-store", - accessPropertiesByDotNotation: false, // To make dots safe in cluster context names - syncOptions: { - equals: comparer.structural, - }, - projectVersion: this.dependencies.storeMigrationVersion, - migrations: this.dependencies.migrations, - fromStore: action(({ clusters = [] }) => { - const currentClusters = new Map(this.clusters); - const newClusters = new Map(); - - // update new clusters - for (const clusterModel of clusters) { - try { - let cluster = currentClusters.get(clusterModel.id); - - if (cluster) { - cluster.updateModel(clusterModel); - } else { - cluster = new Cluster( - clusterModel, - this.dependencies.readClusterConfigSync(clusterModel), - ); - } - newClusters.set(clusterModel.id, cluster); - } catch (error) { - this.dependencies.logger.warn(`[CLUSTER-STORE]: Failed to update/create a cluster: ${error}`); - } - } - - this.clusters.replace(newClusters); - }), - toJSON: () => toJS({ - clusters: this.clustersList.get().map(cluster => cluster.toJSON()), - }), - }); - } - - readonly clustersList = computed(() => [...this.clusters.values()]); - - hasClusters() { - return this.clusters.size > 0; - } - - getById(id: ClusterId | undefined): Cluster | undefined { - if (id) { - return this.clusters.get(id); - } - - return undefined; - } - - addCluster(clusterOrModel: ClusterModel | Cluster): Cluster { - this.dependencies.emitAppEvent({ name: "cluster", action: "add" }); - - const cluster = clusterOrModel instanceof Cluster - ? clusterOrModel - : new Cluster( - clusterOrModel, - this.dependencies.readClusterConfigSync(clusterOrModel), - ); - - this.clusters.set(cluster.id, cluster); - - return cluster; - } - - load() { - this.store.loadAndStartSyncing(); - } -} diff --git a/packages/core/src/common/front-end-routing/routes/cluster/config/config-maps/config-maps-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/config/config-maps/config-maps-route.injectable.ts index 0ad7ed3d88..c6a525269c 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/config/config-maps/config-maps-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/config/config-maps/config-maps-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const configMapsRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/config/horizontal-pod-autoscalers/horizontal-pod-autoscalers-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/config/horizontal-pod-autoscalers/horizontal-pod-autoscalers-route.injectable.ts index 00002620ee..cef3bdcb5a 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/config/horizontal-pod-autoscalers/horizontal-pod-autoscalers-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/config/horizontal-pod-autoscalers/horizontal-pod-autoscalers-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const horizontalPodAutoscalersRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/config/leases/leases-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/config/leases/leases-route.injectable.ts index ea4eb2ae59..6da3564c8f 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/config/leases/leases-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/config/leases/leases-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const leasesRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/config/limit-ranges/limit-ranges-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/config/limit-ranges/limit-ranges-route.injectable.ts index 0536e76004..a80a9e8ef4 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/config/limit-ranges/limit-ranges-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/config/limit-ranges/limit-ranges-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const limitRangesRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/config/pod-disruption-budgets/pod-disruption-budgets-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/config/pod-disruption-budgets/pod-disruption-budgets-route.injectable.ts index 12ce0a2138..e297c7396e 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/config/pod-disruption-budgets/pod-disruption-budgets-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/config/pod-disruption-budgets/pod-disruption-budgets-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const podDisruptionBudgetsRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/config/priority-classes/priority-classes-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/config/priority-classes/priority-classes-route.injectable.ts index 75194b0541..ea424ec86d 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/config/priority-classes/priority-classes-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/config/priority-classes/priority-classes-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const priorityClassesRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/config/resource-quotas/resource-quotas-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/config/resource-quotas/resource-quotas-route.injectable.ts index 4905b70890..96704bbc80 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/config/resource-quotas/resource-quotas-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/config/resource-quotas/resource-quotas-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const resourceQuotasRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/config/runtime-classes/runtime-classes-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/config/runtime-classes/runtime-classes-route.injectable.ts index beab83754f..a088ee2ba4 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/config/runtime-classes/runtime-classes-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/config/runtime-classes/runtime-classes-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const runtimeClassesRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/config/secrets/secrets-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/config/secrets/secrets-route.injectable.ts index 7442de14b1..38343e4729 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/config/secrets/secrets-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/config/secrets/secrets-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const secretsRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/config/vertical-pod-autoscalers/vertical-pod-autoscalers-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/config/vertical-pod-autoscalers/vertical-pod-autoscalers-route.injectable.ts index 57776c8237..07559a8d2a 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/config/vertical-pod-autoscalers/vertical-pod-autoscalers-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/config/vertical-pod-autoscalers/vertical-pod-autoscalers-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const verticalPodAutoscalersRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/events/events-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/events/events-route.injectable.ts index 728f80c21d..fd4dfef75d 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/events/events-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/events/events-route.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 { shouldShowResourceInjectionToken } from "../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../front-end-route-injection-token"; const eventsRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/namespaces/namespaces-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/namespaces/namespaces-route.injectable.ts index 0b57c8d573..6fb569fc11 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/namespaces/namespaces-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/namespaces/namespaces-route.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 { shouldShowResourceInjectionToken } from "../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../front-end-route-injection-token"; const namespacesRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/network/endpoints/endpoints-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/network/endpoints/endpoints-route.injectable.ts index 50b3c72e4c..d8dcf8aa8f 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/network/endpoints/endpoints-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/network/endpoints/endpoints-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const endpointsRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/network/ingress-class/ingress-classeses-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/network/ingress-class/ingress-classeses-route.injectable.ts index e036d4b6a6..efde1d8d7a 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/network/ingress-class/ingress-classeses-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/network/ingress-class/ingress-classeses-route.injectable.ts @@ -6,7 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; import { shouldShowResourceInjectionToken, -} from "../../../../../cluster-store/allowed-resources-injection-token"; +} from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; const ingressClassesesRouteInjectable = getInjectable({ id: "ingress-classes-route", diff --git a/packages/core/src/common/front-end-routing/routes/cluster/network/ingresses/ingresses-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/network/ingresses/ingresses-route.injectable.ts index 3a6669d99f..c2a6fe33cc 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/network/ingresses/ingresses-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/network/ingresses/ingresses-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { computedOr } from "@k8slens/utilities"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/network/network-policies/network-policies-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/network/network-policies/network-policies-route.injectable.ts index 38a1b8a7e2..664eefa9f1 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/network/network-policies/network-policies-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/network/network-policies/network-policies-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const networkPoliciesRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/network/services/services-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/network/services/services-route.injectable.ts index 223ded1e65..e9b130b318 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/network/services/services-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/network/services/services-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const servicesRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/nodes/nodes-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/nodes/nodes-route.injectable.ts index e6ca61346e..1fe80a799b 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/nodes/nodes-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/nodes/nodes-route.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 { shouldShowResourceInjectionToken } from "../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../front-end-route-injection-token"; const nodesRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/overview/cluster-overview-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/overview/cluster-overview-route.injectable.ts index e559c35079..bf9c3961ed 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/overview/cluster-overview-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/overview/cluster-overview-route.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 { shouldShowResourceInjectionToken } from "../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../front-end-route-injection-token"; const clusterOverviewRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/storage/persistent-volume-claims/persistent-volume-claims-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/storage/persistent-volume-claims/persistent-volume-claims-route.injectable.ts index dbda527555..c8d7b64f8d 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/storage/persistent-volume-claims/persistent-volume-claims-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/storage/persistent-volume-claims/persistent-volume-claims-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const persistentVolumeClaimsRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/storage/persistent-volumes/persistent-volumes-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/storage/persistent-volumes/persistent-volumes-route.injectable.ts index 7a06d9df58..a93ac0a3c8 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/storage/persistent-volumes/persistent-volumes-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/storage/persistent-volumes/persistent-volumes-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const persistentVolumesRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/storage/storage-classes/storage-classes-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/storage/storage-classes/storage-classes-route.injectable.ts index 8702ab1602..0645c0f4eb 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/storage/storage-classes/storage-classes-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/storage/storage-classes/storage-classes-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const storageClassesRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/user-management/cluster-role-bindings/cluster-role-bindings-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/user-management/cluster-role-bindings/cluster-role-bindings-route.injectable.ts index 0903d5fced..158563f8d5 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/user-management/cluster-role-bindings/cluster-role-bindings-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/user-management/cluster-role-bindings/cluster-role-bindings-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const clusterRoleBindingsRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/user-management/cluster-roles/cluster-roles-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/user-management/cluster-roles/cluster-roles-route.injectable.ts index 9fce206667..db28d8dfff 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/user-management/cluster-roles/cluster-roles-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/user-management/cluster-roles/cluster-roles-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const clusterRolesRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/user-management/pod-security-policies/pod-security-policies-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/user-management/pod-security-policies/pod-security-policies-route.injectable.ts index 2f35986916..27f9165be8 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/user-management/pod-security-policies/pod-security-policies-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/user-management/pod-security-policies/pod-security-policies-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const podSecurityPoliciesRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/user-management/role-bindings/role-bindings-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/user-management/role-bindings/role-bindings-route.injectable.ts index 759c1b8eda..195210df23 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/user-management/role-bindings/role-bindings-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/user-management/role-bindings/role-bindings-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const roleBindingsRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/user-management/roles/roles-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/user-management/roles/roles-route.injectable.ts index efe4cad810..807a12177c 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/user-management/roles/roles-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/user-management/roles/roles-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const rolesRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/user-management/service-accounts/service-accounts-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/user-management/service-accounts/service-accounts-route.injectable.ts index 65d02135c7..aecc5a3640 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/user-management/service-accounts/service-accounts-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/user-management/service-accounts/service-accounts-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const serviceAccountsRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/workloads/cron-jobs/cron-jobs-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/workloads/cron-jobs/cron-jobs-route.injectable.ts index 33453a2247..0899486298 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/workloads/cron-jobs/cron-jobs-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/workloads/cron-jobs/cron-jobs-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const cronJobsRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/workloads/daemonsets/daemonsets-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/workloads/daemonsets/daemonsets-route.injectable.ts index f1ec2008fa..42f1329551 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/workloads/daemonsets/daemonsets-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/workloads/daemonsets/daemonsets-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const daemonsetsRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/workloads/deployments/deployments-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/workloads/deployments/deployments-route.injectable.ts index 84c059780f..222f842981 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/workloads/deployments/deployments-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/workloads/deployments/deployments-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const deploymentsRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/workloads/jobs/jobs-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/workloads/jobs/jobs-route.injectable.ts index 39cc89e88f..4933c69531 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/workloads/jobs/jobs-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/workloads/jobs/jobs-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const jobsRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/workloads/pods/pods-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/workloads/pods/pods-route.injectable.ts index d013f872f0..6563896893 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/workloads/pods/pods-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/workloads/pods/pods-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const podsRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/workloads/replicasets/replicasets-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/workloads/replicasets/replicasets-route.injectable.ts index b790ce13ec..bff60b2b8d 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/workloads/replicasets/replicasets-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/workloads/replicasets/replicasets-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const replicasetsRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/workloads/replicationcontrollers/replicationcontrollers-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/workloads/replicationcontrollers/replicationcontrollers-route.injectable.ts index 77d87abc96..c6ce4afafe 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/workloads/replicationcontrollers/replicationcontrollers-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/workloads/replicationcontrollers/replicationcontrollers-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const replicationControllersRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/routes/cluster/workloads/statefulsets/statefulsets-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/workloads/statefulsets/statefulsets-route.injectable.ts index 72c81b3bee..0a0160ccd9 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/workloads/statefulsets/statefulsets-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/workloads/statefulsets/statefulsets-route.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 { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; const statefulsetsRouteInjectable = getInjectable({ diff --git a/packages/core/src/common/front-end-routing/verify-that-all-routes-have-route-component.test.ts b/packages/core/src/common/front-end-routing/verify-that-all-routes-have-route-component.test.ts index 44f86f270d..a13a3f8929 100644 --- a/packages/core/src/common/front-end-routing/verify-that-all-routes-have-route-component.test.ts +++ b/packages/core/src/common/front-end-routing/verify-that-all-routes-have-route-component.test.ts @@ -6,22 +6,14 @@ import { getDiForUnitTesting } from "../../renderer/getDiForUnitTesting"; import { routeSpecificComponentInjectionToken } from "../../renderer/routes/route-specific-component-injection-token"; import { frontEndRouteInjectionToken } from "./front-end-route-injection-token"; import { filter, map } from "lodash/fp"; -import clusterStoreInjectable from "../cluster-store/cluster-store.injectable"; -import type { ClusterStore } from "../cluster-store/cluster-store"; import { pipeline } from "@ogre-tools/fp"; describe("verify-that-all-routes-have-component", () => { it("verify that routes have route component", () => { const rendererDi = getDiForUnitTesting(); - rendererDi.override(clusterStoreInjectable, () => ({ - getById: () => null, - } as unknown as ClusterStore)); - const routes = rendererDi.injectMany(frontEndRouteInjectionToken); - const routeComponents = rendererDi.injectMany( - routeSpecificComponentInjectionToken, - ); + const routeComponents = rendererDi.injectMany(routeSpecificComponentInjectionToken); const routesMissingComponent = pipeline( routes, diff --git a/packages/core/src/extensions/renderer-api/k8s-api.ts b/packages/core/src/extensions/renderer-api/k8s-api.ts index 1dfdc0e075..98e2cfcdfb 100644 --- a/packages/core/src/extensions/renderer-api/k8s-api.ts +++ b/packages/core/src/extensions/renderer-api/k8s-api.ts @@ -37,7 +37,7 @@ import namespaceApiInjectable from "../../common/k8s-api/endpoints/namespace.api import kubeEventApiInjectable from "../../common/k8s-api/endpoints/events.api.injectable"; import roleBindingApiInjectable from "../../common/k8s-api/endpoints/role-binding.api.injectable"; import customResourceDefinitionApiInjectable from "../../common/k8s-api/endpoints/custom-resource-definition.api.injectable"; -import { shouldShowResourceInjectionToken } from "../../common/cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { asLegacyGlobalFunctionForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api"; import requestMetricsInjectable from "../../common/k8s-api/endpoints/metrics.api/request-metrics.injectable"; diff --git a/packages/core/src/features/catalog/__snapshots__/opening-entity-details.test.tsx.snap b/packages/core/src/features/catalog/__snapshots__/opening-entity-details.test.tsx.snap index b6f79cb965..2c18525dfe 100644 --- a/packages/core/src/features/catalog/__snapshots__/opening-entity-details.test.tsx.snap +++ b/packages/core/src/features/catalog/__snapshots__/opening-entity-details.test.tsx.snap @@ -231,7 +231,7 @@ exports[`opening catalog entity details panel renders 1`] = ` class="HotbarSelector" > { let builder: ApplicationBuilder; let rendered: RenderResult; let windowDi: DiContainer; - let cluster: Cluster; let clusterEntity: KubernetesCluster; let localClusterEntity: KubernetesCluster; let otherEntity: WebLink; @@ -26,20 +25,7 @@ describe("opening catalog entity details panel", () => { beforeEach(async () => { builder = getApplicationBuilder(); - builder.beforeWindowStart(({ windowDi }) => { - // TODO: remove once ClusterStore can be used without overriding it - windowDi.override(getClusterByIdInjectable, () => (clusterId) => { - if (clusterId === cluster?.id) { - return cluster; - } - - return undefined; - }); - }); - - testUsingFakeTime(); - - builder.afterWindowStart(({ windowDi }) => { + builder.afterWindowStart(async ({ windowDi }) => { clusterEntity = new KubernetesCluster({ metadata: { labels: {}, @@ -82,12 +68,33 @@ describe("opening catalog entity details panel", () => { phase: "available", }, }); - cluster = new Cluster({ - contextName: clusterEntity.spec.kubeconfigContext, + + const writeJsonFile = windowDi.inject(writeJsonFileInjectable); + const addCluster = windowDi.inject(addClusterInjectable); + + await writeJsonFile(clusterEntity.spec.kubeconfigPath, { + contexts: [{ + name: clusterEntity.spec.kubeconfigContext, + context: { + cluster: "some-cluster", + user: "some-user", + }, + }], + clusters: [{ + name: "some-cluster", + cluster: { + server: "https://localhost:9999", + }, + }], + users: [{ + name: "some-user", + }], + }); + + addCluster({ id: clusterEntity.getId(), kubeConfigPath: clusterEntity.spec.kubeconfigPath, - }, { - clusterServerUrl: "https://localhost:9999", + contextName: clusterEntity.spec.kubeconfigContext, }); // TODO: replace with proper entity source once syncing entities between main and windows is injectable diff --git a/packages/core/src/features/cluster/activation/main/request-activation.injectable.ts b/packages/core/src/features/cluster/activation/main/request-activation.injectable.ts index c498040fc0..0bc51a6f6f 100644 --- a/packages/core/src/features/cluster/activation/main/request-activation.injectable.ts +++ b/packages/core/src/features/cluster/activation/main/request-activation.injectable.ts @@ -3,8 +3,8 @@ * 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 getClusterByIdInjectable from "../../storage/common/get-by-id.injectable"; import { requestClusterActivationInjectionToken } from "../common/request-token"; const requestClusterActivationInjectable = getInjectable({ diff --git a/packages/core/src/features/cluster/activation/main/request-deactivation.injectable.ts b/packages/core/src/features/cluster/activation/main/request-deactivation.injectable.ts index 05fc00911c..45585419dc 100644 --- a/packages/core/src/features/cluster/activation/main/request-deactivation.injectable.ts +++ b/packages/core/src/features/cluster/activation/main/request-deactivation.injectable.ts @@ -5,8 +5,8 @@ import { getInjectable } from "@ogre-tools/injectable"; import emitAppEventInjectable from "../../../../common/app-event-bus/emit-event.injectable"; import clusterFramesInjectable from "../../../../common/cluster-frames.injectable"; -import getClusterByIdInjectable from "../../../../common/cluster-store/get-by-id.injectable"; import clusterConnectionInjectable from "../../../../main/cluster/cluster-connection.injectable"; +import getClusterByIdInjectable from "../../storage/common/get-by-id.injectable"; import { requestClusterDeactivationInjectionToken } from "../common/request-token"; const requestClusterDeactivationInjectable = getInjectable({ diff --git a/packages/core/src/features/cluster/delete-dialog/main/delete-channel-listener.injectable.ts b/packages/core/src/features/cluster/delete-dialog/main/delete-channel-listener.injectable.ts index 30d976c59c..5b908a56c0 100644 --- a/packages/core/src/features/cluster/delete-dialog/main/delete-channel-listener.injectable.ts +++ b/packages/core/src/features/cluster/delete-dialog/main/delete-channel-listener.injectable.ts @@ -4,7 +4,6 @@ */ import emitAppEventInjectable from "../../../../common/app-event-bus/emit-event.injectable"; import clusterFramesInjectable from "../../../../common/cluster-frames.injectable"; -import clusterStoreInjectable from "../../../../common/cluster-store/cluster-store.injectable"; import directoryForLensLocalStorageInjectable from "../../../../common/directory-for-lens-local-storage/directory-for-lens-local-storage.injectable"; import removePathInjectable from "../../../../common/fs/remove.injectable"; import joinPathsInjectable from "../../../../common/path/join-paths.injectable"; @@ -12,22 +11,23 @@ import clusterConnectionInjectable from "../../../../main/cluster/cluster-connec import { noop } from "@k8slens/utilities"; import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; import { deleteClusterChannel } from "../common/delete-channel"; +import clustersStateInjectable from "../../storage/common/state.injectable"; const deleteClusterChannelListenerInjectable = getRequestChannelListenerInjectable({ id: "delete-cluster-channel-listener", channel: deleteClusterChannel, getHandler: (di) => { const emitAppEvent = di.inject(emitAppEventInjectable); - const clusterStore = di.inject(clusterStoreInjectable); const clusterFrames = di.inject(clusterFramesInjectable); const joinPaths = di.inject(joinPathsInjectable); const directoryForLensLocalStorage = di.inject(directoryForLensLocalStorageInjectable); const deleteFile = di.inject(removePathInjectable); + const clustersState = di.inject(clustersStateInjectable); return async (clusterId) => { emitAppEvent({ name: "cluster", action: "remove" }); - const cluster = clusterStore.getById(clusterId); + const cluster = clustersState.get(clusterId); if (!cluster) { return; @@ -37,9 +37,7 @@ const deleteClusterChannelListenerInjectable = getRequestChannelListenerInjectab clusterConnection.disconnect(); clusterFrames.delete(cluster.id); - - // Remove from the cluster store as well, this should clear any old settings - clusterStore.clusters.delete(cluster.id); + clustersState.delete(cluster.id); // remove the local storage file const localStorageFilePath = joinPaths(directoryForLensLocalStorage, `${cluster.id}.json`); diff --git a/packages/core/src/common/cluster-store/allowed-resources-injection-token.ts b/packages/core/src/features/cluster/showing-kube-resources/common/allowed-resources-injection-token.ts similarity index 84% rename from packages/core/src/common/cluster-store/allowed-resources-injection-token.ts rename to packages/core/src/features/cluster/showing-kube-resources/common/allowed-resources-injection-token.ts index 5b71038d04..317ed5a0ec 100644 --- a/packages/core/src/common/cluster-store/allowed-resources-injection-token.ts +++ b/packages/core/src/features/cluster/showing-kube-resources/common/allowed-resources-injection-token.ts @@ -5,7 +5,7 @@ import { getInjectionToken } from "@ogre-tools/injectable"; import type { IComputedValue } from "mobx"; -import type { KubeApiResourceDescriptor } from "../rbac"; +import type { KubeApiResourceDescriptor } from "../../../../common/rbac"; export const shouldShowResourceInjectionToken = getInjectionToken, KubeApiResourceDescriptor>({ id: "should-show-resource", diff --git a/packages/core/src/features/cluster/state-sync/main/handle-initial.injectable.ts b/packages/core/src/features/cluster/state-sync/main/handle-initial.injectable.ts index ddfc240f0f..75a68273a0 100644 --- a/packages/core/src/features/cluster/state-sync/main/handle-initial.injectable.ts +++ b/packages/core/src/features/cluster/state-sync/main/handle-initial.injectable.ts @@ -2,17 +2,17 @@ * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ -import clusterStoreInjectable from "../../../../common/cluster-store/cluster-store.injectable"; import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; +import clustersInjectable from "../../storage/common/clusters.injectable"; import { initialClusterStatesChannel } from "../common/channels"; const handleInitialClusterStateSyncInjectable = getRequestChannelListenerInjectable({ id: "handle-initial-cluster-state-sync", channel: initialClusterStatesChannel, getHandler: (di) => { - const clusterStore = di.inject(clusterStoreInjectable); + const clusters = di.inject(clustersInjectable); - return () => clusterStore.clustersList.get().map(cluster => ({ + return () => clusters.get().map(cluster => ({ clusterId: cluster.id, state: cluster.getState(), })); diff --git a/packages/core/src/features/cluster/state-sync/main/setup-sync.injectable.ts b/packages/core/src/features/cluster/state-sync/main/setup-sync.injectable.ts index 348450958d..927c93c148 100644 --- a/packages/core/src/features/cluster/state-sync/main/setup-sync.injectable.ts +++ b/packages/core/src/features/cluster/state-sync/main/setup-sync.injectable.ts @@ -5,22 +5,22 @@ import { getInjectable } from "@ogre-tools/injectable"; import { isEqual } from "lodash"; import { autorun } from "mobx"; -import clusterStoreInjectable from "../../../../common/cluster-store/cluster-store.injectable"; import type { ClusterId, ClusterState } from "../../../../common/cluster-types"; import { beforeApplicationIsLoadingInjectionToken } from "@k8slens/application"; -import initClusterStoreInjectable from "../../store/main/init.injectable"; +import initClusterStoreInjectable from "../../storage/main/init.injectable"; import emitClusterStateUpdateInjectable from "./emit-update.injectable"; +import clustersInjectable from "../../storage/common/clusters.injectable"; const setupClusterStateBroadcastingInjectable = getInjectable({ id: "setup-cluster-state-broadcasting", instantiate: (di) => ({ run: () => { const emitClusterStateUpdate = di.inject(emitClusterStateUpdateInjectable); - const clusterStore = di.inject(clusterStoreInjectable); + const clusters = di.inject(clustersInjectable); const prevStates = new Map(); autorun(() => { - for (const cluster of clusterStore.clusters.values()) { + for (const cluster of clusters.get()) { const prevState = prevStates.get(cluster.id); const curState = cluster.getState(); diff --git a/packages/core/src/features/cluster/state-sync/renderer/listener.injectable.ts b/packages/core/src/features/cluster/state-sync/renderer/listener.injectable.ts index a3778d096e..ec329f2c9d 100644 --- a/packages/core/src/features/cluster/state-sync/renderer/listener.injectable.ts +++ b/packages/core/src/features/cluster/state-sync/renderer/listener.injectable.ts @@ -2,8 +2,8 @@ * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ -import getClusterByIdInjectable from "../../../../common/cluster-store/get-by-id.injectable"; import { getMessageChannelListenerInjectable } from "@k8slens/messaging"; +import getClusterByIdInjectable from "../../storage/common/get-by-id.injectable"; import { clusterStateSyncChannel } from "../common/channels"; const clusterStateListenerInjectable = getMessageChannelListenerInjectable({ diff --git a/packages/core/src/features/cluster/state-sync/renderer/setup-sync.injectable.ts b/packages/core/src/features/cluster/state-sync/renderer/setup-sync.injectable.ts index da43ace234..43e1025f0a 100644 --- a/packages/core/src/features/cluster/state-sync/renderer/setup-sync.injectable.ts +++ b/packages/core/src/features/cluster/state-sync/renderer/setup-sync.injectable.ts @@ -3,9 +3,9 @@ * 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 { beforeFrameStartsSecondInjectionToken } from "../../../../renderer/before-frame-starts/tokens"; -import initClusterStoreInjectable from "../../store/renderer/init.injectable"; +import getClusterByIdInjectable from "../../storage/common/get-by-id.injectable"; +import initClusterStoreInjectable from "../../storage/renderer/init.injectable"; import requestInitialClusterStatesInjectable from "./request-initial.injectable"; const setupClusterStateSyncInjectable = getInjectable({ diff --git a/packages/core/src/common/__tests__/cluster-store.test.ts b/packages/core/src/features/cluster/storage/cluster-storage.test.ts similarity index 70% rename from packages/core/src/common/__tests__/cluster-store.test.ts rename to packages/core/src/features/cluster/storage/cluster-storage.test.ts index dc82998272..f11ae3a4c5 100644 --- a/packages/core/src/common/__tests__/cluster-store.test.ts +++ b/packages/core/src/features/cluster/storage/cluster-storage.test.ts @@ -3,29 +3,35 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ -import type { ClusterStore } from "../cluster-store/cluster-store"; -import type { GetCustomKubeConfigFilePath } from "../app-paths/get-custom-kube-config-directory/get-custom-kube-config-directory.injectable"; -import getCustomKubeConfigFilePathInjectable from "../app-paths/get-custom-kube-config-directory/get-custom-kube-config-directory.injectable"; -import clusterStoreInjectable from "../cluster-store/cluster-store.injectable"; +import type { GetCustomKubeConfigFilePath } from "../../../common/app-paths/get-custom-kube-config-directory/get-custom-kube-config-directory.injectable"; +import getCustomKubeConfigFilePathInjectable from "../../../common/app-paths/get-custom-kube-config-directory/get-custom-kube-config-directory.injectable"; import type { DiContainer } from "@ogre-tools/injectable"; -import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable"; -import { getDiForUnitTesting } from "../../main/getDiForUnitTesting"; +import directoryForUserDataInjectable from "../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable"; +import { getDiForUnitTesting } from "../../../main/getDiForUnitTesting"; import assert from "assert"; -import directoryForTempInjectable from "../app-paths/directory-for-temp/directory-for-temp.injectable"; -import kubectlBinaryNameInjectable from "../../main/kubectl/binary-name.injectable"; -import kubectlDownloadingNormalizedArchInjectable from "../../main/kubectl/normalized-arch.injectable"; -import normalizedPlatformInjectable from "../vars/normalized-platform.injectable"; -import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable"; -import type { WriteJsonSync } from "../fs/write-json-sync.injectable"; -import writeJsonSyncInjectable from "../fs/write-json-sync.injectable"; -import type { ReadFileSync } from "../fs/read-file-sync.injectable"; -import readFileSyncInjectable from "../fs/read-file-sync.injectable"; +import directoryForTempInjectable from "../../../common/app-paths/directory-for-temp/directory-for-temp.injectable"; +import kubectlBinaryNameInjectable from "../../../main/kubectl/binary-name.injectable"; +import kubectlDownloadingNormalizedArchInjectable from "../../../main/kubectl/normalized-arch.injectable"; +import normalizedPlatformInjectable from "../../../common/vars/normalized-platform.injectable"; +import storeMigrationVersionInjectable from "../../../common/vars/store-migration-version.injectable"; +import type { WriteJsonSync } from "../../../common/fs/write-json-sync.injectable"; +import writeJsonSyncInjectable from "../../../common/fs/write-json-sync.injectable"; +import type { ReadFileSync } from "../../../common/fs/read-file-sync.injectable"; +import readFileSyncInjectable from "../../../common/fs/read-file-sync.injectable"; import { readFileSync } from "fs"; -import type { WriteFileSync } from "../fs/write-file-sync.injectable"; -import writeFileSyncInjectable from "../fs/write-file-sync.injectable"; -import type { WriteBufferSync } from "../fs/write-buffer-sync.injectable"; -import writeBufferSyncInjectable from "../fs/write-buffer-sync.injectable"; -import { Cluster } from "../cluster/cluster"; +import type { WriteFileSync } from "../../../common/fs/write-file-sync.injectable"; +import writeFileSyncInjectable from "../../../common/fs/write-file-sync.injectable"; +import type { WriteBufferSync } from "../../../common/fs/write-buffer-sync.injectable"; +import writeBufferSyncInjectable from "../../../common/fs/write-buffer-sync.injectable"; +import { Cluster } from "../../../common/cluster/cluster"; +import clustersPersistentStorageInjectable from "./common/storage.injectable"; +import type { PersistentStorage } from "../../../common/persistent-storage/create.injectable"; +import type { AddCluster } from "./common/add.injectable"; +import addClusterInjectable from "./common/add.injectable"; +import type { GetClusterById } from "./common/get-by-id.injectable"; +import getClusterByIdInjectable from "./common/get-by-id.injectable"; +import type { IComputedValue } from "mobx"; +import clustersInjectable from "./common/clusters.injectable"; // NOTE: this is intended to read the actual file system const testDataIcon = readFileSync("test-data/cluster-store-migration-icon.png"); @@ -54,15 +60,18 @@ users: token: kubeconfig-user-q4lm4:xxxyyyy `; -describe("cluster-store", () => { +describe("cluster storage technical tests", () => { let di: DiContainer; - let clusterStore: ClusterStore; + let clustersPersistentStorage: PersistentStorage; let writeJsonSync: WriteJsonSync; let writeFileSync: WriteFileSync; let writeBufferSync: WriteBufferSync; let readFileSync: ReadFileSync; let getCustomKubeConfigFilePath: GetCustomKubeConfigFilePath; let writeFileSyncAndReturnPath: (filePath: string, contents: string) => string; + let addCluster: AddCluster; + let getClusterById: GetClusterById; + let clusters: IComputedValue; beforeEach(async () => { di = getDiForUnitTesting(); @@ -76,6 +85,9 @@ describe("cluster-store", () => { writeFileSync = di.inject(writeFileSyncInjectable); writeBufferSync = di.inject(writeBufferSyncInjectable); readFileSync = di.inject(readFileSyncInjectable); + addCluster = di.inject(addClusterInjectable); + getClusterById = di.inject(getClusterByIdInjectable); + clusters = di.inject(clustersInjectable); writeFileSyncAndReturnPath = (filePath, contents) => (writeFileSync(filePath, contents), filePath); }); @@ -84,8 +96,8 @@ describe("cluster-store", () => { getCustomKubeConfigFilePath = di.inject(getCustomKubeConfigFilePathInjectable); writeJsonSync("/some-directory-for-user-data/lens-cluster-store.json", {}); - clusterStore = di.inject(clusterStoreInjectable); - clusterStore.load(); + clustersPersistentStorage = di.inject(clustersPersistentStorageInjectable); + clustersPersistentStorage.loadAndStartSyncing(); }); describe("with foo cluster added", () => { @@ -106,11 +118,11 @@ describe("cluster-store", () => { clusterServerUrl, }); - clusterStore.addCluster(cluster); + addCluster(cluster); }); it("adds new cluster to store", async () => { - const storedCluster = clusterStore.getById("foo"); + const storedCluster = getClusterById("foo"); assert(storedCluster); @@ -124,9 +136,7 @@ describe("cluster-store", () => { describe("with prod and dev clusters added", () => { beforeEach(() => { - const store = clusterStore; - - store.addCluster({ + addCluster({ id: "prod", contextName: "foo", preferences: { @@ -137,7 +147,7 @@ describe("cluster-store", () => { kubeconfig, ), }); - store.addCluster({ + addCluster({ id: "dev", contextName: "foo2", preferences: { @@ -151,8 +161,7 @@ describe("cluster-store", () => { }); it("check if store can contain multiple clusters", () => { - expect(clusterStore.hasClusters()).toBeTruthy(); - expect(clusterStore.clusters.size).toBe(2); + expect(clusters.get().length).toBe(2); }); it("check if cluster's kubeconfig file saved", () => { @@ -199,11 +208,11 @@ describe("cluster-store", () => { getCustomKubeConfigFilePath = di.inject(getCustomKubeConfigFilePathInjectable); - clusterStore = di.inject(clusterStoreInjectable); - clusterStore.load(); + clustersPersistentStorage = di.inject(clustersPersistentStorageInjectable); + clustersPersistentStorage.loadAndStartSyncing(); }); it("allows to retrieve a cluster", () => { - const storedCluster = clusterStore.getById("cluster1"); + const storedCluster = getClusterById("cluster1"); assert(storedCluster); @@ -212,7 +221,7 @@ describe("cluster-store", () => { }); it("allows getting all of the clusters", async () => { - const storedClusters = clusterStore.clustersList.get(); + const storedClusters = clusters.get(); expect(storedClusters.length).toBe(3); expect(storedClusters[0].id).toBe("cluster1"); @@ -253,12 +262,12 @@ describe("cluster-store", () => { getCustomKubeConfigFilePath = di.inject(getCustomKubeConfigFilePathInjectable); - clusterStore = di.inject(clusterStoreInjectable); - clusterStore.load(); + clustersPersistentStorage = di.inject(clustersPersistentStorageInjectable); + clustersPersistentStorage.loadAndStartSyncing(); }); it("does not enable clusters with invalid kubeconfig", () => { - const storedClusters = clusterStore.clustersList.get(); + const storedClusters = clusters.get(); expect(storedClusters.length).toBe(1); }); @@ -290,18 +299,18 @@ describe("cluster-store", () => { writeBufferSync("/some-directory-for-user-data/icon_path", testDataIcon); - clusterStore = di.inject(clusterStoreInjectable); - clusterStore.load(); + clustersPersistentStorage = di.inject(clustersPersistentStorageInjectable); + clustersPersistentStorage.loadAndStartSyncing(); }); it("migrates to modern format with kubeconfig in a file", async () => { - const configPath = clusterStore.clustersList.get()[0].kubeConfigPath.get(); + const configPath = clusters.get()[0].kubeConfigPath.get(); expect(readFileSync(configPath)).toBe(minimalValidKubeConfig); }); it("migrates to modern format with icon not in file", async () => { - expect(clusterStore.clustersList.get()[0].preferences.icon).toMatch(/data:;base64,/); + expect(clusters.get()[0].preferences.icon).toMatch(/data:;base64,/); }); }); }); diff --git a/packages/core/src/features/cluster/storage/common/add.injectable.ts b/packages/core/src/features/cluster/storage/common/add.injectable.ts new file mode 100644 index 0000000000..051aa6d23b --- /dev/null +++ b/packages/core/src/features/cluster/storage/common/add.injectable.ts @@ -0,0 +1,39 @@ +/** + * 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 { action } from "mobx"; +import emitAppEventInjectable from "../../../../common/app-event-bus/emit-event.injectable"; +import readClusterConfigSyncInjectable from "./read-cluster-config.injectable"; +import type { ClusterModel } from "../../../../common/cluster-types"; +import { Cluster } from "../../../../common/cluster/cluster"; +import clustersStateInjectable from "./state.injectable"; + +export type AddCluster = (clusterOrModel: ClusterModel | Cluster) => Cluster; + +const addClusterInjectable = getInjectable({ + id: "add-cluster", + instantiate: (di): AddCluster => { + const clustersState = di.inject(clustersStateInjectable); + const emitAppEvent = di.inject(emitAppEventInjectable); + const readClusterConfigSync = di.inject(readClusterConfigSyncInjectable); + + return action((clusterOrModel) => { + emitAppEvent({ name: "cluster", action: "add" }); + + const cluster = clusterOrModel instanceof Cluster + ? clusterOrModel + : new Cluster( + clusterOrModel, + readClusterConfigSync(clusterOrModel), + ); + + clustersState.set(cluster.id, cluster); + + return cluster; + }); + }, +}); + +export default addClusterInjectable; diff --git a/packages/core/src/features/cluster/storage/common/clusters.injectable.ts b/packages/core/src/features/cluster/storage/common/clusters.injectable.ts new file mode 100644 index 0000000000..d251cf784f --- /dev/null +++ b/packages/core/src/features/cluster/storage/common/clusters.injectable.ts @@ -0,0 +1,18 @@ +/** + * 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 { computed } from "mobx"; +import clustersStateInjectable from "./state.injectable"; + +const clustersInjectable = getInjectable({ + id: "clusters", + instantiate: (di) => { + const clustersState = di.inject(clustersStateInjectable); + + return computed(() => [...clustersState.values()]); + }, +}); + +export default clustersInjectable; diff --git a/packages/core/src/common/cluster-store/get-by-id.injectable.ts b/packages/core/src/features/cluster/storage/common/get-by-id.injectable.ts similarity index 59% rename from packages/core/src/common/cluster-store/get-by-id.injectable.ts rename to packages/core/src/features/cluster/storage/common/get-by-id.injectable.ts index 534bdb5e76..2e3128f4d6 100644 --- a/packages/core/src/common/cluster-store/get-by-id.injectable.ts +++ b/packages/core/src/features/cluster/storage/common/get-by-id.injectable.ts @@ -3,18 +3,18 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import type { ClusterId } from "../cluster-types"; -import type { Cluster } from "../cluster/cluster"; -import clusterStoreInjectable from "./cluster-store.injectable"; +import type { ClusterId } from "../../../../common/cluster-types"; +import type { Cluster } from "../../../../common/cluster/cluster"; +import clustersStateInjectable from "./state.injectable"; export type GetClusterById = (id: ClusterId) => Cluster | undefined; const getClusterByIdInjectable = getInjectable({ id: "get-cluster-by-id", instantiate: (di): GetClusterById => { - const store = di.inject(clusterStoreInjectable); + const clustersState = di.inject(clustersStateInjectable); - return (id) => store.getById(id); + return (id) => clustersState.get(id); }, }); diff --git a/packages/core/src/common/cluster-store/migration-token.ts b/packages/core/src/features/cluster/storage/common/migration-token.ts similarity index 76% rename from packages/core/src/common/cluster-store/migration-token.ts rename to packages/core/src/features/cluster/storage/common/migration-token.ts index a0efa74e5a..8fa8064cf6 100644 --- a/packages/core/src/common/cluster-store/migration-token.ts +++ b/packages/core/src/features/cluster/storage/common/migration-token.ts @@ -4,7 +4,7 @@ */ import { getInjectionToken } from "@ogre-tools/injectable"; -import type { MigrationDeclaration } from "../persistent-storage/migrations.injectable"; +import type { MigrationDeclaration } from "../../../../common/persistent-storage/migrations.injectable"; export const clusterStoreMigrationInjectionToken = getInjectionToken({ id: "cluster-store-migration", diff --git a/packages/core/src/common/cluster-store/read-cluster-config.injectable.ts b/packages/core/src/features/cluster/storage/common/read-cluster-config.injectable.ts similarity index 77% rename from packages/core/src/common/cluster-store/read-cluster-config.injectable.ts rename to packages/core/src/features/cluster/storage/common/read-cluster-config.injectable.ts index 9fea013b16..9b3be7733e 100644 --- a/packages/core/src/common/cluster-store/read-cluster-config.injectable.ts +++ b/packages/core/src/features/cluster/storage/common/read-cluster-config.injectable.ts @@ -3,9 +3,9 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import type { ClusterConfigData, ClusterModel } from "../cluster-types"; -import readFileSyncInjectable from "../fs/read-file-sync.injectable"; -import { loadConfigFromString, validateKubeConfig } from "../kube-helpers"; +import type { ClusterConfigData, ClusterModel } from "../../../../common/cluster-types"; +import readFileSyncInjectable from "../../../../common/fs/read-file-sync.injectable"; +import { loadConfigFromString, validateKubeConfig } from "../../../../common/kube-helpers"; export type ReadClusterConfigSync = (model: ClusterModel) => ClusterConfigData; diff --git a/packages/core/src/features/cluster/storage/common/state.injectable.ts b/packages/core/src/features/cluster/storage/common/state.injectable.ts new file mode 100644 index 0000000000..a3234dcb62 --- /dev/null +++ b/packages/core/src/features/cluster/storage/common/state.injectable.ts @@ -0,0 +1,15 @@ +/** + * 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 { observable } from "mobx"; +import type { ClusterId } from "../../../../common/cluster-types"; +import type { Cluster } from "../../../../common/cluster/cluster"; + +const clustersStateInjectable = getInjectable({ + id: "clusters-state", + instantiate: () => observable.map(), +}); + +export default clustersStateInjectable; diff --git a/packages/core/src/features/cluster/storage/common/storage.injectable.ts b/packages/core/src/features/cluster/storage/common/storage.injectable.ts new file mode 100644 index 0000000000..e2778275c4 --- /dev/null +++ b/packages/core/src/features/cluster/storage/common/storage.injectable.ts @@ -0,0 +1,74 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ +import { iter } from "@k8slens/utilities"; +import { getInjectable } from "@ogre-tools/injectable"; +import { comparer, action } from "mobx"; +import { clusterStoreMigrationInjectionToken } from "./migration-token"; +import readClusterConfigSyncInjectable from "./read-cluster-config.injectable"; +import type { ClusterId, ClusterModel } from "../../../../common/cluster-types"; +import { Cluster } from "../../../../common/cluster/cluster"; +import loggerInjectable from "../../../../common/logger.injectable"; +import createPersistentStorageInjectable from "../../../../common/persistent-storage/create.injectable"; +import persistentStorageMigrationsInjectable from "../../../../common/persistent-storage/migrations.injectable"; +import storeMigrationVersionInjectable from "../../../../common/vars/store-migration-version.injectable"; +import clustersStateInjectable from "./state.injectable"; + +export interface ClusterStoreModel { + clusters?: ClusterModel[]; +} + +const clustersPersistentStorageInjectable = getInjectable({ + id: "clusters-persistent-storage", + instantiate: (di) => { + const createPersistentStorage = di.inject(createPersistentStorageInjectable); + const readClusterConfigSync = di.inject(readClusterConfigSyncInjectable); + const clustersState = di.inject(clustersStateInjectable); + const logger = di.inject(loggerInjectable); + const storeMigrationVersion = di.inject(storeMigrationVersionInjectable); + const migrations = di.inject(persistentStorageMigrationsInjectable, clusterStoreMigrationInjectionToken); + + return createPersistentStorage({ + configName: "lens-cluster-store", + accessPropertiesByDotNotation: false, // To make dots safe in cluster context names + syncOptions: { + equals: comparer.structural, + }, + projectVersion: storeMigrationVersion, + migrations, + fromStore: action(({ clusters = [] }) => { + const currentClusters = new Map(clustersState); + const newClusters = new Map(); + + // update new clusters + for (const clusterModel of clusters) { + try { + let cluster = currentClusters.get(clusterModel.id); + + if (cluster) { + cluster.updateModel(clusterModel); + } else { + cluster = new Cluster( + clusterModel, + readClusterConfigSync(clusterModel), + ); + } + newClusters.set(clusterModel.id, cluster); + } catch (error) { + logger.warn(`[CLUSTER-STORE]: Failed to update/create a cluster: ${error}`); + } + } + + clustersState.replace(newClusters); + }), + toJSON: () => ({ + clusters: iter.chain(clustersState.values()) + .map(cluster => cluster.toJSON()) + .toArray(), + }), + }); + }, +}); + +export default clustersPersistentStorageInjectable; diff --git a/packages/core/src/features/cluster/store/main/init.injectable.ts b/packages/core/src/features/cluster/storage/main/init.injectable.ts similarity index 77% rename from packages/core/src/features/cluster/store/main/init.injectable.ts rename to packages/core/src/features/cluster/storage/main/init.injectable.ts index c7a6bc1c9a..230357c7e2 100644 --- a/packages/core/src/features/cluster/store/main/init.injectable.ts +++ b/packages/core/src/features/cluster/storage/main/init.injectable.ts @@ -3,17 +3,17 @@ * 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 { beforeApplicationIsLoadingInjectionToken } from "@k8slens/application"; import initUserStoreInjectable from "../../../../main/stores/init-user-store.injectable"; +import clustersPersistentStorageInjectable from "../common/storage.injectable"; const initClusterStoreInjectable = getInjectable({ id: "init-cluster-store", instantiate: (di) => ({ run: () => { - const clusterStore = di.inject(clusterStoreInjectable); + const storage = di.inject(clustersPersistentStorageInjectable); - clusterStore.load(); + storage.loadAndStartSyncing(); }, runAfter: initUserStoreInjectable, }), diff --git a/packages/core/src/features/cluster/store/renderer/init.injectable.ts b/packages/core/src/features/cluster/storage/renderer/init.injectable.ts similarity index 78% rename from packages/core/src/features/cluster/store/renderer/init.injectable.ts rename to packages/core/src/features/cluster/storage/renderer/init.injectable.ts index f937796bae..cff2bb358b 100644 --- a/packages/core/src/features/cluster/store/renderer/init.injectable.ts +++ b/packages/core/src/features/cluster/storage/renderer/init.injectable.ts @@ -3,17 +3,17 @@ * 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 { beforeFrameStartsSecondInjectionToken } from "../../../../renderer/before-frame-starts/tokens"; import initUserStoreInjectable from "../../../../renderer/stores/init-user-store.injectable"; +import clustersPersistentStorageInjectable from "../common/storage.injectable"; const initClusterStoreInjectable = getInjectable({ id: "init-cluster-store", instantiate: (di) => ({ run: () => { - const clusterStore = di.inject(clusterStoreInjectable); + const storage = di.inject(clustersPersistentStorageInjectable); - clusterStore.load(); + storage.loadAndStartSyncing(); }, runAfter: initUserStoreInjectable, }), diff --git a/packages/core/src/features/cluster/visibility-of-sidebar-items.test.tsx b/packages/core/src/features/cluster/visibility-of-sidebar-items.test.tsx index bc96800562..46a8916241 100644 --- a/packages/core/src/features/cluster/visibility-of-sidebar-items.test.tsx +++ b/packages/core/src/features/cluster/visibility-of-sidebar-items.test.tsx @@ -13,7 +13,7 @@ import { frontEndRouteInjectionToken } from "../../common/front-end-routing/fron import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import { navigateToRouteInjectionToken } from "../../common/front-end-routing/navigate-to-route-injection-token"; -import { shouldShowResourceInjectionToken } from "../../common/cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "./showing-kube-resources/common/allowed-resources-injection-token"; describe("cluster - visibility of sidebar items", () => { let builder: ApplicationBuilder; diff --git a/packages/core/src/features/entity-settings/__snapshots__/showing-settings-for-correct-entity.test.tsx.snap b/packages/core/src/features/entity-settings/__snapshots__/showing-settings-for-correct-entity.test.tsx.snap index f8addbd6b9..9fd9b2feb8 100644 --- a/packages/core/src/features/entity-settings/__snapshots__/showing-settings-for-correct-entity.test.tsx.snap +++ b/packages/core/src/features/entity-settings/__snapshots__/showing-settings-for-correct-entity.test.tsx.snap @@ -231,7 +231,7 @@ exports[`Showing correct entity settings renders 1`] = ` class="HotbarSelector" > { let builder: ApplicationBuilder; @@ -19,23 +19,11 @@ describe("Showing correct entity settings", () => { let clusterEntity: KubernetesCluster; let localClusterEntity: KubernetesCluster; let otherEntity: WebLink; - let cluster: Cluster; beforeEach(async () => { builder = getApplicationBuilder(); - builder.beforeWindowStart(({ windowDi }) => { - // TODO: remove once ClusterStore can be used without overriding it - windowDi.override(getClusterByIdInjectable, () => (clusterId) => { - if (clusterId === cluster.id) { - return cluster; - } - - return undefined; - }); - }); - - builder.afterWindowStart(({ windowDi }) => { + builder.afterWindowStart(async ({ windowDi }) => { clusterEntity = new KubernetesCluster({ metadata: { labels: {}, @@ -78,14 +66,34 @@ describe("Showing correct entity settings", () => { phase: "available", }, }); - cluster = new Cluster({ - contextName: clusterEntity.spec.kubeconfigContext, - id: clusterEntity.getId(), - kubeConfigPath: clusterEntity.spec.kubeconfigPath, - }, { - clusterServerUrl: "https://localhost:9999", + + const writeJsonFile = windowDi.inject(writeJsonFileInjectable); + const addCluster = windowDi.inject(addClusterInjectable); + + await writeJsonFile(clusterEntity.spec.kubeconfigPath, { + contexts: [{ + name: clusterEntity.spec.kubeconfigContext, + context: { + cluster: "some-cluster", + user: "some-user", + }, + }], + clusters: [{ + name: "some-cluster", + cluster: { + server: "https://localhost:9999", + }, + }], + users: [{ + name: "some-user", + }], }); + addCluster({ + id: clusterEntity.getId(), + kubeConfigPath: clusterEntity.spec.kubeconfigPath, + contextName: clusterEntity.spec.kubeconfigContext, + }); // TODO: replace with proper entity source once syncing entities between main and windows is injectable const catalogEntityRegistry = windowDi.inject(catalogEntityRegistryInjectable); diff --git a/packages/core/src/features/hotbar/store/renderer/init.injectable.ts b/packages/core/src/features/hotbar/store/renderer/init.injectable.ts index 239807dfda..bb6c2da259 100644 --- a/packages/core/src/features/hotbar/store/renderer/init.injectable.ts +++ b/packages/core/src/features/hotbar/store/renderer/init.injectable.ts @@ -5,7 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import hotbarStoreInjectable from "../../../../common/hotbars/store.injectable"; import { beforeFrameStartsSecondInjectionToken } from "../../../../renderer/before-frame-starts/tokens"; -import initClusterStoreInjectable from "../../../cluster/store/renderer/init.injectable"; +import initClusterStoreInjectable from "../../../cluster/storage/renderer/init.injectable"; const initHotbarStoreInjectable = getInjectable({ id: "init-hotbar-store", diff --git a/packages/core/src/main/catalog-sources/__test__/kubeconfig-sync.test.ts b/packages/core/src/main/catalog-sources/__test__/kubeconfig-sync.test.ts index 42ffbedf30..9625d7399c 100644 --- a/packages/core/src/main/catalog-sources/__test__/kubeconfig-sync.test.ts +++ b/packages/core/src/main/catalog-sources/__test__/kubeconfig-sync.test.ts @@ -19,7 +19,6 @@ import kubeconfigSyncManagerInjectable from "../kubeconfig-sync/manager.injectab import type { KubeconfigSyncManager } from "../kubeconfig-sync/manager"; import type { KubeconfigSyncValue } from "../../../common/user-store"; import kubeconfigSyncsInjectable from "../../../common/user-store/kubeconfig-syncs.injectable"; -import getClusterByIdInjectable from "../../../common/cluster-store/get-by-id.injectable"; import type { DiContainer } from "@ogre-tools/injectable"; import type { AsyncFnMock } from "@async-fn/jest"; import type { Stat } from "../../../common/fs/stat.injectable"; @@ -41,7 +40,6 @@ describe("kubeconfig-sync.source tests", () => { let computeKubeconfigDiff: ComputeKubeconfigDiff; let configToModels: ConfigToModels; let kubeconfigSyncs: ObservableMap; - let clusters: Map; let di: DiContainer; beforeEach(async () => { @@ -58,9 +56,6 @@ describe("kubeconfig-sync.source tests", () => { ensurePath: async () => "/some-proxy-kubeconfig-file", } as Partial as KubeconfigManager)); - clusters = new Map(); - di.override(getClusterByIdInjectable, () => id => clusters.get(id)); - kubeconfigSyncs = observable.map(); di.override(kubeconfigSyncsInjectable, () => kubeconfigSyncs); diff --git a/packages/core/src/main/catalog-sources/kubeconfig-sync/compute-diff.injectable.ts b/packages/core/src/main/catalog-sources/kubeconfig-sync/compute-diff.injectable.ts index 3b81e82382..87475931fe 100644 --- a/packages/core/src/main/catalog-sources/kubeconfig-sync/compute-diff.injectable.ts +++ b/packages/core/src/main/catalog-sources/kubeconfig-sync/compute-diff.injectable.ts @@ -9,7 +9,6 @@ import { action } from "mobx"; import { homedir } from "os"; import directoryForKubeConfigsInjectable from "../../../common/app-paths/directory-for-kube-configs/directory-for-kube-configs.injectable"; import type { CatalogEntity } from "../../../common/catalog"; -import getClusterByIdInjectable from "../../../common/cluster-store/get-by-id.injectable"; import { Cluster } from "../../../common/cluster/cluster"; import { loadConfigFromString } from "../../../common/kube-helpers"; import clustersThatAreBeingDeletedInjectable from "../../cluster/are-being-deleted.injectable"; @@ -17,6 +16,7 @@ import { catalogEntityFromCluster } from "../../cluster/manager"; import configToModelsInjectable from "./config-to-models.injectable"; import kubeconfigSyncLoggerInjectable from "./logger.injectable"; import clusterConnectionInjectable from "../../cluster/cluster-connection.injectable"; +import getClusterByIdInjectable from "../../../features/cluster/storage/common/get-by-id.injectable"; export type ComputeKubeconfigDiff = (contents: string, source: ObservableMap, filePath: string) => void; diff --git a/packages/core/src/main/cluster/manager.injectable.ts b/packages/core/src/main/cluster/manager.injectable.ts index e1567e51b6..21530dfe4d 100644 --- a/packages/core/src/main/cluster/manager.injectable.ts +++ b/packages/core/src/main/cluster/manager.injectable.ts @@ -3,8 +3,10 @@ * 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 loggerInjectable from "../../common/logger.injectable"; +import addClusterInjectable from "../../features/cluster/storage/common/add.injectable"; +import clustersInjectable from "../../features/cluster/storage/common/clusters.injectable"; +import getClusterByIdInjectable from "../../features/cluster/storage/common/get-by-id.injectable"; import catalogEntityRegistryInjectable from "../catalog/entity-registry.injectable"; import clustersThatAreBeingDeletedInjectable from "./are-being-deleted.injectable"; import clusterConnectionInjectable from "./cluster-connection.injectable"; @@ -17,11 +19,13 @@ const clusterManagerInjectable = getInjectable({ id: "cluster-manager", instantiate: (di) => new ClusterManager({ - store: di.inject(clusterStoreInjectable), catalogEntityRegistry: di.inject(catalogEntityRegistryInjectable), clustersThatAreBeingDeleted: di.inject(clustersThatAreBeingDeletedInjectable), visibleCluster: di.inject(visibleClusterInjectable), logger: di.inject(loggerInjectable), + addCluster: di.inject(addClusterInjectable), + clusters: di.inject(clustersInjectable), + getClusterById: di.inject(getClusterByIdInjectable), updateEntityMetadata: di.inject(updateEntityMetadataInjectable), updateEntitySpec: di.inject(updateEntitySpecInjectable), getClusterConnection: (cluster) => di.inject(clusterConnectionInjectable, cluster), diff --git a/packages/core/src/main/cluster/manager.ts b/packages/core/src/main/cluster/manager.ts index 2277d8fced..f9f844bd9f 100644 --- a/packages/core/src/main/cluster/manager.ts +++ b/packages/core/src/main/cluster/manager.ts @@ -4,34 +4,37 @@ */ import "../../common/ipc/cluster"; -import type { IObservableValue, ObservableSet } from "mobx"; +import type { IComputedValue, IObservableValue, ObservableSet } from "mobx"; import { action, makeObservable, observe, reaction, toJS } from "mobx"; import type { Cluster } from "../../common/cluster/cluster"; import { isErrnoException } from "@k8slens/utilities"; 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 { Logger } from "../../common/logger"; import type { UpdateEntityMetadata } from "./update-entity-metadata.injectable"; import type { UpdateEntitySpec } from "./update-entity-spec.injectable"; import type { ClusterConnection } from "./cluster-connection.injectable"; +import type { GetClusterById } from "../../features/cluster/storage/common/get-by-id.injectable"; +import type { AddCluster } from "../../features/cluster/storage/common/add.injectable"; const logPrefix = "[CLUSTER-MANAGER]:"; const lensSpecificClusterStatuses: Set = new Set(Object.values(LensKubernetesClusterStatus)); interface Dependencies { - readonly store: ClusterStore; readonly catalogEntityRegistry: CatalogEntityRegistry; readonly clustersThatAreBeingDeleted: ObservableSet; readonly visibleCluster: IObservableValue; readonly logger: Logger; + readonly clusters: IComputedValue; updateEntityMetadata: UpdateEntityMetadata; updateEntitySpec: UpdateEntitySpec; getClusterConnection: (cluster: Cluster) => ClusterConnection; + getClusterById: GetClusterById; + addCluster: AddCluster; } export class ClusterManager { @@ -42,15 +45,15 @@ export class ClusterManager { init = once(() => { // reacting to every cluster's state change and total amount of items reaction( - () => this.dependencies.store.clustersList.get().map(c => c.getState()), - () => this.updateCatalog(this.dependencies.store.clustersList.get()), + () => this.dependencies.clusters.get().map(c => c.getState()), + () => this.updateCatalog(this.dependencies.clusters.get()), { fireImmediately: false }, ); // reacting to every cluster's preferences change and total amount of items reaction( - () => this.dependencies.store.clustersList.get().map(c => toJS(c.preferences)), - () => this.updateCatalog(this.dependencies.store.clustersList.get()), + () => this.dependencies.clusters.get().map(c => toJS(c.preferences)), + () => this.updateCatalog(this.dependencies.clusters.get()), { fireImmediately: false }, ); @@ -152,7 +155,7 @@ export class ClusterManager { @action protected syncClustersFromCatalog(entities: KubernetesCluster[]) { for (const entity of entities) { - const cluster = this.dependencies.store.getById(entity.getId()); + const cluster = this.dependencies.getClusterById(entity.getId()); if (!cluster) { const model = { @@ -167,7 +170,7 @@ export class ClusterManager { * Add the bare minimum of data to ClusterStore. And especially no * preferences, as those might be configured by the entity's source */ - this.dependencies.store.addCluster(model); + this.dependencies.addCluster(model); } catch (error) { if (isErrnoException(error) && error.code === "ENOENT" && error.path === entity.spec.kubeconfigPath) { this.dependencies.logger.warn(`${logPrefix} kubeconfig file disappeared`, model); @@ -208,8 +211,8 @@ export class ClusterManager { this.dependencies.logger.info(`${logPrefix} network is offline`); await Promise.allSettled( - this.dependencies.store - .clustersList + this.dependencies + .clusters .get() .filter(cluster => !cluster.disconnected.get()) .map(async (cluster) => { @@ -227,8 +230,8 @@ export class ClusterManager { this.dependencies.logger.info(`${logPrefix} network is online`); await Promise.allSettled( - this.dependencies.store - .clustersList + this.dependencies + .clusters .get() .filter(cluster => !cluster.disconnected.get()) .map((cluster) => ( @@ -240,7 +243,7 @@ export class ClusterManager { }; stop() { - for (const cluster of this.dependencies.store.clustersList.get()) { + for (const cluster of this.dependencies.clusters.get()) { this.dependencies .getClusterConnection(cluster) .disconnect(); diff --git a/packages/core/src/main/cluster/store-migrations/3.6.0-beta.1.injectable.ts b/packages/core/src/main/cluster/store-migrations/3.6.0-beta.1.injectable.ts index 9b8bb83e2b..5f43359d8d 100644 --- a/packages/core/src/main/cluster/store-migrations/3.6.0-beta.1.injectable.ts +++ b/packages/core/src/main/cluster/store-migrations/3.6.0-beta.1.injectable.ts @@ -18,7 +18,7 @@ interface Pre360ClusterModel extends ClusterModel { } import { getInjectable } from "@ogre-tools/injectable"; -import { clusterStoreMigrationInjectionToken } from "../../../common/cluster-store/migration-token"; +import { clusterStoreMigrationInjectionToken } from "../../../features/cluster/storage/common/migration-token"; import readFileBufferSyncInjectable from "../../../common/fs/read-file-buffer-sync.injectable"; import loggerInjectable from "../../../common/logger.injectable"; import writeFileSyncInjectable from "../../../common/fs/write-file-sync.injectable"; diff --git a/packages/core/src/main/cluster/store-migrations/5.0.0-beta.10.injectable.ts b/packages/core/src/main/cluster/store-migrations/5.0.0-beta.10.injectable.ts index 026ded3d1b..3ba3629578 100644 --- a/packages/core/src/main/cluster/store-migrations/5.0.0-beta.10.injectable.ts +++ b/packages/core/src/main/cluster/store-migrations/5.0.0-beta.10.injectable.ts @@ -4,7 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import directoryForUserDataInjectable from "../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable"; -import { clusterStoreMigrationInjectionToken } from "../../../common/cluster-store/migration-token"; +import { clusterStoreMigrationInjectionToken } from "../../../features/cluster/storage/common/migration-token"; import type { ClusterModel } from "../../../common/cluster-types"; import readJsonSyncInjectable from "../../../common/fs/read-json-sync.injectable"; import joinPathsInjectable from "../../../common/path/join-paths.injectable"; diff --git a/packages/core/src/main/cluster/store-migrations/5.0.0-beta.13.injectable.ts b/packages/core/src/main/cluster/store-migrations/5.0.0-beta.13.injectable.ts index 9137c81fed..6c33cfa2c4 100644 --- a/packages/core/src/main/cluster/store-migrations/5.0.0-beta.13.injectable.ts +++ b/packages/core/src/main/cluster/store-migrations/5.0.0-beta.13.injectable.ts @@ -10,7 +10,7 @@ import { isDefined } from "@k8slens/utilities"; import joinPathsInjectable from "../../../common/path/join-paths.injectable"; import { getInjectable } from "@ogre-tools/injectable"; import loggerInjectable from "../../../common/logger.injectable"; -import { clusterStoreMigrationInjectionToken } from "../../../common/cluster-store/migration-token"; +import { clusterStoreMigrationInjectionToken } from "../../../features/cluster/storage/common/migration-token"; import { generateNewIdFor } from "../../../common/utils/generate-new-id-for"; interface Pre500ClusterModel extends ClusterModel { diff --git a/packages/core/src/main/cluster/store-migrations/snap.injectable.ts b/packages/core/src/main/cluster/store-migrations/snap.injectable.ts index d4efc37612..f20f0a4820 100644 --- a/packages/core/src/main/cluster/store-migrations/snap.injectable.ts +++ b/packages/core/src/main/cluster/store-migrations/snap.injectable.ts @@ -6,7 +6,7 @@ // Fix embedded kubeconfig paths under snap config import { getInjectable } from "@ogre-tools/injectable"; -import { clusterStoreMigrationInjectionToken } from "../../../common/cluster-store/migration-token"; +import { clusterStoreMigrationInjectionToken } from "../../../features/cluster/storage/common/migration-token"; import loggerInjectable from "../../../common/logger.injectable"; import isSnapPackageInjectable from "../../../common/vars/is-snap-package.injectable"; import type { ClusterModel } from "../../../common/cluster-types"; diff --git a/packages/core/src/main/create-cluster/allowed-resources.injectable.ts b/packages/core/src/main/create-cluster/allowed-resources.injectable.ts index 09beae9fd2..7b520fd29a 100644 --- a/packages/core/src/main/create-cluster/allowed-resources.injectable.ts +++ b/packages/core/src/main/create-cluster/allowed-resources.injectable.ts @@ -4,7 +4,7 @@ */ import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable"; import { computed } from "mobx"; -import { shouldShowResourceInjectionToken } from "../../common/cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import type { KubeApiResourceDescriptor } from "../../common/rbac"; import { formatKubeApiResource } from "../../common/rbac"; diff --git a/packages/core/src/main/electron-app/runnables/setup-ipc-main-handlers/setup-ipc-main-handlers.injectable.ts b/packages/core/src/main/electron-app/runnables/setup-ipc-main-handlers/setup-ipc-main-handlers.injectable.ts index cdf120dad7..61e37642e1 100644 --- a/packages/core/src/main/electron-app/runnables/setup-ipc-main-handlers/setup-ipc-main-handlers.injectable.ts +++ b/packages/core/src/main/electron-app/runnables/setup-ipc-main-handlers/setup-ipc-main-handlers.injectable.ts @@ -5,12 +5,12 @@ import { getInjectable } from "@ogre-tools/injectable"; import { setupIpcMainHandlers } from "./setup-ipc-main-handlers"; import loggerInjectable from "../../../../common/logger.injectable"; -import clusterStoreInjectable from "../../../../common/cluster-store/cluster-store.injectable"; import { onLoadOfApplicationInjectionToken } from "@k8slens/application"; import applicationMenuItemCompositeInjectable from "../../../../features/application-menu/main/application-menu-item-composite.injectable"; -import getClusterByIdInjectable from "../../../../common/cluster-store/get-by-id.injectable"; import pushCatalogToRendererInjectable from "../../../catalog-sync-to-renderer/push-catalog-to-renderer.injectable"; import clusterFramesInjectable from "../../../../common/cluster-frames.injectable"; +import getClusterByIdInjectable from "../../../../features/cluster/storage/common/get-by-id.injectable"; +import clustersInjectable from "../../../../features/cluster/storage/common/clusters.injectable"; const setupIpcMainHandlersInjectable = getInjectable({ id: "setup-ipc-main-handlers", @@ -24,7 +24,7 @@ const setupIpcMainHandlersInjectable = getInjectable({ setupIpcMainHandlers({ applicationMenuItemComposite: di.inject(applicationMenuItemCompositeInjectable), pushCatalogToRenderer: di.inject(pushCatalogToRendererInjectable), - clusterStore: di.inject(clusterStoreInjectable), + clusters: di.inject(clustersInjectable), getClusterById: di.inject(getClusterByIdInjectable), clusterFrames: di.inject(clusterFramesInjectable), }); diff --git a/packages/core/src/main/electron-app/runnables/setup-ipc-main-handlers/setup-ipc-main-handlers.ts b/packages/core/src/main/electron-app/runnables/setup-ipc-main-handlers/setup-ipc-main-handlers.ts index 874b14747a..6fdd498910 100644 --- a/packages/core/src/main/electron-app/runnables/setup-ipc-main-handlers/setup-ipc-main-handlers.ts +++ b/packages/core/src/main/electron-app/runnables/setup-ipc-main-handlers/setup-ipc-main-handlers.ts @@ -7,7 +7,6 @@ import { BrowserWindow, Menu } from "electron"; import type { ClusterFrameInfo } from "../../../../common/cluster-frames.injectable"; import { clusterSetFrameIdHandler, clusterStates } from "../../../../common/ipc/cluster"; import type { ClusterId } from "../../../../common/cluster-types"; -import type { ClusterStore } from "../../../../common/cluster-store/cluster-store"; import { broadcastMainChannel, broadcastMessage, ipcMainHandle, ipcMainOn } from "../../../../common/ipc"; import type { IComputedValue, ObservableMap } from "mobx"; import { windowActionHandleChannel, windowLocationChangedChannel, windowOpenAppMenuAsContextMenuChannel } from "../../../../common/ipc/window"; @@ -16,21 +15,23 @@ import type { ApplicationMenuItemTypes } from "../../../../features/application- import type { Composite } from "../../../../common/utils/composite/get-composite/get-composite"; import { getApplicationMenuTemplate } from "../../../../features/application-menu/main/populate-application-menu.injectable"; import type { MenuItemRoot } from "../../../../features/application-menu/main/application-menu-item-composite.injectable"; -import type { GetClusterById } from "../../../../common/cluster-store/get-by-id.injectable"; +import type { GetClusterById } from "../../../../features/cluster/storage/common/get-by-id.injectable"; +import type { Cluster } from "../../../../common/cluster/cluster"; + interface Dependencies { applicationMenuItemComposite: IComputedValue>; - clusterStore: ClusterStore; getClusterById: GetClusterById; pushCatalogToRenderer: () => void; clusterFrames: ObservableMap; + clusters: IComputedValue; } export const setupIpcMainHandlers = ({ applicationMenuItemComposite, - clusterStore, getClusterById, pushCatalogToRenderer, clusterFrames, + clusters, }: Dependencies) => { ipcMainHandle(clusterSetFrameIdHandler, (event: IpcMainInvokeEvent, clusterId: ClusterId) => { const cluster = getClusterById(clusterId); @@ -60,7 +61,7 @@ export const setupIpcMainHandlers = ({ }); ipcMainHandle(clusterStates, () => ( - clusterStore.clustersList.get().map(cluster => ({ + clusters.get().map(cluster => ({ id: cluster.id, state: cluster.getState(), })) diff --git a/packages/core/src/main/kubectl/apply-all-handler.injectable.ts b/packages/core/src/main/kubectl/apply-all-handler.injectable.ts index 00f58e5e3f..fb5f3a040f 100644 --- a/packages/core/src/main/kubectl/apply-all-handler.injectable.ts +++ b/packages/core/src/main/kubectl/apply-all-handler.injectable.ts @@ -3,8 +3,8 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import emitAppEventInjectable from "../../common/app-event-bus/emit-event.injectable"; -import getClusterByIdInjectable from "../../common/cluster-store/get-by-id.injectable"; import { kubectlApplyAllChannel } from "../../common/kube-helpers/channels"; +import getClusterByIdInjectable from "../../features/cluster/storage/common/get-by-id.injectable"; import resourceApplierInjectable from "../resource-applier/create-resource-applier.injectable"; import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; @@ -15,14 +15,16 @@ const kubectlApplyAllChannelHandlerInjectable = getRequestChannelListenerInjecta const getClusterById = di.inject(getClusterByIdInjectable); const emitAppEvent = di.inject(emitAppEventInjectable); - return async ({ - clusterId, - extraArgs, - resources, - }) => { - emitAppEvent({ name: "cluster", action: "kubectl-apply-all" }); + return async (event) => { + const { + clusterId, + extraArgs, + resources, + } = event; const cluster = getClusterById(clusterId); + emitAppEvent({ name: "cluster", action: "kubectl-apply-all" }); + if (!cluster) { return { callWasSuccessful: false, diff --git a/packages/core/src/main/kubectl/delete-all-handler.injectable.ts b/packages/core/src/main/kubectl/delete-all-handler.injectable.ts index 5d207be482..b7e21b4d8e 100644 --- a/packages/core/src/main/kubectl/delete-all-handler.injectable.ts +++ b/packages/core/src/main/kubectl/delete-all-handler.injectable.ts @@ -3,8 +3,8 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import emitAppEventInjectable from "../../common/app-event-bus/emit-event.injectable"; -import getClusterByIdInjectable from "../../common/cluster-store/get-by-id.injectable"; import { kubectlDeleteAllChannel } from "../../common/kube-helpers/channels"; +import getClusterByIdInjectable from "../../features/cluster/storage/common/get-by-id.injectable"; import resourceApplierInjectable from "../resource-applier/create-resource-applier.injectable"; import { getRequestChannelListenerInjectable } from "@k8slens/messaging"; @@ -15,15 +15,16 @@ const kubectlDeleteAllChannelHandlerInjectable = getRequestChannelListenerInject const emitAppEvent = di.inject(emitAppEventInjectable); const getClusterById = di.inject(getClusterByIdInjectable); - return async ({ - clusterId, - extraArgs, - resources, - }) => { - emitAppEvent({ name: "cluster", action: "kubectl-delete-all" }); - + return async (event) => { + const { + clusterId, + extraArgs, + resources, + } = event; const cluster = getClusterById(clusterId); + emitAppEvent({ name: "cluster", action: "kubectl-delete-all" }); + if (!cluster) { return { callWasSuccessful: false, diff --git a/packages/core/src/main/lens-proxy/get-cluster-for-request.injectable.ts b/packages/core/src/main/lens-proxy/get-cluster-for-request.injectable.ts index 7d529540d1..8be8d1d4e4 100644 --- a/packages/core/src/main/lens-proxy/get-cluster-for-request.injectable.ts +++ b/packages/core/src/main/lens-proxy/get-cluster-for-request.injectable.ts @@ -3,9 +3,9 @@ * 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 { getClusterIdFromHost } from "../../common/utils"; import { apiKubePrefix } from "../../common/vars"; +import getClusterByIdInjectable from "../../features/cluster/storage/common/get-by-id.injectable"; import type { GetClusterForRequest } from "./lens-proxy"; const getClusterForRequestInjectable = getInjectable({ diff --git a/packages/core/src/main/user-store/migrations/5.0.3-beta.1.injectable.ts b/packages/core/src/main/user-store/migrations/5.0.3-beta.1.injectable.ts index 7739c67e66..66a324f87c 100644 --- a/packages/core/src/main/user-store/migrations/5.0.3-beta.1.injectable.ts +++ b/packages/core/src/main/user-store/migrations/5.0.3-beta.1.injectable.ts @@ -3,7 +3,6 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ -import type { ClusterStoreModel } from "../../../common/cluster-store/cluster-store"; import type { KubeconfigSyncEntry, UserPreferencesModel } from "../../../common/user-store"; import { isErrnoException } from "@k8slens/utilities"; import directoryForUserDataInjectable from "../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable"; @@ -17,6 +16,7 @@ import readJsonSyncInjectable from "../../../common/fs/read-json-sync.injectable import homeDirectoryPathInjectable from "../../../common/os/home-directory-path.injectable"; import loggerInjectable from "../../../common/logger.injectable"; import pathExistsSyncInjectable from "../../../common/fs/path-exists-sync.injectable"; +import type { ClusterStoreModel } from "../../../features/cluster/storage/common/storage.injectable"; const v503Beta1UserStoreMigrationInjectable = getInjectable({ id: "v5.0.3-beta.1-user-store-migration", diff --git a/packages/core/src/renderer/api/catalog/entity/get-active-cluster-entity.injectable.ts b/packages/core/src/renderer/api/catalog/entity/get-active-cluster-entity.injectable.ts index b856c15ffd..5a8c691c82 100644 --- a/packages/core/src/renderer/api/catalog/entity/get-active-cluster-entity.injectable.ts +++ b/packages/core/src/renderer/api/catalog/entity/get-active-cluster-entity.injectable.ts @@ -4,16 +4,24 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { computed } from "mobx"; -import clusterStoreInjectable from "../../../../common/cluster-store/cluster-store.injectable"; +import getClusterByIdInjectable from "../../../../features/cluster/storage/common/get-by-id.injectable"; import catalogEntityRegistryInjectable from "./registry.injectable"; const activeEntityInternalClusterInjectable = getInjectable({ id: "active-entity-internal-cluster", instantiate: (di) => { - const store = di.inject(clusterStoreInjectable); + const getClusterById = di.inject(getClusterByIdInjectable); const entityRegistry = di.inject(catalogEntityRegistryInjectable); - return computed(() => store.getById(entityRegistry.activeEntity?.getId())); + return computed(() => { + const entityId = entityRegistry.activeEntity?.getId(); + + if (entityId) { + return getClusterById(entityId); + } + + return undefined; + }); }, }); diff --git a/packages/core/src/renderer/before-frame-starts/runnables/setup-kubernetes-cluster-context-menu-open.injectable.ts b/packages/core/src/renderer/before-frame-starts/runnables/setup-kubernetes-cluster-context-menu-open.injectable.ts index 0775b501b5..d175ce2899 100644 --- a/packages/core/src/renderer/before-frame-starts/runnables/setup-kubernetes-cluster-context-menu-open.injectable.ts +++ b/packages/core/src/renderer/before-frame-starts/runnables/setup-kubernetes-cluster-context-menu-open.injectable.ts @@ -4,9 +4,9 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import catalogCategoryRegistryInjectable from "../../../common/catalog/category-registry.injectable"; -import getClusterByIdInjectable from "../../../common/cluster-store/get-by-id.injectable"; import loadKubeconfigInjectable from "../../../common/cluster/load-kubeconfig.injectable"; import loggerInjectable from "../../../common/logger.injectable"; +import getClusterByIdInjectable from "../../../features/cluster/storage/common/get-by-id.injectable"; import openDeleteClusterDialogInjectable from "../../components/delete-cluster-dialog/open.injectable"; import { beforeFrameStartsSecondInjectionToken } from "../tokens"; diff --git a/packages/core/src/renderer/cluster-frame-context/hosted-cluster.injectable.ts b/packages/core/src/renderer/cluster-frame-context/hosted-cluster.injectable.ts index a466984952..934a660188 100644 --- a/packages/core/src/renderer/cluster-frame-context/hosted-cluster.injectable.ts +++ b/packages/core/src/renderer/cluster-frame-context/hosted-cluster.injectable.ts @@ -4,16 +4,20 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import hostedClusterIdInjectable from "./hosted-cluster-id.injectable"; -import clusterStoreInjectable from "../../common/cluster-store/cluster-store.injectable"; +import getClusterByIdInjectable from "../../features/cluster/storage/common/get-by-id.injectable"; const hostedClusterInjectable = getInjectable({ id: "hosted-cluster", instantiate: (di) => { const hostedClusterId = di.inject(hostedClusterIdInjectable); - const store = di.inject(clusterStoreInjectable); + const getClusterById = di.inject(getClusterByIdInjectable); - return store.getById(hostedClusterId); + if (!hostedClusterId) { + return undefined; + } + + return getClusterById(hostedClusterId); }, }); diff --git a/packages/core/src/renderer/cluster-frame-context/should-show-resource.injectable.ts b/packages/core/src/renderer/cluster-frame-context/should-show-resource.injectable.ts index 6258796a0b..39b6070c3b 100644 --- a/packages/core/src/renderer/cluster-frame-context/should-show-resource.injectable.ts +++ b/packages/core/src/renderer/cluster-frame-context/should-show-resource.injectable.ts @@ -5,7 +5,7 @@ import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable"; import { computed } from "mobx"; import hostedClusterInjectable from "./hosted-cluster.injectable"; -import { shouldShowResourceInjectionToken } from "../../common/cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import type { KubeApiResourceDescriptor } from "../../common/rbac"; import { formatKubeApiResource } from "../../common/rbac"; diff --git a/packages/core/src/renderer/components/+entity-settings/internal-kubernetes-cluster/general-settings.injectable.tsx b/packages/core/src/renderer/components/+entity-settings/internal-kubernetes-cluster/general-settings.injectable.tsx index 059f8c15eb..64d4028f24 100644 --- a/packages/core/src/renderer/components/+entity-settings/internal-kubernetes-cluster/general-settings.injectable.tsx +++ b/packages/core/src/renderer/components/+entity-settings/internal-kubernetes-cluster/general-settings.injectable.tsx @@ -6,8 +6,8 @@ import { getInjectable } from "@ogre-tools/injectable"; import { withInjectables } from "@ogre-tools/injectable-react"; import React from "react"; import type { KubernetesCluster } from "../../../../common/catalog-entities"; -import type { GetClusterById } from "../../../../common/cluster-store/get-by-id.injectable"; -import getClusterByIdInjectable from "../../../../common/cluster-store/get-by-id.injectable"; +import type { GetClusterById } from "../../../../features/cluster/storage/common/get-by-id.injectable"; +import getClusterByIdInjectable from "../../../../features/cluster/storage/common/get-by-id.injectable"; import { ClusterIconSetting } from "../../cluster-settings/icon-settings"; import { ClusterKubeconfig } from "../../cluster-settings/kubeconfig"; import { ClusterNameSetting } from "../../cluster-settings/name-setting"; diff --git a/packages/core/src/renderer/components/+entity-settings/internal-kubernetes-cluster/metrics-settings.injectable.tsx b/packages/core/src/renderer/components/+entity-settings/internal-kubernetes-cluster/metrics-settings.injectable.tsx index 1be5f7e78a..0a860300a3 100644 --- a/packages/core/src/renderer/components/+entity-settings/internal-kubernetes-cluster/metrics-settings.injectable.tsx +++ b/packages/core/src/renderer/components/+entity-settings/internal-kubernetes-cluster/metrics-settings.injectable.tsx @@ -5,8 +5,8 @@ import { getInjectable } from "@ogre-tools/injectable"; import { withInjectables } from "@ogre-tools/injectable-react"; import React from "react"; -import type { GetClusterById } from "../../../../common/cluster-store/get-by-id.injectable"; -import getClusterByIdInjectable from "../../../../common/cluster-store/get-by-id.injectable"; +import type { GetClusterById } from "../../../../features/cluster/storage/common/get-by-id.injectable"; +import getClusterByIdInjectable from "../../../../features/cluster/storage/common/get-by-id.injectable"; import { ClusterMetricsSetting } from "../../cluster-settings/metrics-setting"; import { ClusterPrometheusSetting } from "../../cluster-settings/prometheus-setting"; import { ShowMetricsSetting } from "../../cluster-settings/show-metrics"; diff --git a/packages/core/src/renderer/components/+entity-settings/internal-kubernetes-cluster/namespace-settings.injectable.tsx b/packages/core/src/renderer/components/+entity-settings/internal-kubernetes-cluster/namespace-settings.injectable.tsx index a7c86265b8..c84827f2a7 100644 --- a/packages/core/src/renderer/components/+entity-settings/internal-kubernetes-cluster/namespace-settings.injectable.tsx +++ b/packages/core/src/renderer/components/+entity-settings/internal-kubernetes-cluster/namespace-settings.injectable.tsx @@ -5,8 +5,8 @@ import { getInjectable } from "@ogre-tools/injectable"; import { withInjectables } from "@ogre-tools/injectable-react"; import React from "react"; -import type { GetClusterById } from "../../../../common/cluster-store/get-by-id.injectable"; -import getClusterByIdInjectable from "../../../../common/cluster-store/get-by-id.injectable"; +import type { GetClusterById } from "../../../../features/cluster/storage/common/get-by-id.injectable"; +import getClusterByIdInjectable from "../../../../features/cluster/storage/common/get-by-id.injectable"; import { ClusterAccessibleNamespaces } from "../../cluster-settings/accessible-namespaces"; import type { EntitySettingViewProps } from "../extension-registrator.injectable"; import { entitySettingInjectionToken } from "../token"; diff --git a/packages/core/src/renderer/components/+entity-settings/internal-kubernetes-cluster/node-shell-settings.injectable.tsx b/packages/core/src/renderer/components/+entity-settings/internal-kubernetes-cluster/node-shell-settings.injectable.tsx index ff899095d6..1a1424b5b3 100644 --- a/packages/core/src/renderer/components/+entity-settings/internal-kubernetes-cluster/node-shell-settings.injectable.tsx +++ b/packages/core/src/renderer/components/+entity-settings/internal-kubernetes-cluster/node-shell-settings.injectable.tsx @@ -5,8 +5,8 @@ import { getInjectable } from "@ogre-tools/injectable"; import { withInjectables } from "@ogre-tools/injectable-react"; import React from "react"; -import type { GetClusterById } from "../../../../common/cluster-store/get-by-id.injectable"; -import getClusterByIdInjectable from "../../../../common/cluster-store/get-by-id.injectable"; +import type { GetClusterById } from "../../../../features/cluster/storage/common/get-by-id.injectable"; +import getClusterByIdInjectable from "../../../../features/cluster/storage/common/get-by-id.injectable"; import { ClusterNodeShellSetting } from "../../cluster-settings/node-shell-setting"; import type { EntitySettingViewProps } from "../extension-registrator.injectable"; import { entitySettingInjectionToken } from "../token"; diff --git a/packages/core/src/renderer/components/+entity-settings/internal-kubernetes-cluster/proxy-settings.injectable.tsx b/packages/core/src/renderer/components/+entity-settings/internal-kubernetes-cluster/proxy-settings.injectable.tsx index 4479a04c2a..90b30ce7d2 100644 --- a/packages/core/src/renderer/components/+entity-settings/internal-kubernetes-cluster/proxy-settings.injectable.tsx +++ b/packages/core/src/renderer/components/+entity-settings/internal-kubernetes-cluster/proxy-settings.injectable.tsx @@ -5,8 +5,8 @@ import { getInjectable } from "@ogre-tools/injectable"; import { withInjectables } from "@ogre-tools/injectable-react"; import React from "react"; -import type { GetClusterById } from "../../../../common/cluster-store/get-by-id.injectable"; -import getClusterByIdInjectable from "../../../../common/cluster-store/get-by-id.injectable"; +import type { GetClusterById } from "../../../../features/cluster/storage/common/get-by-id.injectable"; +import getClusterByIdInjectable from "../../../../features/cluster/storage/common/get-by-id.injectable"; import { ClusterProxySetting } from "../../cluster-settings/proxy-setting"; import type { EntitySettingViewProps } from "../extension-registrator.injectable"; import { entitySettingInjectionToken } from "../token"; diff --git a/packages/core/src/renderer/components/+entity-settings/internal-kubernetes-cluster/terminal-settings.injectable.tsx b/packages/core/src/renderer/components/+entity-settings/internal-kubernetes-cluster/terminal-settings.injectable.tsx index e778c97728..6448c935bc 100644 --- a/packages/core/src/renderer/components/+entity-settings/internal-kubernetes-cluster/terminal-settings.injectable.tsx +++ b/packages/core/src/renderer/components/+entity-settings/internal-kubernetes-cluster/terminal-settings.injectable.tsx @@ -5,8 +5,8 @@ import { getInjectable } from "@ogre-tools/injectable"; import { withInjectables } from "@ogre-tools/injectable-react"; import React from "react"; -import type { GetClusterById } from "../../../../common/cluster-store/get-by-id.injectable"; -import getClusterByIdInjectable from "../../../../common/cluster-store/get-by-id.injectable"; +import type { GetClusterById } from "../../../../features/cluster/storage/common/get-by-id.injectable"; +import getClusterByIdInjectable from "../../../../features/cluster/storage/common/get-by-id.injectable"; import { ClusterLocalTerminalSetting } from "../../cluster-settings/local-terminal-settings"; import type { EntitySettingViewProps } from "../extension-registrator.injectable"; import { entitySettingInjectionToken } from "../token"; diff --git a/packages/core/src/renderer/components/+workloads-overview/workloads/workloads.injectable.ts b/packages/core/src/renderer/components/+workloads-overview/workloads/workloads.injectable.ts index d6b23b582f..a90e3d63d9 100644 --- a/packages/core/src/renderer/components/+workloads-overview/workloads/workloads.injectable.ts +++ b/packages/core/src/renderer/components/+workloads-overview/workloads/workloads.injectable.ts @@ -4,7 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { computed } from "mobx"; -import { shouldShowResourceInjectionToken } from "../../../../common/cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { byOrderNumber } from "../../../../common/utils/composable-responsibilities/orderable/orderable"; import { workloadInjectionToken } from "./workload-injection-token"; diff --git a/packages/core/src/renderer/components/cluster-manager/cluster-frame-handler.injectable.ts b/packages/core/src/renderer/components/cluster-manager/cluster-frame-handler.injectable.ts index 3f40455527..079bf22b2d 100644 --- a/packages/core/src/renderer/components/cluster-manager/cluster-frame-handler.injectable.ts +++ b/packages/core/src/renderer/components/cluster-manager/cluster-frame-handler.injectable.ts @@ -3,8 +3,8 @@ * 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 loggerInjectable from "../../../common/logger.injectable"; +import getClusterByIdInjectable from "../../../features/cluster/storage/common/get-by-id.injectable"; import { ClusterFrameHandler } from "./cluster-frame-handler"; import emitClusterVisibilityInjectable from "./emit-cluster-visibility.injectable"; diff --git a/packages/core/src/renderer/components/cluster-manager/cluster-frame-handler.ts b/packages/core/src/renderer/components/cluster-manager/cluster-frame-handler.ts index 7420fa680a..eca0e28e11 100644 --- a/packages/core/src/renderer/components/cluster-manager/cluster-frame-handler.ts +++ b/packages/core/src/renderer/components/cluster-manager/cluster-frame-handler.ts @@ -9,8 +9,8 @@ import type { Disposer } from "@k8slens/utilities"; import { onceDefined } from "@k8slens/utilities"; import assert from "assert"; import type { Logger } from "../../../common/logger"; -import type { GetClusterById } from "../../../common/cluster-store/get-by-id.injectable"; import { getClusterFrameUrl } from "../../../common/utils"; +import type { GetClusterById } from "../../../features/cluster/storage/common/get-by-id.injectable"; export interface LensView { isLoaded: boolean; diff --git a/packages/core/src/renderer/components/cluster-manager/cluster-view.tsx b/packages/core/src/renderer/components/cluster-manager/cluster-view.tsx index 6749fdd9d3..1e5062b313 100644 --- a/packages/core/src/renderer/components/cluster-manager/cluster-view.tsx +++ b/packages/core/src/renderer/components/cluster-manager/cluster-view.tsx @@ -18,10 +18,10 @@ import clusterViewRouteParametersInjectable from "./cluster-view-route-parameter import clusterFrameHandlerInjectable from "./cluster-frame-handler.injectable"; import type { CatalogEntityRegistry } from "../../api/catalog/entity/registry"; import catalogEntityRegistryInjectable from "../../api/catalog/entity/registry.injectable"; -import type { GetClusterById } 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"; +import type { GetClusterById } from "../../../features/cluster/storage/common/get-by-id.injectable"; +import getClusterByIdInjectable from "../../../features/cluster/storage/common/get-by-id.injectable"; interface Dependencies { clusterId: IComputedValue; diff --git a/packages/core/src/renderer/initializers/workload-events.tsx b/packages/core/src/renderer/initializers/workload-events.tsx index 73251382c8..945746cb2f 100644 --- a/packages/core/src/renderer/initializers/workload-events.tsx +++ b/packages/core/src/renderer/initializers/workload-events.tsx @@ -7,7 +7,7 @@ import { withInjectables } from "@ogre-tools/injectable-react"; import type { IComputedValue } from "mobx"; import { observer } from "mobx-react"; import React from "react"; -import { shouldShowResourceInjectionToken } from "../../common/cluster-store/allowed-resources-injection-token"; +import { shouldShowResourceInjectionToken } from "../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { Events } from "../components/+events/events"; export interface WorkloadEventsProps {} diff --git a/packages/core/src/renderer/ipc/list-namespaces-forbidden-handler.injectable.tsx b/packages/core/src/renderer/ipc/list-namespaces-forbidden-handler.injectable.tsx index 4acf8182b1..f8c850e7f1 100644 --- a/packages/core/src/renderer/ipc/list-namespaces-forbidden-handler.injectable.tsx +++ b/packages/core/src/renderer/ipc/list-namespaces-forbidden-handler.injectable.tsx @@ -10,8 +10,8 @@ import type { IpcRendererEvent } from "electron"; import React from "react"; import notificationsStoreInjectable from "../components/notifications/notifications-store.injectable"; import { getMillisecondsFromUnixEpoch } from "../../common/utils/date/get-current-date-time"; -import getClusterByIdInjectable from "../../common/cluster-store/get-by-id.injectable"; import showSuccessNotificationInjectable from "../components/notifications/show-success-notification.injectable"; +import getClusterByIdInjectable from "../../features/cluster/storage/common/get-by-id.injectable"; const intervalBetweenNotifications = 1000 * 60; // 60s diff --git a/packages/core/src/renderer/protocol-handler/bind-protocol-add-route-handlers/bind-protocol-add-route-handlers.injectable.ts b/packages/core/src/renderer/protocol-handler/bind-protocol-add-route-handlers/bind-protocol-add-route-handlers.injectable.ts index 1d378df375..c4497dfaeb 100644 --- a/packages/core/src/renderer/protocol-handler/bind-protocol-add-route-handlers/bind-protocol-add-route-handlers.injectable.ts +++ b/packages/core/src/renderer/protocol-handler/bind-protocol-add-route-handlers/bind-protocol-add-route-handlers.injectable.ts @@ -12,11 +12,9 @@ import navigateToExtensionsInjectable from "../../../common/front-end-routing/ro import navigateToEntitySettingsInjectable from "../../../common/front-end-routing/routes/entity-settings/navigate-to-entity-settings.injectable"; import navigateToClusterViewInjectable from "../../../common/front-end-routing/routes/cluster-view/navigate-to-cluster-view.injectable"; import catalogEntityRegistryInjectable from "../../api/catalog/entity/registry.injectable"; - -// TODO: Importing from features is not OK. Make protocol-router to comply with Open Closed Principle to allow moving implementation under a feature import navigateToPreferencesInjectable from "../../../features/preferences/common/navigate-to-preferences.injectable"; -import getClusterByIdInjectable from "../../../common/cluster-store/get-by-id.injectable"; import showShortInfoNotificationInjectable from "../../components/notifications/show-short-info.injectable"; +import getClusterByIdInjectable from "../../../features/cluster/storage/common/get-by-id.injectable"; const bindProtocolAddRouteHandlersInjectable = getInjectable({ id: "bind-protocol-add-route-handlers", diff --git a/packages/core/src/renderer/protocol-handler/bind-protocol-add-route-handlers/bind-protocol-add-route-handlers.tsx b/packages/core/src/renderer/protocol-handler/bind-protocol-add-route-handlers/bind-protocol-add-route-handlers.tsx index 4bcf207340..bf80d6c4d4 100644 --- a/packages/core/src/renderer/protocol-handler/bind-protocol-add-route-handlers/bind-protocol-add-route-handlers.tsx +++ b/packages/core/src/renderer/protocol-handler/bind-protocol-add-route-handlers/bind-protocol-add-route-handlers.tsx @@ -17,7 +17,7 @@ import type { NavigateToEntitySettings } from "../../../common/front-end-routing import type { NavigateToClusterView } from "../../../common/front-end-routing/routes/cluster-view/navigate-to-cluster-view.injectable"; import assert from "assert"; import type { AttemptInstallByInfo } from "../../components/+extensions/attempt-install-by-info.injectable"; -import type { GetClusterById } from "../../../common/cluster-store/get-by-id.injectable"; +import type { GetClusterById } from "../../../features/cluster/storage/common/get-by-id.injectable"; interface Dependencies { attemptInstallByInfo: AttemptInstallByInfo;