refactoring

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman committed 2020-07-11 11:32:29 +03:00
1 parent 8bb3954700
commit e72e28ddab
22 files changed
+133 -218

No files matched your search

+8 -15
View File
@@ -4,40 +4,33 @@ import path from "path"
import { app, remote } from "electron"
import { migration } from "../migration-wrapper";
import { ensureDirSync } from "fs-extra"
import { KubeConfig } from "@kubernetes/client-node";
import { writeEmbeddedKubeConfig } from "../../common/utils/kubeconfig"
import { ClusterModel } from "../../common/cluster-store";
export default migration({
version: "3.6.0-beta.1",
run(store, log: (...args: any[]) => void) {
const migratingClusters: ClusterModel[] = []
const migratedClusters: ClusterModel[] = []
const storedClusters: ClusterModel[] = store.get("clusters");
const kubeConfigBase = path.join((app || remote.app).getPath("userData"), "kubeconfigs")
ensureDirSync(kubeConfigBase)
const storedClusters: ClusterModel[] = store.get("clusters")
if (!storedClusters) return
if (!storedClusters) return;
ensureDirSync(kubeConfigBase);
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()
delete cluster.kubeConfig
migratingClusters.push(cluster)
migratedClusters.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)
if (migratedClusters.length > 0) {
store.set("clusters", migratedClusters)
}
}
})