diff --git a/src/common/cluster-store.ts b/src/common/cluster-store.ts index 0812358a78..fa5219ceb6 100644 --- a/src/common/cluster-store.ts +++ b/src/common/cluster-store.ts @@ -71,6 +71,11 @@ export interface ClusterModel { */ workspace?: string; + /** + * @deprecated this is used only for hotbar migrations from 4.2.X + */ + workspaces?: string[]; + /** User context in kubeconfig */ contextName: string; diff --git a/src/main/cluster.ts b/src/main/cluster.ts index 6675bd0151..1266a9c00a 100644 --- a/src/main/cluster.ts +++ b/src/main/cluster.ts @@ -120,6 +120,10 @@ export class Cluster implements ClusterModel, ClusterState { * @deprecated */ @observable workspace: string; + /** + * @deprecated + */ + @observable workspaces: string[]; /** * Kubernetes API server URL * @@ -294,6 +298,10 @@ export class Cluster implements ClusterModel, ClusterState { this.workspace = model.workspace; } + if (model.workspaces) { + this.workspaces = model.workspaces; + } + if (model.contextName) { this.contextName = model.contextName; } @@ -589,6 +597,7 @@ export class Cluster implements ClusterModel, ClusterState { contextName: this.contextName, kubeConfigPath: this.kubeConfigPath, workspace: this.workspace, + workspaces: this.workspaces, preferences: this.preferences, metadata: this.metadata, accessibleNamespaces: this.accessibleNamespaces, diff --git a/src/migrations/cluster-store/5.0.0-beta.13.ts b/src/migrations/cluster-store/5.0.0-beta.13.ts index ace040e2fe..25e0cd1543 100644 --- a/src/migrations/cluster-store/5.0.0-beta.13.ts +++ b/src/migrations/cluster-store/5.0.0-beta.13.ts @@ -63,8 +63,16 @@ function mergeLabels(left: Record, right: Record }; } -function mergeSet(left: Iterable, right: Iterable): string[] { - return [...new Set([...left, ...right])]; +function mergeSet(...iterables: Iterable[]): string[] { + const res = new Set(); + + for (const iterable of iterables) { + for (const val of iterable) { + res.add(val); + } + } + + return [...res]; } function mergeClusterModel(prev: ClusterModel, right: Omit): ClusterModel { @@ -77,6 +85,7 @@ function mergeClusterModel(prev: ClusterModel, right: Omit): labels: mergeLabels(prev.labels ?? {}, right.labels ?? {}), accessibleNamespaces: mergeSet(prev.accessibleNamespaces ?? [], right.accessibleNamespaces ?? []), workspace: prev.workspace || right.workspace, + workspaces: mergeSet([prev.workspace, right.workspace], prev.workspaces ?? [], right.workspaces ?? []), }; } @@ -113,6 +122,7 @@ export default { clusters.set(newId, { ...cluster, id: newId, + workspaces: [cluster.workspace].filter(Boolean), }); moveStorageFolder({ folder, newId, oldId }); } diff --git a/src/migrations/hotbar-store/5.0.0-beta.10.ts b/src/migrations/hotbar-store/5.0.0-beta.10.ts index 97efd0ce1d..9a696ba36c 100644 --- a/src/migrations/hotbar-store/5.0.0-beta.10.ts +++ b/src/migrations/hotbar-store/5.0.0-beta.10.ts @@ -71,17 +71,20 @@ export default { for (const cluster of clusters) { 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) { - workspaceHotbar.items.push({ - entity: { - uid: generateNewIdFor(cluster), - name: cluster.preferences.clusterName || cluster.contextName, - } - }); + migrationLog(`Adding cluster ${uid} to ${workspaceHotbar.name}`); + + if (workspaceHotbar?.items.length < defaultHotbarCells) { + workspaceHotbar.items.push({ + entity: { + uid: generateNewIdFor(cluster), + name: cluster.preferences.clusterName || cluster.contextName, + } + }); + } } }