mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Kubeconfigs as file references (#466)
Signed-off-by: Jussi Nummelin <jussi.nummelin@gmail.com> Co-authored-by: Lauri Nevala <lauri.nevala@gmail.com> Co-authored-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
23 files changed
+272
-162
No files matched your search
@@ -0,0 +1,39 @@
|
||||
// move embedded kubeconfig into separate file and add reference to it to cluster settings
|
||||
import { app } from "electron"
|
||||
import { ensureDirSync } from "fs-extra"
|
||||
import * as path from "path"
|
||||
import { KubeConfig } from "@kubernetes/client-node";
|
||||
import { writeEmbeddedKubeConfig } from "../../common/utils/kubeconfig"
|
||||
|
||||
export function migration(store: any) {
|
||||
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[]
|
||||
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
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
// "overwrite" the cluster configs
|
||||
if (clusters.length > 0) {
|
||||
store.set("clusters", clusters)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user