Merge remote-tracking branch 'origin/master' into vue_react_migration

# Conflicts:
#	src/common/cluster-store.ts
#	src/common/cluster-store_spec.ts
This commit is contained in:
Roman committed 2020-07-04 12:50:23 +03:00
commit f9c0c5d825
23 files changed
+258 -161

No files matched your search

+5 -3
View File
@@ -16,7 +16,7 @@ export class ClusterStore extends Singleton {
})
}
public getAllClusters(): Array<ClusterBaseInfo> {
public getAllClusters(): ClusterBaseInfo[] {
return this.store.get("clusters", [])
}
@@ -52,7 +52,8 @@ export class ClusterStore extends Singleton {
const index = clusters.findIndex((cl) => cl.id === cluster.id)
const storable = {
id: cluster.id,
kubeConfig: cluster.kubeConfig,
kubeConfigPath: cluster.kubeConfigPath,
contextName: cluster.contextName,
preferences: cluster.preferences,
workspace: cluster.workspace
}
@@ -74,7 +75,8 @@ export class ClusterStore extends Singleton {
public reloadCluster(cluster: ClusterBaseInfo): void {
const storedCluster = this.getCluster(cluster.id);
if (storedCluster) {
cluster.kubeConfig = storedCluster.kubeConfig
cluster.kubeConfigPath = storedCluster.kubeConfigPath
cluster.contextName = storedCluster.contextName
cluster.preferences = storedCluster.preferences
cluster.workspace = storedCluster.workspace
}
+18 -13
View File
@@ -27,7 +27,8 @@ describe("for an empty config", () => {
it("allows to store and retrieve a cluster", async () => {
const cluster = new Cluster({
id: 'foo',
kubeConfig: 'kubeconfig string',
kubeConfigPath: 'kubeconfig',
contextName: "foo",
preferences: {
terminalCWD: '/tmp',
icon: 'path to icon'
@@ -35,7 +36,8 @@ describe("for an empty config", () => {
})
clusterStore.saveCluster(cluster);
const storedCluster = clusterStore.getCluster(cluster.id);
expect(storedCluster.kubeConfig).toBe(cluster.kubeConfig)
expect(storedCluster.kubeConfigPath).toBe(cluster.kubeConfigPath)
expect(storedCluster.contextName).toBe(cluster.contextName)
expect(storedCluster.preferences.icon).toBe(cluster.preferences.icon)
expect(storedCluster.preferences.terminalCWD).toBe(cluster.preferences.terminalCWD)
expect(storedCluster.id).toBe(cluster.id)
@@ -44,7 +46,8 @@ describe("for an empty config", () => {
it("allows to delete a cluster", async () => {
const cluster = new Cluster({
id: 'foofoo',
kubeConfig: 'kubeconfig string',
kubeConfigPath: 'kubeconfig',
contextName: "foo",
preferences: {
terminalCWD: '/tmp'
}
@@ -73,12 +76,12 @@ describe("for a config with existing clusters", () => {
clusters: [
{
id: 'cluster1',
kubeConfig: 'foo',
kubeConfigPath: 'foo',
preferences: { terminalCWD: '/foo' }
},
{
id: 'cluster2',
kubeConfig: 'foo2',
kubeConfigPath: 'foo2',
preferences: { terminalCWD: '/foo2' }
}
]
@@ -90,12 +93,12 @@ describe("for a config with existing clusters", () => {
it("allows to retrieve a cluster", async () => {
const storedCluster = clusterStore.getCluster('cluster1')
expect(storedCluster.kubeConfig).toBe('foo')
expect(storedCluster.kubeConfigPath).toBe('foo')
expect(storedCluster.preferences.terminalCWD).toBe('/foo')
expect(storedCluster.id).toBe('cluster1')
const storedCluster2 = clusterStore.getCluster('cluster2')
expect(storedCluster2.kubeConfig).toBe('foo2')
expect(storedCluster2.kubeConfigPath).toBe('foo2')
expect(storedCluster2.preferences.terminalCWD).toBe('/foo2')
expect(storedCluster2.id).toBe('cluster2')
})
@@ -114,7 +117,8 @@ describe("for a config with existing clusters", () => {
it("allows to reload a cluster in-place", async () => {
const cluster = new Cluster({
id: 'cluster1',
kubeConfig: 'kubeconfig string',
kubeConfigPath: 'kubeconfig string',
contextName: "foo",
preferences: {
terminalCWD: '/tmp'
}
@@ -122,7 +126,7 @@ describe("for a config with existing clusters", () => {
clusterStore.reloadCluster(cluster)
expect(cluster.kubeConfig).toBe('foo')
expect(cluster.kubeConfigPath).toBe('foo')
expect(cluster.preferences.terminalCWD).toBe('/foo')
expect(cluster.id).toBe('cluster1')
})
@@ -132,11 +136,11 @@ describe("for a config with existing clusters", () => {
expect(storedClusters[0].id).toBe('cluster1')
expect(storedClusters[0].preferences.terminalCWD).toBe('/foo')
expect(storedClusters[0].kubeConfig).toBe('foo')
expect(storedClusters[0].kubeConfigPath).toBe('foo')
expect(storedClusters[1].id).toBe('cluster2')
expect(storedClusters[1].preferences.terminalCWD).toBe('/foo2')
expect(storedClusters[1].kubeConfig).toBe('foo2')
expect(storedClusters[1].kubeConfigPath).toBe('foo2')
})
it("allows storing the clusters in a different order", async () => {
@@ -170,7 +174,7 @@ describe("for a config with existing clusters", () => {
//
// it("migrates to modern format with kubeconfig under a key", async () => {
// const storedCluster = clusterStore.store.get('clusters')[0]
// expect(storedCluster.kubeConfig).toBe('kubeconfig content')
// expect(storedCluster.kubeConfigPath).toBe(`tmp/kubeconfigs/${storedCluster.id}`)
// })
// })
@@ -225,9 +229,10 @@ describe("for a config with existing clusters", () => {
//
// it("replaces array format access token and expiry into string", async () => {
// const storedClusterData = clusterStore.store.get('clusters')[0]
// const kc = yaml.safeLoad(storedClusterData.kubeConfig)
// const kc = yaml.safeLoad(fs.readFileSync(storedClusterData.kubeConfigPath).toString())
// expect(kc.users[0].user['auth-provider'].config['access-token']).toBe("should be string")
// expect(kc.users[0].user['auth-provider'].config['expiry']).toBe("should be string")
// expect(storedClusterData.contextName).toBe("minikube")
// })
// })
+16
View 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
}