mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Correctly migrate duplicate clusters in workspaces (#3211)
- Keep track of the set of all workspaces that each duplicated entry was a part of Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
b00afee15c
commit
05311c4b1b
@ -71,6 +71,11 @@ export interface ClusterModel {
|
|||||||
*/
|
*/
|
||||||
workspace?: string;
|
workspace?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated this is used only for hotbar migrations from 4.2.X
|
||||||
|
*/
|
||||||
|
workspaces?: string[];
|
||||||
|
|
||||||
/** User context in kubeconfig */
|
/** User context in kubeconfig */
|
||||||
contextName: string;
|
contextName: string;
|
||||||
|
|
||||||
|
|||||||
@ -120,6 +120,10 @@ export class Cluster implements ClusterModel, ClusterState {
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
@observable workspace: string;
|
@observable workspace: string;
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
@observable workspaces: string[];
|
||||||
/**
|
/**
|
||||||
* Kubernetes API server URL
|
* Kubernetes API server URL
|
||||||
*
|
*
|
||||||
@ -294,6 +298,10 @@ export class Cluster implements ClusterModel, ClusterState {
|
|||||||
this.workspace = model.workspace;
|
this.workspace = model.workspace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (model.workspaces) {
|
||||||
|
this.workspaces = model.workspaces;
|
||||||
|
}
|
||||||
|
|
||||||
if (model.contextName) {
|
if (model.contextName) {
|
||||||
this.contextName = model.contextName;
|
this.contextName = model.contextName;
|
||||||
}
|
}
|
||||||
@ -589,6 +597,7 @@ export class Cluster implements ClusterModel, ClusterState {
|
|||||||
contextName: this.contextName,
|
contextName: this.contextName,
|
||||||
kubeConfigPath: this.kubeConfigPath,
|
kubeConfigPath: this.kubeConfigPath,
|
||||||
workspace: this.workspace,
|
workspace: this.workspace,
|
||||||
|
workspaces: this.workspaces,
|
||||||
preferences: this.preferences,
|
preferences: this.preferences,
|
||||||
metadata: this.metadata,
|
metadata: this.metadata,
|
||||||
accessibleNamespaces: this.accessibleNamespaces,
|
accessibleNamespaces: this.accessibleNamespaces,
|
||||||
|
|||||||
@ -63,8 +63,16 @@ function mergeLabels(left: Record<string, string>, right: Record<string, string>
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function mergeSet(left: Iterable<string>, right: Iterable<string>): string[] {
|
function mergeSet(...iterables: Iterable<string>[]): string[] {
|
||||||
return [...new Set([...left, ...right])];
|
const res = new Set<string>();
|
||||||
|
|
||||||
|
for (const iterable of iterables) {
|
||||||
|
for (const val of iterable) {
|
||||||
|
res.add(val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [...res];
|
||||||
}
|
}
|
||||||
|
|
||||||
function mergeClusterModel(prev: ClusterModel, right: Omit<ClusterModel, "id">): ClusterModel {
|
function mergeClusterModel(prev: ClusterModel, right: Omit<ClusterModel, "id">): ClusterModel {
|
||||||
@ -77,6 +85,7 @@ function mergeClusterModel(prev: ClusterModel, right: Omit<ClusterModel, "id">):
|
|||||||
labels: mergeLabels(prev.labels ?? {}, right.labels ?? {}),
|
labels: mergeLabels(prev.labels ?? {}, right.labels ?? {}),
|
||||||
accessibleNamespaces: mergeSet(prev.accessibleNamespaces ?? [], right.accessibleNamespaces ?? []),
|
accessibleNamespaces: mergeSet(prev.accessibleNamespaces ?? [], right.accessibleNamespaces ?? []),
|
||||||
workspace: prev.workspace || right.workspace,
|
workspace: prev.workspace || right.workspace,
|
||||||
|
workspaces: mergeSet([prev.workspace, right.workspace], prev.workspaces ?? [], right.workspaces ?? []),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,6 +122,7 @@ export default {
|
|||||||
clusters.set(newId, {
|
clusters.set(newId, {
|
||||||
...cluster,
|
...cluster,
|
||||||
id: newId,
|
id: newId,
|
||||||
|
workspaces: [cluster.workspace].filter(Boolean),
|
||||||
});
|
});
|
||||||
moveStorageFolder({ folder, newId, oldId });
|
moveStorageFolder({ folder, newId, oldId });
|
||||||
}
|
}
|
||||||
|
|||||||
@ -71,17 +71,20 @@ export default {
|
|||||||
|
|
||||||
for (const cluster of clusters) {
|
for (const cluster of clusters) {
|
||||||
const uid = generateNewIdFor(cluster);
|
const uid = generateNewIdFor(cluster);
|
||||||
const workspaceHotbar = workspaceHotbars.get(cluster.workspace);
|
|
||||||
|
|
||||||
migrationLog(`Adding cluster ${uid} to ${workspaceHotbar.name}`);
|
for (const workspaceId of cluster.workspaces ?? [cluster.workspace].filter(Boolean)) {
|
||||||
|
const workspaceHotbar = workspaceHotbars.get(workspaceId);
|
||||||
|
|
||||||
if (workspaceHotbar?.items.length < defaultHotbarCells) {
|
migrationLog(`Adding cluster ${uid} to ${workspaceHotbar.name}`);
|
||||||
workspaceHotbar.items.push({
|
|
||||||
entity: {
|
if (workspaceHotbar?.items.length < defaultHotbarCells) {
|
||||||
uid: generateNewIdFor(cluster),
|
workspaceHotbar.items.push({
|
||||||
name: cluster.preferences.clusterName || cluster.contextName,
|
entity: {
|
||||||
}
|
uid: generateNewIdFor(cluster),
|
||||||
});
|
name: cluster.preferences.clusterName || cluster.contextName,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user