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:
parent
b88c0d4fbf
commit
fe4a63a955
@ -122,8 +122,8 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
||||
return this.clusters.size > 0;
|
||||
}
|
||||
|
||||
hasContext(name: string) {
|
||||
return this.clustersList.some(cluster => cluster.contextName === name);
|
||||
hasContextInWorkspace(name: string, workspaceId: string) {
|
||||
return this.clustersList.some(cluster => cluster.contextName === name && cluster.workspace === workspaceId);
|
||||
}
|
||||
|
||||
getById(id: ClusterId): Cluster {
|
||||
|
||||
@ -146,14 +146,22 @@ describe("config with existing clusters", () => {
|
||||
id: 'cluster1',
|
||||
kubeConfig: 'foo',
|
||||
contextName: 'foo',
|
||||
preferences: { terminalCWD: '/foo' }
|
||||
preferences: { terminalCWD: '/foo' },
|
||||
workspace: 'default'
|
||||
},
|
||||
{
|
||||
id: 'cluster2',
|
||||
kubeConfig: 'foo2',
|
||||
contextName: '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 () => {
|
||||
const storedClusters = clusterStore.clustersList;
|
||||
expect(storedClusters.length).toBe(3)
|
||||
expect(storedClusters[0].id).toBe('cluster1')
|
||||
expect(storedClusters[0].preferences.terminalCWD).toBe('/foo')
|
||||
expect(storedClusters[1].id).toBe('cluster2')
|
||||
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
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -99,7 +99,7 @@ export class AddCluster extends React.Component {
|
||||
getContexts(config: KubeConfig): Map<string, KubeConfig> {
|
||||
const contexts = new Map();
|
||||
splitConfig(config).forEach(config => {
|
||||
const isExists = clusterStore.hasContext(config.currentContext);
|
||||
const isExists = clusterStore.hasContextInWorkspace(config.currentContext, workspaceStore.currentWorkspaceId);
|
||||
if (!isExists) {
|
||||
contexts.set(config.currentContext, config);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user