mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Rename migration to 3.6.0-beta.1 and move writeEmbeddedKubeConfig to app-utils
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
parent
8a6451d912
commit
985bb29b96
@ -1,7 +1,4 @@
|
|||||||
import { app, remote } from "electron"
|
|
||||||
import ElectronStore from "electron-store"
|
import ElectronStore from "electron-store"
|
||||||
import { ensureDirSync, writeFileSync } from "fs-extra"
|
|
||||||
import * as path from "path"
|
|
||||||
import { Cluster, ClusterBaseInfo } from "../main/cluster";
|
import { Cluster, ClusterBaseInfo } from "../main/cluster";
|
||||||
import * as version200Beta2 from "../migrations/cluster-store/2.0.0-beta.2"
|
import * as version200Beta2 from "../migrations/cluster-store/2.0.0-beta.2"
|
||||||
import * as version241 from "../migrations/cluster-store/2.4.1"
|
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 version260Beta3 from "../migrations/cluster-store/2.6.0-beta.3"
|
||||||
import * as version270Beta0 from "../migrations/cluster-store/2.7.0-beta.0"
|
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 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";
|
import { getAppVersion } from "./utils/app-version";
|
||||||
|
|
||||||
export class ClusterStore {
|
export class ClusterStore {
|
||||||
@ -30,7 +27,7 @@ export class ClusterStore {
|
|||||||
"2.6.0-beta.3": version260Beta3.migration,
|
"2.6.0-beta.3": version260Beta3.migration,
|
||||||
"2.7.0-beta.0": version270Beta0.migration,
|
"2.7.0-beta.0": version270Beta0.migration,
|
||||||
"2.7.0-beta.1": version270Beta1.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();
|
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
|
|
||||||
}
|
|
||||||
|
|||||||
16
src/common/utils/kubeconfig.ts
Normal file
16
src/common/utils/kubeconfig.ts
Normal file
@ -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
|
||||||
|
}
|
||||||
@ -3,10 +3,8 @@ import logger from "./logger"
|
|||||||
import * as tcpPortUsed from "tcp-port-used"
|
import * as tcpPortUsed from "tcp-port-used"
|
||||||
import { Kubectl, bundledKubectl } from "./kubectl"
|
import { Kubectl, bundledKubectl } from "./kubectl"
|
||||||
import { Cluster } from "./cluster"
|
import { Cluster } from "./cluster"
|
||||||
import { readFileSync, watch } from "fs"
|
|
||||||
import { PromiseIpc } from "electron-promise-ipc"
|
import { PromiseIpc } from "electron-promise-ipc"
|
||||||
import { findMainWebContents } from "./webcontents"
|
import { findMainWebContents } from "./webcontents"
|
||||||
import * as url from "url"
|
|
||||||
|
|
||||||
export class KubeAuthProxy {
|
export class KubeAuthProxy {
|
||||||
public lastError: string
|
public lastError: string
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
// 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 { app } from "electron"
|
import { app } from "electron"
|
||||||
import { ensureDirSync, writeFileSync } from "fs-extra"
|
import { ensureDirSync } from "fs-extra"
|
||||||
import * as path from "path"
|
import * as path from "path"
|
||||||
import { KubeConfig } from "@kubernetes/client-node";
|
import { KubeConfig } from "@kubernetes/client-node";
|
||||||
import * as clusterStore from "../../cluster-store"
|
import { writeEmbeddedKubeConfig } from "../../common/utils/kubeconfig"
|
||||||
|
|
||||||
export function migration(store: any) {
|
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 clusters: any[] = []
|
||||||
|
|
||||||
const kubeConfigBase = path.join(app.getPath("userData"), "kubeconfigs")
|
const kubeConfigBase = path.join(app.getPath("userData"), "kubeconfigs")
|
||||||
ensureDirSync(kubeConfigBase)
|
ensureDirSync(kubeConfigBase)
|
||||||
const storedClusters = store.get("clusters") as any[]
|
const storedClusters = store.get("clusters") as any[]
|
||||||
@ -18,13 +18,13 @@ export function migration(store: any) {
|
|||||||
for (const cluster of storedClusters ) {
|
for (const cluster of storedClusters ) {
|
||||||
// TODO Should probably guard this, not to make the whole migration fail if one cluster fails!?
|
// 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
|
// 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
|
cluster.kubeConfigPath = kubeConfigFile
|
||||||
|
|
||||||
const kc = new KubeConfig()
|
const kc = new KubeConfig()
|
||||||
kc.loadFromFile(cluster.kubeConfigPath)
|
kc.loadFromFile(cluster.kubeConfigPath)
|
||||||
cluster.contextName = kc.getCurrentContext()
|
cluster.contextName = kc.getCurrentContext()
|
||||||
|
|
||||||
delete cluster.kubeConfig
|
delete cluster.kubeConfig
|
||||||
clusters.push(cluster)
|
clusters.push(cluster)
|
||||||
}
|
}
|
||||||
@ -129,6 +129,7 @@ import * as path from "path"
|
|||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import * as clusterStore from "../../common/cluster-store"
|
import * as clusterStore from "../../common/cluster-store"
|
||||||
|
import { writeEmbeddedKubeConfig} from "../../common/app-utils"
|
||||||
|
|
||||||
class ClusterAccessError extends Error {}
|
class ClusterAccessError extends Error {}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user