1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Allow to add the same cluster to multiple workspaces (#961)

Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
Lauri Nevala 2020-09-24 14:30:44 +03:00 committed by GitHub
parent b88c0d4fbf
commit fe4a63a955
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 5 deletions

View File

@ -122,8 +122,8 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
return this.clusters.size > 0; return this.clusters.size > 0;
} }
hasContext(name: string) { hasContextInWorkspace(name: string, workspaceId: string) {
return this.clustersList.some(cluster => cluster.contextName === name); return this.clustersList.some(cluster => cluster.contextName === name && cluster.workspace === workspaceId);
} }
getById(id: ClusterId): Cluster { getById(id: ClusterId): Cluster {

View File

@ -146,14 +146,22 @@ describe("config with existing clusters", () => {
id: 'cluster1', id: 'cluster1',
kubeConfig: 'foo', kubeConfig: 'foo',
contextName: 'foo', contextName: 'foo',
preferences: { terminalCWD: '/foo' } preferences: { terminalCWD: '/foo' },
workspace: 'default'
}, },
{ {
id: 'cluster2', id: 'cluster2',
kubeConfig: 'foo2', kubeConfig: 'foo2',
contextName: 'foo2', contextName: 'foo2',
preferences: { terminalCWD: '/foo2' } preferences: { terminalCWD: '/foo2' }
} },
{
id: 'cluster3',
kubeConfig: 'foo',
contextName: 'foo',
preferences: { terminalCWD: '/foo' },
workspace: 'foo'
},
] ]
}) })
} }
@ -183,10 +191,19 @@ describe("config with existing clusters", () => {
it("allows getting all of the clusters", async () => { it("allows getting all of the clusters", async () => {
const storedClusters = clusterStore.clustersList; const storedClusters = clusterStore.clustersList;
expect(storedClusters.length).toBe(3)
expect(storedClusters[0].id).toBe('cluster1') expect(storedClusters[0].id).toBe('cluster1')
expect(storedClusters[0].preferences.terminalCWD).toBe('/foo') expect(storedClusters[0].preferences.terminalCWD).toBe('/foo')
expect(storedClusters[1].id).toBe('cluster2') expect(storedClusters[1].id).toBe('cluster2')
expect(storedClusters[1].preferences.terminalCWD).toBe('/foo2') expect(storedClusters[1].preferences.terminalCWD).toBe('/foo2')
expect(storedClusters[2].id).toBe('cluster3')
})
it("allows to test if store already has context in workspace", async () => {
const existingContext = clusterStore.hasContextInWorkspace('foo', 'default');
expect(existingContext).toBeTruthy
const nonExistingContext = clusterStore.hasContextInWorkspace('foo2', 'foo');
expect(existingContext).toBeFalsy
}) })
}) })

View File

@ -99,7 +99,7 @@ export class AddCluster extends React.Component {
getContexts(config: KubeConfig): Map<string, KubeConfig> { getContexts(config: KubeConfig): Map<string, KubeConfig> {
const contexts = new Map(); const contexts = new Map();
splitConfig(config).forEach(config => { splitConfig(config).forEach(config => {
const isExists = clusterStore.hasContext(config.currentContext); const isExists = clusterStore.hasContextInWorkspace(config.currentContext, workspaceStore.currentWorkspaceId);
if (!isExists) { if (!isExists) {
contexts.set(config.currentContext, config); contexts.set(config.currentContext, config);
} }