add-cluster page -- part 1

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman committed 2020-07-16 20:19:04 +03:00
1 parent 2a818601f9
commit 5b98674d80
16 files changed
+286 -96

No files matched your search

+5 -6
View File
@@ -4,13 +4,12 @@ import path from "path"
import { app, remote } from "electron"
import { migration } from "../migration-wrapper";
import { ensureDirSync } from "fs-extra"
import { writeEmbeddedKubeConfig } from "../../common/utils/kubeconfig"
import { ClusterModel } from "../../common/cluster-store";
import { loadConfig } from "../../main/k8s";
import { loadConfig, saveConfigToAppFiles } from "../../common/kube-helpers";
export default migration({
version: "3.6.0-beta.1",
run(store, log: (...args: any[]) => void) {
run(store, printLog) {
const migratedClusters: ClusterModel[] = []
const storedClusters: ClusterModel[] = store.get("clusters");
const kubeConfigBase = path.join((app || remote.app).getPath("userData"), "kubeconfigs")
@@ -18,16 +17,16 @@ export default migration({
if (!storedClusters) return;
ensureDirSync(kubeConfigBase);
log("Number of clusters to migrate: ", storedClusters.length)
printLog("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)
cluster.kubeConfigPath = saveConfigToAppFiles(cluster.id, cluster.kubeConfig)
cluster.contextName = loadConfig(cluster.kubeConfigPath).getCurrentContext();
delete cluster.kubeConfig;
migratedClusters.push(cluster)
} catch (error) {
log(`Failed to migrate Kubeconfig for cluster "${cluster.id}"`, error)
printLog(`Failed to migrate Kubeconfig for cluster "${cluster.id}"`, error)
}
}