diff --git a/src/common/cluster-store.ts b/src/common/cluster-store.ts index be716cbba6..8e8940c644 100644 --- a/src/common/cluster-store.ts +++ b/src/common/cluster-store.ts @@ -19,13 +19,11 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import path from "path"; -import { app, ipcMain, ipcRenderer, remote, webFrame } from "electron"; +import { ipcMain, ipcRenderer, webFrame } from "electron"; import { action, comparer, computed, makeObservable, observable, reaction } from "mobx"; import { BaseStore } from "./base-store"; import { Cluster } from "../main/cluster"; import migrations from "../migrations/cluster-store"; -import * as uuid from "uuid"; import logger from "../main/logger"; import { appEventBus } from "./event-bus"; import { ipcMainHandle, ipcMainOn, ipcRendererOn, requestMain } from "./ipc"; @@ -38,19 +36,9 @@ export interface ClusterStoreModel { const initialStates = "cluster:states"; -export const initialNodeShellImage = "docker.io/alpine:3.13"; - export class ClusterStore extends BaseStore { private static StateChannel = "cluster:state"; - static get storedKubeConfigFolder(): string { - return path.resolve((app ?? remote.app).getPath("userData"), "kubeconfigs"); - } - - static getCustomKubeConfigPath(clusterId: ClusterId = uuid.v4()): string { - return path.resolve(ClusterStore.storedKubeConfigFolder, clusterId); - } - clusters = observable.map(); removedClusters = observable.map(); diff --git a/src/main/catalog-sources/kubeconfig-sync.ts b/src/main/catalog-sources/kubeconfig-sync.ts index 2f755d52d7..0ade5f0a8d 100644 --- a/src/main/catalog-sources/kubeconfig-sync.ts +++ b/src/main/catalog-sources/kubeconfig-sync.ts @@ -26,7 +26,7 @@ import { watch } from "chokidar"; import fs from "fs"; import fse from "fs-extra"; import type stream from "stream"; -import { Disposer, ExtendedObservableMap, iter, Singleton } from "../../common/utils"; +import { Disposer, ExtendedObservableMap, iter, Singleton, storedKubeConfigFolder } from "../../common/utils"; import logger from "../logger"; import type { KubeConfig } from "@kubernetes/client-node"; import { loadConfigFromString, splitConfig } from "../../common/kube-helpers"; @@ -71,7 +71,7 @@ export class KubeconfigSyncManager extends Singleton { ))); // This must be done so that c&p-ed clusters are visible - this.startNewSync(ClusterStore.storedKubeConfigFolder); + this.startNewSync(storedKubeConfigFolder()); for (const filePath of UserStore.getInstance().syncKubeconfigEntries.keys()) { this.startNewSync(filePath); @@ -202,7 +202,7 @@ export function computeDiff(contents: string, source: RootSource, filePath: stri const entity = catalogEntityFromCluster(cluster); - if (!filePath.startsWith(ClusterStore.storedKubeConfigFolder)) { + if (!filePath.startsWith(storedKubeConfigFolder())) { entity.metadata.labels.file = filePath.replace(homedir(), "~"); } source.set(contextName, [cluster, entity]); diff --git a/src/migrations/cluster-store/3.6.0-beta.1.ts b/src/migrations/cluster-store/3.6.0-beta.1.ts index 80d2c8f225..7ef4b042ec 100644 --- a/src/migrations/cluster-store/3.6.0-beta.1.ts +++ b/src/migrations/cluster-store/3.6.0-beta.1.ts @@ -25,10 +25,10 @@ import path from "path"; import { app } from "electron"; import fse from "fs-extra"; -import { ClusterStore } from "../../common/cluster-store"; import { loadConfigFromFileSync } from "../../common/kube-helpers"; import { MigrationDeclaration, migrationLog } from "../helpers"; import type { ClusterModel } from "../../common/cluster-types"; +import { getCustomKubeConfigPath, storedKubeConfigFolder } from "../../common/utils"; interface Pre360ClusterModel extends ClusterModel { kubeConfig: string; @@ -41,7 +41,7 @@ export default { const storedClusters: Pre360ClusterModel[] = store.get("clusters") ?? []; const migratedClusters: ClusterModel[] = []; - fse.ensureDirSync(ClusterStore.storedKubeConfigFolder); + fse.ensureDirSync(storedKubeConfigFolder()); migrationLog("Number of clusters to migrate: ", storedClusters.length); @@ -50,7 +50,7 @@ export default { * migrate kubeconfig */ try { - const absPath = ClusterStore.getCustomKubeConfigPath(clusterModel.id); + const absPath = getCustomKubeConfigPath(clusterModel.id); // take the embedded kubeconfig and dump it into a file fse.writeFileSync(absPath, clusterModel.kubeConfig, { encoding: "utf-8", mode: 0o600 }); diff --git a/src/migrations/user-store/5.0.3-beta.1.ts b/src/migrations/user-store/5.0.3-beta.1.ts index ef3448116d..728cf6a395 100644 --- a/src/migrations/user-store/5.0.3-beta.1.ts +++ b/src/migrations/user-store/5.0.3-beta.1.ts @@ -23,10 +23,10 @@ import { app } from "electron"; import { existsSync, readFileSync } from "fs"; import path from "path"; import os from "os"; -import { ClusterStore, ClusterStoreModel } from "../../common/cluster-store"; +import type { ClusterStoreModel } from "../../common/cluster-store"; import type { KubeconfigSyncEntry, UserPreferencesModel } from "../../common/user-store"; import { MigrationDeclaration, migrationLog } from "../helpers"; -import { isLogicalChildPath } from "../../common/utils"; +import { isLogicalChildPath, storedKubeConfigFolder } from "../../common/utils"; export default { version: "5.0.3-beta.1", @@ -42,8 +42,8 @@ export default { for (const cluster of clusters) { const dirOfKubeconfig = path.dirname(cluster.kubeConfigPath); - if (dirOfKubeconfig === ClusterStore.storedKubeConfigFolder) { - migrationLog(`Skipping ${cluster.id} because kubeConfigPath is under ClusterStore.storedKubeConfigFolder`); + if (dirOfKubeconfig === storedKubeConfigFolder()) { + migrationLog(`Skipping ${cluster.id} because kubeConfigPath is under the stored KubeConfig folder`); continue; }