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

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 2021-06-29 09:42:32 -04:00 committed by GitHub
parent 10e1e69137
commit 45cafaa420
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 7 deletions

View File

@ -241,8 +241,8 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
cluster = new Cluster(clusterModel);
}
newClusters.set(clusterModel.id, cluster);
} catch {
// ignore
} catch (error) {
logger.warn(`[CLUSTER-STORE]: Failed to update/create a cluster: ${error}`);
}
}

View File

@ -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,

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);
}