diff --git a/src/main/cluster.ts b/src/main/cluster.ts index 67fa3caf17..8093fd15f7 100644 --- a/src/main/cluster.ts +++ b/src/main/cluster.ts @@ -19,6 +19,7 @@ enum ClusterStatus { export interface ClusterBaseInfo { id: string; + kubeConfig?: string; kubeConfigPath: string; contextName: string; preferences?: ClusterPreferences; 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 d4c867ffbd..e31d7f9af8 100644 --- a/src/migrations/cluster-store/3.6.0-beta.1.ts +++ b/src/migrations/cluster-store/3.6.0-beta.1.ts @@ -1,39 +1,43 @@ -// move embedded kubeconfig into separate file and add reference to it to cluster settings +// Move embedded kubeconfig into separate file and add reference to it to cluster settings + +import path from "path" import { app } from "electron" -import { ensureDirSync } from "fs-extra" -import * as path from "path" +import { migration } from "../migration-wrapper"; +import { ensureDirSync } from "fs-extra" import { KubeConfig } from "@kubernetes/client-node"; import { writeEmbeddedKubeConfig } from "../../common/utils/kubeconfig" +import { ClusterBaseInfo } from "../../main/cluster"; -export function migration(store: any) { - console.log("CLUSTER STORE, MIGRATION: 3.6.0-beta.1"); - const clusters: any[] = [] +export default migration({ + version: "3.6.0-beta.1", + run(store, log: (...args: any[]) => void) { + const migratingClusters: ClusterBaseInfo[] = [] - const kubeConfigBase = path.join(app.getPath("userData"), "kubeconfigs") - ensureDirSync(kubeConfigBase) - const storedClusters = store.get("clusters") as any[] - if (!storedClusters) return + const kubeConfigBase = path.join(app.getPath("userData"), "kubeconfigs") + ensureDirSync(kubeConfigBase) + const storedClusters: ClusterBaseInfo[] = store.get("clusters") + if (!storedClusters) return - console.log("num clusters to migrate: ", storedClusters.length) - for (const cluster of storedClusters ) { - try { - // take the embedded kubeconfig and dump it into a file - const kubeConfigFile = writeEmbeddedKubeConfig(cluster.id, cluster.kubeConfig) - cluster.kubeConfigPath = kubeConfigFile + log("Number of clusters to migrate: ", storedClusters.length) + for (const cluster of storedClusters) { + try { + // take the embedded kubeconfig and dump it into a file + cluster.kubeConfigPath = writeEmbeddedKubeConfig(cluster.id, cluster.kubeConfig) - const kc = new KubeConfig() - kc.loadFromFile(cluster.kubeConfigPath) - cluster.contextName = kc.getCurrentContext() + const kc = new KubeConfig() + kc.loadFromFile(cluster.kubeConfigPath) + cluster.contextName = kc.getCurrentContext() - delete cluster.kubeConfig - clusters.push(cluster) - } catch(error) { - console.error("failed to migrate kubeconfig for cluster:", cluster.id) + delete cluster.kubeConfig + migratingClusters.push(cluster) + } catch (error) { + log(`Failed to migrate Kubeconfig for cluster "${cluster.id}"`, error) + } + } + + // "overwrite" the cluster configs + if (migratingClusters.length > 0) { + store.set("clusters", migratingClusters) } } - - // "overwrite" the cluster configs - if (clusters.length > 0) { - store.set("clusters", clusters) - } -} +}) diff --git a/src/migrations/cluster-store/index.ts b/src/migrations/cluster-store/index.ts index b531d606c4..d178d7106b 100644 --- a/src/migrations/cluster-store/index.ts +++ b/src/migrations/cluster-store/index.ts @@ -6,6 +6,7 @@ import version260Beta2 from "./2.6.0-beta.2" import version260Beta3 from "./2.6.0-beta.3" import version270Beta0 from "./2.7.0-beta.0" import version270Beta1 from "./2.7.0-beta.1" +import version360Beta1 from "./3.6.0-beta.1" export default { ...version200Beta2, @@ -14,4 +15,5 @@ export default { ...version260Beta3, ...version270Beta0, ...version270Beta1, + ...version360Beta1, } \ No newline at end of file