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:
parent
10e1e69137
commit
45cafaa420
@ -241,8 +241,8 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
cluster = new Cluster(clusterModel);
|
cluster = new Cluster(clusterModel);
|
||||||
}
|
}
|
||||||
newClusters.set(clusterModel.id, cluster);
|
newClusters.set(clusterModel.id, cluster);
|
||||||
} catch {
|
} catch (error) {
|
||||||
// ignore
|
logger.warn(`[CLUSTER-STORE]: Failed to update/create a cluster: ${error}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -70,12 +70,13 @@ function mergeSet(left: Iterable<string>, right: Iterable<string>): string[] {
|
|||||||
function mergeClusterModel(prev: ClusterModel, right: Omit<ClusterModel, "id">): ClusterModel {
|
function mergeClusterModel(prev: ClusterModel, right: Omit<ClusterModel, "id">): ClusterModel {
|
||||||
return {
|
return {
|
||||||
id: prev.id,
|
id: prev.id,
|
||||||
kubeConfigPath: prev.id,
|
kubeConfigPath: prev.kubeConfigPath,
|
||||||
contextName: prev.contextName,
|
contextName: prev.contextName,
|
||||||
preferences: mergePreferences(prev.preferences ?? {}, right.preferences ?? {}),
|
preferences: mergePreferences(prev.preferences ?? {}, right.preferences ?? {}),
|
||||||
metadata: prev.metadata,
|
metadata: prev.metadata,
|
||||||
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,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,8 +106,10 @@ export default {
|
|||||||
const newId = generateNewIdFor(cluster);
|
const newId = generateNewIdFor(cluster);
|
||||||
|
|
||||||
if (clusters.has(newId)) {
|
if (clusters.has(newId)) {
|
||||||
|
migrationLog(`Duplicate entries for ${newId}`, { oldId });
|
||||||
clusters.set(newId, mergeClusterModel(clusters.get(newId), cluster));
|
clusters.set(newId, mergeClusterModel(clusters.get(newId), cluster));
|
||||||
} else {
|
} else {
|
||||||
|
migrationLog(`First entry for ${newId}`, { oldId });
|
||||||
clusters.set(newId, {
|
clusters.set(newId, {
|
||||||
...cluster,
|
...cluster,
|
||||||
id: newId,
|
id: newId,
|
||||||
|
|||||||
@ -21,13 +21,13 @@
|
|||||||
|
|
||||||
import { app } from "electron";
|
import { app } from "electron";
|
||||||
import fse from "fs-extra";
|
import fse from "fs-extra";
|
||||||
import { isNull, uniqBy } from "lodash";
|
import { isNull } from "lodash";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import * as uuid from "uuid";
|
import * as uuid from "uuid";
|
||||||
import type { ClusterStoreModel } from "../../common/cluster-store";
|
import type { ClusterStoreModel } from "../../common/cluster-store";
|
||||||
import { defaultHotbarCells, Hotbar, HotbarStore } from "../../common/hotbar-store";
|
import { defaultHotbarCells, Hotbar, HotbarStore } from "../../common/hotbar-store";
|
||||||
import { catalogEntity } from "../../main/catalog-sources/general";
|
import { catalogEntity } from "../../main/catalog-sources/general";
|
||||||
import type { MigrationDeclaration } from "../helpers";
|
import { MigrationDeclaration, migrationLog } from "../helpers";
|
||||||
import { generateNewIdFor } from "../utils";
|
import { generateNewIdFor } from "../utils";
|
||||||
|
|
||||||
interface Pre500WorkspaceStoreModel {
|
interface Pre500WorkspaceStoreModel {
|
||||||
@ -47,9 +47,9 @@ export default {
|
|||||||
const workspaceStoreData: Pre500WorkspaceStoreModel = fse.readJsonSync(path.join(userDataPath, "lens-workspace-store.json"));
|
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 { clusters }: ClusterStoreModel = fse.readJSONSync(path.join(userDataPath, "lens-cluster-store.json"));
|
||||||
const workspaceHotbars = new Map<string, Hotbar>(); // mapping from WorkspaceId to HotBar
|
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) {
|
for (const { id, name } of workspaceStoreData.workspaces) {
|
||||||
|
migrationLog(`Creating new hotbar for ${name}`);
|
||||||
workspaceHotbars.set(id, {
|
workspaceHotbars.set(id, {
|
||||||
id: uuid.v4(), // don't use the old IDs as they aren't necessarily UUIDs
|
id: uuid.v4(), // don't use the old IDs as they aren't necessarily UUIDs
|
||||||
items: [],
|
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);
|
const workspaceHotbar = workspaceHotbars.get(cluster.workspace);
|
||||||
|
|
||||||
|
migrationLog(`Adding cluster ${uid} to ${workspaceHotbar.name}`);
|
||||||
|
|
||||||
if (workspaceHotbar?.items.length < defaultHotbarCells) {
|
if (workspaceHotbar?.items.length < defaultHotbarCells) {
|
||||||
workspaceHotbar.items.push({
|
workspaceHotbar.items.push({
|
||||||
entity: {
|
entity: {
|
||||||
@ -83,6 +86,11 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const hotbar of workspaceHotbars.values()) {
|
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) {
|
while (hotbar.items.length < defaultHotbarCells) {
|
||||||
hotbar.items.push(null);
|
hotbar.items.push(null);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user