diff --git a/src/common/cluster-store.ts b/src/common/cluster-store.ts index 7b97c9e31c..f7f323fad2 100644 --- a/src/common/cluster-store.ts +++ b/src/common/cluster-store.ts @@ -1,7 +1,4 @@ -import { app, remote } from "electron" import ElectronStore from "electron-store" -import { ensureDirSync, writeFileSync } from "fs-extra" -import * as path from "path" import { Cluster, ClusterBaseInfo } from "../main/cluster"; import * as version200Beta2 from "../migrations/cluster-store/2.0.0-beta.2" import * as version241 from "../migrations/cluster-store/2.4.1" @@ -9,7 +6,7 @@ import * as version260Beta2 from "../migrations/cluster-store/2.6.0-beta.2" import * as version260Beta3 from "../migrations/cluster-store/2.6.0-beta.3" import * as version270Beta0 from "../migrations/cluster-store/2.7.0-beta.0" import * as version270Beta1 from "../migrations/cluster-store/2.7.0-beta.1" -import * as version350Beta1 from "../migrations/cluster-store/3.5.0-beta.1" +import * as version360Beta1 from "../migrations/cluster-store/3.6.0-beta.1" import { getAppVersion } from "./utils/app-version"; export class ClusterStore { @@ -30,7 +27,7 @@ export class ClusterStore { "2.6.0-beta.3": version260Beta3.migration, "2.7.0-beta.0": version270Beta0.migration, "2.7.0-beta.1": version270Beta1.migration, - "3.5.0-beta.1": version350Beta1.migration + "3.6.0-beta.1": version360Beta1.migration } }) } @@ -121,16 +118,3 @@ export class ClusterStore { } export const clusterStore: ClusterStore = ClusterStore.getInstance(); - -// Writes kubeconfigs to "embedded" store, i.e. .../Lens/kubeconfigs/ -export function writeEmbeddedKubeConfig(clusterId: string, kubeConfig: string): string { - // This can be called from main & renderer - const a = (app || remote.app) - const kubeConfigBase = path.join(a.getPath("userData"), "kubeconfigs") - ensureDirSync(kubeConfigBase) - - const kubeConfigFile = path.join(kubeConfigBase, clusterId) - writeFileSync(kubeConfigFile, kubeConfig) - - return kubeConfigFile -} diff --git a/src/common/utils/kubeconfig.ts b/src/common/utils/kubeconfig.ts new file mode 100644 index 0000000000..1f6cf4a874 --- /dev/null +++ b/src/common/utils/kubeconfig.ts @@ -0,0 +1,16 @@ +import { app, remote } from "electron" +import { ensureDirSync, writeFileSync } from "fs-extra" +import * as path from "path" + +// Writes kubeconfigs to "embedded" store, i.e. .../Lens/kubeconfigs/ +export function writeEmbeddedKubeConfig(clusterId: string, kubeConfig: string): string { + // This can be called from main & renderer + const a = (app || remote.app) + const kubeConfigBase = path.join(a.getPath("userData"), "kubeconfigs") + ensureDirSync(kubeConfigBase) + + const kubeConfigFile = path.join(kubeConfigBase, clusterId) + writeFileSync(kubeConfigFile, kubeConfig) + + return kubeConfigFile +} diff --git a/src/main/kube-auth-proxy.ts b/src/main/kube-auth-proxy.ts index 109a5f85b1..02d4e0bb7b 100644 --- a/src/main/kube-auth-proxy.ts +++ b/src/main/kube-auth-proxy.ts @@ -3,10 +3,8 @@ import logger from "./logger" import * as tcpPortUsed from "tcp-port-used" import { Kubectl, bundledKubectl } from "./kubectl" import { Cluster } from "./cluster" -import { readFileSync, watch } from "fs" import { PromiseIpc } from "electron-promise-ipc" import { findMainWebContents } from "./webcontents" -import * as url from "url" export class KubeAuthProxy { public lastError: string diff --git a/src/migrations/cluster-store/3.5.0-beta.1.ts b/src/migrations/cluster-store/3.6.0-beta.1.ts similarity index 79% rename from src/migrations/cluster-store/3.5.0-beta.1.ts rename to src/migrations/cluster-store/3.6.0-beta.1.ts index 8f2c0dbb8a..a0fcc81de5 100644 --- a/src/migrations/cluster-store/3.5.0-beta.1.ts +++ b/src/migrations/cluster-store/3.6.0-beta.1.ts @@ -1,14 +1,14 @@ // move embedded kubeconfig into separate file and add reference to it to cluster settings import { app } from "electron" -import { ensureDirSync, writeFileSync } from "fs-extra" +import { ensureDirSync } from "fs-extra" import * as path from "path" import { KubeConfig } from "@kubernetes/client-node"; -import * as clusterStore from "../../cluster-store" +import { writeEmbeddedKubeConfig } from "../../common/utils/kubeconfig" export function migration(store: any) { - console.log("CLUSTER STORE, MIGRATION: 3.5.0-beta.1"); + console.log("CLUSTER STORE, MIGRATION: 3.6.0-beta.1"); const clusters: any[] = [] - + const kubeConfigBase = path.join(app.getPath("userData"), "kubeconfigs") ensureDirSync(kubeConfigBase) const storedClusters = store.get("clusters") as any[] @@ -18,13 +18,13 @@ export function migration(store: any) { for (const cluster of storedClusters ) { // TODO Should probably guard this, not to make the whole migration fail if one cluster fails!? // take the embedded kubeconfig and dump it into a file - const kubeConfigFile = clusterStore.writeEmbeddedKubeConfig(cluster.id, cluster.kubeConfig) + const kubeConfigFile = writeEmbeddedKubeConfig(cluster.id, cluster.kubeConfig) cluster.kubeConfigPath = kubeConfigFile - + const kc = new KubeConfig() kc.loadFromFile(cluster.kubeConfigPath) cluster.contextName = kc.getCurrentContext() - + delete cluster.kubeConfig clusters.push(cluster) } diff --git a/src/renderer/_vue/components/AddClusterPage.vue b/src/renderer/_vue/components/AddClusterPage.vue index c371d3df30..fb662e9695 100644 --- a/src/renderer/_vue/components/AddClusterPage.vue +++ b/src/renderer/_vue/components/AddClusterPage.vue @@ -129,6 +129,7 @@ import * as path from "path" import fs from 'fs' import { v4 as uuidv4 } from 'uuid'; import * as clusterStore from "../../common/cluster-store" +import { writeEmbeddedKubeConfig} from "../../common/app-utils" class ClusterAccessError extends Error {}