Fix cluster-store and hotbar-store migrations (#3208)

- kubeConfigPath was erroniously set to cluster.id
- Skip empty workspace hotbars
- Output a warn if updating or creating a cluster throws in
  cluster-store

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-06-29 09:42:32 -04:00
1 parent 10e1e69137
commit 45cafaa420
3 files changed
+18 -7

No files matched your search

@@ -70,12 +70,13 @@ function mergeSet(left: Iterable<string>, right: Iterable<string>): string[] {
function mergeClusterModel(prev: ClusterModel, right: Omit<ClusterModel, "id">): ClusterModel {
return {
id: prev.id,
kubeConfigPath: prev.id,
kubeConfigPath: prev.kubeConfigPath,
contextName: prev.contextName,
preferences: mergePreferences(prev.preferences ?? {}, right.preferences ?? {}),
metadata: prev.metadata,
labels: mergeLabels(prev.labels ?? {}, right.labels ?? {}),
accessibleNamespaces: mergeSet(prev.accessibleNamespaces ?? [], right.accessibleNamespaces ?? []),
workspace: prev.workspace || right.workspace,
};
}
@@ -105,8 +106,10 @@ export default {
const newId = generateNewIdFor(cluster);
if (clusters.has(newId)) {
migrationLog(`Duplicate entries for ${newId}`, { oldId });
clusters.set(newId, mergeClusterModel(clusters.get(newId), cluster));
} else {
migrationLog(`First entry for ${newId}`, { oldId });
clusters.set(newId, {
...cluster,
id: newId,
+12 -4
View File
@@ -21,13 +21,13 @@
import { app } from "electron";
import fse from "fs-extra";
import { isNull, uniqBy } from "lodash";
import { isNull } from "lodash";
import path from "path";
import * as uuid from "uuid";
import type { ClusterStoreModel } from "../../common/cluster-store";
import { defaultHotbarCells, Hotbar, HotbarStore } from "../../common/hotbar-store";
import { catalogEntity } from "../../main/catalog-sources/general";
import type { MigrationDeclaration } from "../helpers";
import { MigrationDeclaration, migrationLog } from "../helpers";
import { generateNewIdFor } from "../utils";
interface Pre500WorkspaceStoreModel {
@@ -47,9 +47,9 @@ export default {
const workspaceStoreData: Pre500WorkspaceStoreModel = fse.readJsonSync(path.join(userDataPath, "lens-workspace-store.json"));
const { clusters }: ClusterStoreModel = fse.readJSONSync(path.join(userDataPath, "lens-cluster-store.json"));
const workspaceHotbars = new Map<string, Hotbar>(); // mapping from WorkspaceId to HotBar
const uniqueClusters = uniqBy(clusters, "metadata.id"); // Filtering out duplicated clusters
for (const { id, name } of workspaceStoreData.workspaces) {
migrationLog(`Creating new hotbar for ${name}`);
workspaceHotbars.set(id, {
id: uuid.v4(), // don't use the old IDs as they aren't necessarily UUIDs
items: [],
@@ -69,9 +69,12 @@ export default {
});
}
for (const cluster of uniqueClusters) {
for (const cluster of clusters) {
const uid = generateNewIdFor(cluster);
const workspaceHotbar = workspaceHotbars.get(cluster.workspace);
migrationLog(`Adding cluster ${uid} to ${workspaceHotbar.name}`);
if (workspaceHotbar?.items.length < defaultHotbarCells) {
workspaceHotbar.items.push({
entity: {
@@ -83,6 +86,11 @@ export default {
}
for (const hotbar of workspaceHotbars.values()) {
if (hotbar.items.length === 0) {
migrationLog(`Skipping ${hotbar.name} due to it being empty`);
continue;
}
while (hotbar.items.length < defaultHotbarCells) {
hotbar.items.push(null);
}