mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Make CatalogEntity labels clickable (#3075)
- Transition workspace's to be labels - Fix migrations to support multiple migrations for the same version Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
d812e28639
commit
7f51e3addd
30 files changed
+268
-120
No files matched your search
@@ -19,12 +19,14 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/* Early store format had the kubeconfig directly under context name, this moves
|
||||
it under the kubeConfig key */
|
||||
import type { MigrationDeclaration } from "../helpers";
|
||||
|
||||
import { migration } from "../migration-wrapper";
|
||||
/**
|
||||
* Early store format had the kubeconfig directly under context name, this moves
|
||||
* it under the kubeConfig key
|
||||
*/
|
||||
|
||||
export default migration({
|
||||
export default {
|
||||
version: "2.0.0-beta.2",
|
||||
run(store) {
|
||||
for (const value of store) {
|
||||
@@ -35,4 +37,4 @@ export default migration({
|
||||
store.set(contextName, { kubeConfig: value[1] });
|
||||
}
|
||||
}
|
||||
});
|
||||
} as MigrationDeclaration;
|
||||
@@ -19,10 +19,11 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// Cleans up a store that had the state related data stored
|
||||
import { migration } from "../migration-wrapper";
|
||||
import type { MigrationDeclaration } from "../helpers";
|
||||
|
||||
export default migration({
|
||||
// Cleans up a store that had the state related data stored
|
||||
|
||||
export default {
|
||||
version: "2.4.1",
|
||||
run(store) {
|
||||
for (const value of store) {
|
||||
@@ -34,4 +35,4 @@ export default migration({
|
||||
store.set(contextName, { kubeConfig: cluster.kubeConfig, icon: cluster.icon || null, preferences: cluster.preferences || {} });
|
||||
}
|
||||
}
|
||||
});
|
||||
} as MigrationDeclaration;
|
||||
@@ -20,9 +20,9 @@
|
||||
*/
|
||||
|
||||
// Move cluster icon from root to preferences
|
||||
import { migration } from "../migration-wrapper";
|
||||
import type { MigrationDeclaration } from "../helpers";
|
||||
|
||||
export default migration({
|
||||
export default {
|
||||
version: "2.6.0-beta.2",
|
||||
run(store) {
|
||||
for (const value of store) {
|
||||
@@ -40,4 +40,4 @@ export default migration({
|
||||
store.set(clusterKey, { contextName: clusterKey, kubeConfig: value[1].kubeConfig, preferences: value[1].preferences });
|
||||
}
|
||||
}
|
||||
});
|
||||
} as MigrationDeclaration;
|
||||
@@ -19,12 +19,12 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { migration } from "../migration-wrapper";
|
||||
import yaml from "js-yaml";
|
||||
import { MigrationDeclaration, migrationLog } from "../helpers";
|
||||
|
||||
export default migration({
|
||||
export default {
|
||||
version: "2.6.0-beta.3",
|
||||
run(store, log) {
|
||||
run(store) {
|
||||
for (const value of store) {
|
||||
const clusterKey = value[0];
|
||||
|
||||
@@ -50,7 +50,7 @@ export default migration({
|
||||
if (authConfig.expiry) {
|
||||
authConfig.expiry = `${authConfig.expiry}`;
|
||||
}
|
||||
log(authConfig);
|
||||
migrationLog(authConfig);
|
||||
user["auth-provider"].config = authConfig;
|
||||
kubeConfig.users = [{
|
||||
name: userObj.name,
|
||||
@@ -62,4 +62,4 @@ export default migration({
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} as MigrationDeclaration;
|
||||
@@ -20,9 +20,9 @@
|
||||
*/
|
||||
|
||||
// Add existing clusters to "default" workspace
|
||||
import { migration } from "../migration-wrapper";
|
||||
import type { MigrationDeclaration } from "../helpers";
|
||||
|
||||
export default migration({
|
||||
export default {
|
||||
version: "2.7.0-beta.0",
|
||||
run(store) {
|
||||
for (const value of store) {
|
||||
@@ -35,4 +35,4 @@ export default migration({
|
||||
store.set(clusterKey, cluster);
|
||||
}
|
||||
}
|
||||
});
|
||||
} as MigrationDeclaration;
|
||||
@@ -20,10 +20,10 @@
|
||||
*/
|
||||
|
||||
// Add id for clusters and store them to array
|
||||
import { migration } from "../migration-wrapper";
|
||||
import { v4 as uuid } from "uuid";
|
||||
import type { MigrationDeclaration } from "../helpers";
|
||||
|
||||
export default migration({
|
||||
export default {
|
||||
version: "2.7.0-beta.1",
|
||||
run(store) {
|
||||
const clusters: any[] = [];
|
||||
@@ -48,4 +48,4 @@ export default migration({
|
||||
store.set("clusters", clusters);
|
||||
}
|
||||
}
|
||||
});
|
||||
} as MigrationDeclaration;
|
||||
@@ -24,25 +24,25 @@
|
||||
|
||||
import path from "path";
|
||||
import { app } from "electron";
|
||||
import { migration } from "../migration-wrapper";
|
||||
import fse from "fs-extra";
|
||||
import { ClusterModel, ClusterStore } from "../../common/cluster-store";
|
||||
import { loadConfigFromFileSync } from "../../common/kube-helpers";
|
||||
import { MigrationDeclaration, migrationLog } from "../helpers";
|
||||
|
||||
interface Pre360ClusterModel extends ClusterModel {
|
||||
kubeConfig: string;
|
||||
}
|
||||
|
||||
export default migration({
|
||||
export default {
|
||||
version: "3.6.0-beta.1",
|
||||
run(store, printLog) {
|
||||
run(store) {
|
||||
const userDataPath = app.getPath("userData");
|
||||
const storedClusters: Pre360ClusterModel[] = store.get("clusters") ?? [];
|
||||
const migratedClusters: ClusterModel[] = [];
|
||||
|
||||
fse.ensureDirSync(ClusterStore.storedKubeConfigFolder);
|
||||
|
||||
printLog("Number of clusters to migrate: ", storedClusters.length);
|
||||
migrationLog("Number of clusters to migrate: ", storedClusters.length);
|
||||
|
||||
for (const clusterModel of storedClusters) {
|
||||
/**
|
||||
@@ -59,7 +59,7 @@ export default migration({
|
||||
delete clusterModel.kubeConfig;
|
||||
|
||||
} catch (error) {
|
||||
printLog(`Failed to migrate Kubeconfig for cluster "${clusterModel.id}", removing clusterModel...`, error);
|
||||
migrationLog(`Failed to migrate Kubeconfig for cluster "${clusterModel.id}", removing clusterModel...`, error);
|
||||
|
||||
continue;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ export default migration({
|
||||
*/
|
||||
try {
|
||||
if (clusterModel.preferences?.icon) {
|
||||
printLog(`migrating ${clusterModel.preferences.icon} for ${clusterModel.preferences.clusterName}`);
|
||||
migrationLog(`migrating ${clusterModel.preferences.icon} for ${clusterModel.preferences.clusterName}`);
|
||||
const iconPath = clusterModel.preferences.icon.replace("store://", "");
|
||||
const fileData = fse.readFileSync(path.join(userDataPath, iconPath));
|
||||
|
||||
@@ -78,7 +78,7 @@ export default migration({
|
||||
delete clusterModel.preferences?.icon;
|
||||
}
|
||||
} catch (error) {
|
||||
printLog(`Failed to migrate cluster icon for cluster "${clusterModel.id}"`, error);
|
||||
migrationLog(`Failed to migrate cluster icon for cluster "${clusterModel.id}"`, error);
|
||||
delete clusterModel.preferences.icon;
|
||||
}
|
||||
|
||||
@@ -87,4 +87,4 @@ export default migration({
|
||||
|
||||
store.set("clusters", migratedClusters);
|
||||
}
|
||||
});
|
||||
} as MigrationDeclaration;
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import path from "path";
|
||||
import { app } from "electron";
|
||||
import fse from "fs-extra";
|
||||
import type { ClusterModel } from "../../common/cluster-store";
|
||||
import { MigrationDeclaration, migrationLog } from "../helpers";
|
||||
|
||||
interface Pre500WorkspaceStoreModel {
|
||||
workspaces: {
|
||||
id: string;
|
||||
name: string;
|
||||
}[];
|
||||
}
|
||||
|
||||
export default {
|
||||
version: "5.0.0-beta.10",
|
||||
run(store) {
|
||||
const userDataPath = app.getPath("userData");
|
||||
|
||||
try {
|
||||
const workspaceData: Pre500WorkspaceStoreModel = fse.readJsonSync(path.join(userDataPath, "lens-workspace-store.json"));
|
||||
const workspaces = new Map<string, string>(); // mapping from WorkspaceId to name
|
||||
|
||||
for (const { id, name } of workspaceData.workspaces) {
|
||||
workspaces.set(id, name);
|
||||
}
|
||||
|
||||
migrationLog("workspaces", JSON.stringify([...workspaces.entries()]));
|
||||
|
||||
const clusters: ClusterModel[] = store.get("clusters");
|
||||
|
||||
for (const cluster of clusters) {
|
||||
if (cluster.workspace && workspaces.has(cluster.workspace)) {
|
||||
cluster.labels ??= {};
|
||||
cluster.labels.workspace = workspaces.get(cluster.workspace);
|
||||
}
|
||||
}
|
||||
|
||||
store.set("clusters", clusters);
|
||||
} catch (error) {
|
||||
migrationLog("error", error.path);
|
||||
|
||||
if (!(error.code === "ENOENT" && error.path.endsWith("lens-workspace-store.json"))) {
|
||||
// ignore lens-workspace-store.json being missing
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
},
|
||||
} as MigrationDeclaration;
|
||||
@@ -21,6 +21,8 @@
|
||||
|
||||
// Cluster store migrations
|
||||
|
||||
import { joinMigrations } from "../helpers";
|
||||
|
||||
import version200Beta2 from "./2.0.0-beta.2";
|
||||
import version241 from "./2.4.1";
|
||||
import version260Beta2 from "./2.6.0-beta.2";
|
||||
@@ -28,15 +30,17 @@ import version260Beta3 from "./2.6.0-beta.3";
|
||||
import version270Beta0 from "./2.7.0-beta.0";
|
||||
import version270Beta1 from "./2.7.0-beta.1";
|
||||
import version360Beta1 from "./3.6.0-beta.1";
|
||||
import version500Beta10 from "./5.0.0-beta.10";
|
||||
import snap from "./snap";
|
||||
|
||||
export default {
|
||||
...version200Beta2,
|
||||
...version241,
|
||||
...version260Beta2,
|
||||
...version260Beta3,
|
||||
...version270Beta0,
|
||||
...version270Beta1,
|
||||
...version360Beta1,
|
||||
...snap
|
||||
};
|
||||
export default joinMigrations(
|
||||
version200Beta2,
|
||||
version241,
|
||||
version260Beta2,
|
||||
version260Beta3,
|
||||
version270Beta0,
|
||||
version270Beta1,
|
||||
version360Beta1,
|
||||
version500Beta10,
|
||||
snap,
|
||||
);
|
||||
@@ -21,22 +21,22 @@
|
||||
|
||||
// Fix embedded kubeconfig paths under snap config
|
||||
|
||||
import { migration } from "../migration-wrapper";
|
||||
import type { ClusterModel } from "../../common/cluster-store";
|
||||
import { getAppVersion } from "../../common/utils/app-version";
|
||||
import fs from "fs";
|
||||
import { MigrationDeclaration, migrationLog } from "../helpers";
|
||||
|
||||
export default migration({
|
||||
export default {
|
||||
version: getAppVersion(), // Run always after upgrade
|
||||
run(store, printLog) {
|
||||
run(store) {
|
||||
if (!process.env["SNAP"]) return;
|
||||
|
||||
printLog("Migrating embedded kubeconfig paths");
|
||||
migrationLog("Migrating embedded kubeconfig paths");
|
||||
const storedClusters: ClusterModel[] = store.get("clusters") || [];
|
||||
|
||||
if (!storedClusters.length) return;
|
||||
|
||||
printLog("Number of clusters to migrate: ", storedClusters.length);
|
||||
migrationLog("Number of clusters to migrate: ", storedClusters.length);
|
||||
const migratedClusters = storedClusters
|
||||
.map(cluster => {
|
||||
/**
|
||||
@@ -54,4 +54,4 @@ export default migration({
|
||||
|
||||
store.set("clusters", migratedClusters);
|
||||
}
|
||||
});
|
||||
} as MigrationDeclaration;
|
||||
@@ -19,24 +19,37 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import type Config from "conf";
|
||||
import type Conf from "conf";
|
||||
import type { Migrations } from "conf/dist/source/types";
|
||||
import { ExtendedMap, iter } from "../common/utils";
|
||||
import { isTestEnv } from "../common/vars";
|
||||
|
||||
export interface MigrationOpts {
|
||||
version: string;
|
||||
run(storeConfig: Config<any>, log: (...args: any[]) => void): void;
|
||||
export function migrationLog(...args: any[]) {
|
||||
if (!isTestEnv) {
|
||||
console.log(...args);
|
||||
}
|
||||
}
|
||||
|
||||
function infoLog(...args: any[]) {
|
||||
if (isTestEnv) return;
|
||||
console.log(...args);
|
||||
export interface MigrationDeclaration {
|
||||
version: string,
|
||||
run(store: Conf<any>): void;
|
||||
}
|
||||
|
||||
export function migration<S = any>({ version, run }: MigrationOpts) {
|
||||
return {
|
||||
[version]: (storeConfig: Config<S>) => {
|
||||
infoLog(`STORE MIGRATION (${storeConfig.path}): ${version}`,);
|
||||
run(storeConfig, infoLog);
|
||||
}
|
||||
};
|
||||
export function joinMigrations(...declarations: MigrationDeclaration[]): Migrations<any> {
|
||||
const migrations = new ExtendedMap<string, ((store: Conf<any>) => void)[]>();
|
||||
|
||||
for (const decl of declarations) {
|
||||
migrations.getOrInsert(decl.version, () => []).push(decl.run);
|
||||
}
|
||||
|
||||
return Object.fromEntries(
|
||||
iter.map(
|
||||
migrations,
|
||||
([v, fns]) => [v, (store: Conf<any>) => {
|
||||
for (const fn of fns) {
|
||||
fn(store);
|
||||
}
|
||||
}]
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -22,10 +22,10 @@
|
||||
// Cleans up a store that had the state related data stored
|
||||
import type { Hotbar } from "../../common/hotbar-store";
|
||||
import { ClusterStore } from "../../common/cluster-store";
|
||||
import { migration } from "../migration-wrapper";
|
||||
import { v4 as uuid } from "uuid";
|
||||
import * as uuid from "uuid";
|
||||
import type { MigrationDeclaration } from "../helpers";
|
||||
|
||||
export default migration({
|
||||
export default {
|
||||
version: "5.0.0-alpha.0",
|
||||
run(store) {
|
||||
const hotbars: Hotbar[] = [];
|
||||
@@ -38,7 +38,7 @@ export default migration({
|
||||
let hotbar = hotbars.find((h) => h.name === name);
|
||||
|
||||
if (!hotbar) {
|
||||
hotbar = { id: uuid(), name, items: [] };
|
||||
hotbar = { id: uuid.v4(), name, items: [] };
|
||||
hotbars.push(hotbar);
|
||||
}
|
||||
|
||||
@@ -50,4 +50,4 @@ export default migration({
|
||||
|
||||
store.set("hotbars", hotbars);
|
||||
}
|
||||
});
|
||||
} as MigrationDeclaration;
|
||||
@@ -21,10 +21,10 @@
|
||||
|
||||
// Cleans up a store that had the state related data stored
|
||||
import type { Hotbar } from "../../common/hotbar-store";
|
||||
import { migration } from "../migration-wrapper";
|
||||
import * as uuid from "uuid";
|
||||
import type { MigrationDeclaration } from "../helpers";
|
||||
|
||||
export default migration({
|
||||
export default {
|
||||
version: "5.0.0-alpha.2",
|
||||
run(store) {
|
||||
const hotbars = (store.get("hotbars") || []) as Hotbar[];
|
||||
@@ -34,4 +34,4 @@ export default migration({
|
||||
...hotbar
|
||||
})));
|
||||
}
|
||||
});
|
||||
} as MigrationDeclaration;
|
||||
@@ -20,10 +20,10 @@
|
||||
*/
|
||||
|
||||
import type { Hotbar } from "../../common/hotbar-store";
|
||||
import { migration } from "../migration-wrapper";
|
||||
import { catalogEntityRegistry } from "../../renderer/api/catalog-entity-registry";
|
||||
import type { MigrationDeclaration } from "../helpers";
|
||||
|
||||
export default migration({
|
||||
export default {
|
||||
version: "5.0.0-beta.5",
|
||||
run(store) {
|
||||
const hotbars: Hotbar[] = store.get("hotbars");
|
||||
@@ -48,4 +48,4 @@ export default migration({
|
||||
|
||||
store.set("hotbars", hotbars);
|
||||
}
|
||||
});
|
||||
} as MigrationDeclaration;
|
||||
@@ -21,12 +21,14 @@
|
||||
|
||||
// Hotbar store migrations
|
||||
|
||||
import { joinMigrations } from "../helpers";
|
||||
|
||||
import version500alpha0 from "./5.0.0-alpha.0";
|
||||
import version500alpha2 from "./5.0.0-alpha.2";
|
||||
import version500beta5 from "./5.0.0-beta.5";
|
||||
|
||||
export default {
|
||||
...version500alpha0,
|
||||
...version500alpha2,
|
||||
...version500beta5,
|
||||
};
|
||||
export default joinMigrations(
|
||||
version500alpha0,
|
||||
version500alpha2,
|
||||
version500beta5,
|
||||
);
|
||||
@@ -20,11 +20,11 @@
|
||||
*/
|
||||
|
||||
// Add / reset "lastSeenAppVersion"
|
||||
import { migration } from "../migration-wrapper";
|
||||
import type { MigrationDeclaration } from "../helpers";
|
||||
|
||||
export default migration({
|
||||
export default {
|
||||
version: "2.1.0-beta.4",
|
||||
run(store) {
|
||||
store.set("lastSeenAppVersion", "0.0.0");
|
||||
}
|
||||
});
|
||||
} as MigrationDeclaration;
|
||||
@@ -20,9 +20,9 @@
|
||||
*/
|
||||
|
||||
// Switch representation of hiddenTableColumns in store
|
||||
import { migration } from "../migration-wrapper";
|
||||
import type { MigrationDeclaration } from "../helpers";
|
||||
|
||||
export default migration({
|
||||
export default {
|
||||
version: "5.0.0-alpha.3",
|
||||
run(store) {
|
||||
const preferences = store.get("preferences");
|
||||
@@ -36,4 +36,4 @@ export default migration({
|
||||
|
||||
store.set("preferences", preferences);
|
||||
}
|
||||
});
|
||||
} as MigrationDeclaration;
|
||||
@@ -21,6 +21,8 @@
|
||||
|
||||
// User store migrations
|
||||
|
||||
import { joinMigrations } from "../helpers";
|
||||
|
||||
import version210Beta4 from "./2.1.0-beta.4";
|
||||
import version500Alpha3 from "./5.0.0-alpha.3";
|
||||
import { fileNameMigration } from "./file-name-migration";
|
||||
@@ -29,7 +31,7 @@ export {
|
||||
fileNameMigration
|
||||
};
|
||||
|
||||
export default {
|
||||
...version210Beta4,
|
||||
...version500Alpha3,
|
||||
};
|
||||
export default joinMigrations(
|
||||
version210Beta4,
|
||||
version500Alpha3,
|
||||
);
|
||||
Reference in new issue
Block a user