mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Migrating Vue components to React and stores refactoring (#585)
Signed-off-by: Roman <ixrock@gmail.com> Co-authored-by: Sebastian Malton <sebastian@malton.name> Co-authored-by: Sebastian Malton <smalton@mirantis.com> Co-authored-by: Lauri Nevala <lauri.nevala@gmail.com> Co-authored-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
297 files changed
+8186
-9103
No files matched your search
@@ -1,17 +1,16 @@
|
||||
/* Early store format had the kubeconfig directly under context name, this moves
|
||||
it under the kubeConfig key */
|
||||
|
||||
import { isTestEnv } from "../../common/vars";
|
||||
import { migration } from "../migration-wrapper";
|
||||
|
||||
export function migration(store: any) {
|
||||
if(!isTestEnv) {
|
||||
console.log("CLUSTER STORE, MIGRATION: 2.0.0-beta.2");
|
||||
export default migration({
|
||||
version: "2.0.0-beta.2",
|
||||
run(store, log) {
|
||||
for (const value of store) {
|
||||
const contextName = value[0];
|
||||
// Looping all the keys gives out the store internal stuff too...
|
||||
if (contextName === "__internal__" || value[1].hasOwnProperty('kubeConfig')) continue;
|
||||
store.set(contextName, { kubeConfig: value[1] });
|
||||
}
|
||||
}
|
||||
for (const value of store) {
|
||||
const contextName = value[0];
|
||||
// Looping all the keys gives out the store internal stuff too...
|
||||
if(contextName === "__internal__" || value[1].hasOwnProperty('kubeConfig')) continue;
|
||||
|
||||
store.set(contextName, { kubeConfig: value[1] });
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -1,15 +1,14 @@
|
||||
// Cleans up a store that had the state related data stored
|
||||
import { isTestEnv } from "../../common/vars";
|
||||
import { migration } from "../migration-wrapper";
|
||||
|
||||
export function migration(store: any) {
|
||||
if (!isTestEnv) {
|
||||
console.log("CLUSTER STORE, MIGRATION: 2.4.1");
|
||||
export default migration({
|
||||
version: "2.4.1",
|
||||
run(store, log) {
|
||||
for (const value of store) {
|
||||
const contextName = value[0];
|
||||
if (contextName === "__internal__") continue;
|
||||
const cluster = value[1];
|
||||
store.set(contextName, { kubeConfig: cluster.kubeConfig, icon: cluster.icon || null, preferences: cluster.preferences || {} });
|
||||
}
|
||||
}
|
||||
for (const value of store) {
|
||||
const contextName = value[0];
|
||||
if (contextName === "__internal__") continue;
|
||||
const cluster = value[1];
|
||||
|
||||
store.set(contextName, { kubeConfig: cluster.kubeConfig, icon: cluster.icon || null, preferences: cluster.preferences || {} });
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -1,19 +1,19 @@
|
||||
// Move cluster icon from root to preferences
|
||||
import { isTestEnv } from "../../common/vars";
|
||||
import { migration } from "../migration-wrapper";
|
||||
|
||||
export function migration(store: any) {
|
||||
if(!isTestEnv) {
|
||||
console.log("CLUSTER STORE, MIGRATION: 2.6.0-beta.2");
|
||||
}
|
||||
for (const value of store) {
|
||||
const clusterKey = value[0];
|
||||
if(clusterKey === "__internal__") continue
|
||||
const cluster = value[1];
|
||||
if(!cluster.preferences) cluster.preferences = {};
|
||||
if(cluster.icon) {
|
||||
cluster.preferences.icon = cluster.icon;
|
||||
delete(cluster["icon"]);
|
||||
export default migration({
|
||||
version: "2.6.0-beta.2",
|
||||
run(store, log) {
|
||||
for (const value of store) {
|
||||
const clusterKey = value[0];
|
||||
if (clusterKey === "__internal__") continue
|
||||
const cluster = value[1];
|
||||
if (!cluster.preferences) cluster.preferences = {};
|
||||
if (cluster.icon) {
|
||||
cluster.preferences.icon = cluster.icon;
|
||||
delete (cluster["icon"]);
|
||||
}
|
||||
store.set(clusterKey, { contextName: clusterKey, kubeConfig: value[1].kubeConfig, preferences: value[1].preferences });
|
||||
}
|
||||
store.set(clusterKey, { contextName: clusterKey, kubeConfig: value[1].kubeConfig, preferences: value[1].preferences });
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -1,38 +1,38 @@
|
||||
import * as yaml from "js-yaml"
|
||||
import { isTestEnv } from "../../common/vars";
|
||||
import { migration } from "../migration-wrapper";
|
||||
import yaml from "js-yaml"
|
||||
|
||||
// Convert access token and expiry from arrays into strings
|
||||
export function migration(store: any) {
|
||||
if(!isTestEnv) {
|
||||
console.log("CLUSTER STORE, MIGRATION: 2.6.0-beta.3");
|
||||
}
|
||||
for (const value of store) {
|
||||
const clusterKey = value[0];
|
||||
if(clusterKey === "__internal__") continue
|
||||
const cluster = value[1];
|
||||
if(!cluster.kubeConfig) continue
|
||||
const kubeConfig = yaml.safeLoad(cluster.kubeConfig)
|
||||
if(!kubeConfig.hasOwnProperty('users')) continue
|
||||
const userObj = kubeConfig.users[0]
|
||||
if (userObj) {
|
||||
const user = userObj.user
|
||||
if (user["auth-provider"] && user["auth-provider"].config) {
|
||||
const authConfig = user["auth-provider"].config
|
||||
if (authConfig["access-token"]) {
|
||||
authConfig["access-token"] = `${authConfig["access-token"]}`
|
||||
export default migration({
|
||||
version: "2.6.0-beta.3",
|
||||
run(store, log) {
|
||||
for (const value of store) {
|
||||
const clusterKey = value[0];
|
||||
if (clusterKey === "__internal__") continue
|
||||
const cluster = value[1];
|
||||
if (!cluster.kubeConfig) continue
|
||||
const kubeConfig = yaml.safeLoad(cluster.kubeConfig)
|
||||
if (!kubeConfig.hasOwnProperty('users')) continue
|
||||
const userObj = kubeConfig.users[0]
|
||||
if (userObj) {
|
||||
const user = userObj.user
|
||||
if (user["auth-provider"] && user["auth-provider"].config) {
|
||||
const authConfig = user["auth-provider"].config
|
||||
if (authConfig["access-token"]) {
|
||||
authConfig["access-token"] = `${authConfig["access-token"]}`
|
||||
}
|
||||
if (authConfig.expiry) {
|
||||
authConfig.expiry = `${authConfig.expiry}`
|
||||
}
|
||||
log(authConfig)
|
||||
user["auth-provider"].config = authConfig
|
||||
kubeConfig.users = [{
|
||||
name: userObj.name,
|
||||
user: user
|
||||
}]
|
||||
cluster.kubeConfig = yaml.safeDump(kubeConfig)
|
||||
store.set(clusterKey, cluster)
|
||||
}
|
||||
if (authConfig.expiry) {
|
||||
authConfig.expiry = `${authConfig.expiry}`
|
||||
}
|
||||
console.log(authConfig)
|
||||
user["auth-provider"].config = authConfig
|
||||
kubeConfig.users = [{
|
||||
name: userObj.name,
|
||||
user: user
|
||||
}]
|
||||
cluster.kubeConfig = yaml.safeDump(kubeConfig)
|
||||
store.set(clusterKey, cluster)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
// Add existing clusters to "default" workspace
|
||||
import { isTestEnv } from "../../common/vars";
|
||||
import { migration } from "../migration-wrapper";
|
||||
|
||||
export function migration(store: any) {
|
||||
if(!isTestEnv) {
|
||||
console.log("CLUSTER STORE, MIGRATION: 2.7.0-beta.0");
|
||||
export default migration({
|
||||
version: "2.7.0-beta.0",
|
||||
run(store, log) {
|
||||
for (const value of store) {
|
||||
const clusterKey = value[0];
|
||||
if(clusterKey === "__internal__") continue
|
||||
const cluster = value[1];
|
||||
cluster.workspace = "default"
|
||||
store.set(clusterKey, cluster)
|
||||
}
|
||||
}
|
||||
for (const value of store) {
|
||||
const clusterKey = value[0];
|
||||
if(clusterKey === "__internal__") continue
|
||||
const cluster = value[1];
|
||||
cluster.workspace = "default"
|
||||
store.set(clusterKey, cluster)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -1,25 +1,25 @@
|
||||
// add id for clusters and store them to array
|
||||
// Add id for clusters and store them to array
|
||||
import { migration } from "../migration-wrapper";
|
||||
import { v4 as uuid } from "uuid"
|
||||
import { isTestEnv } from "../../common/vars";
|
||||
|
||||
export function migration(store: any) {
|
||||
if(!isTestEnv) {
|
||||
console.log("CLUSTER STORE, MIGRATION: 2.7.0-beta.1");
|
||||
}
|
||||
const clusters: any[] = []
|
||||
for (const value of store) {
|
||||
const clusterKey = value[0];
|
||||
if(clusterKey === "__internal__") continue
|
||||
if(clusterKey === "clusters") continue
|
||||
const cluster = value[1];
|
||||
cluster.id = uuid()
|
||||
if (!cluster.preferences.clusterName) {
|
||||
cluster.preferences.clusterName = clusterKey
|
||||
export default migration({
|
||||
version: "2.7.0-beta.1",
|
||||
run(store, log) {
|
||||
const clusters: any[] = []
|
||||
for (const value of store) {
|
||||
const clusterKey = value[0];
|
||||
if (clusterKey === "__internal__") continue
|
||||
if (clusterKey === "clusters") continue
|
||||
const cluster = value[1];
|
||||
cluster.id = uuid()
|
||||
if (!cluster.preferences.clusterName) {
|
||||
cluster.preferences.clusterName = clusterKey
|
||||
}
|
||||
clusters.push(cluster)
|
||||
store.delete(clusterKey)
|
||||
}
|
||||
if (clusters.length > 0) {
|
||||
store.set("clusters", clusters)
|
||||
}
|
||||
clusters.push(cluster)
|
||||
store.delete(clusterKey)
|
||||
}
|
||||
if (clusters.length > 0) {
|
||||
store.set("clusters", clusters)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -1,39 +1,38 @@
|
||||
// move embedded kubeconfig into separate file and add reference to it to cluster settings
|
||||
import { app } from "electron"
|
||||
import { ensureDirSync } from "fs-extra"
|
||||
import * as path from "path"
|
||||
import { KubeConfig } from "@kubernetes/client-node";
|
||||
import { writeEmbeddedKubeConfig } from "../../common/utils/kubeconfig"
|
||||
// Move embedded kubeconfig into separate file and add reference to it to cluster settings
|
||||
|
||||
export function migration(store: any) {
|
||||
console.log("CLUSTER STORE, MIGRATION: 3.6.0-beta.1");
|
||||
const clusters: any[] = []
|
||||
import path from "path"
|
||||
import { app, remote } from "electron"
|
||||
import { migration } from "../migration-wrapper";
|
||||
import { ensureDirSync } from "fs-extra"
|
||||
import { ClusterModel } from "../../common/cluster-store";
|
||||
import { loadConfig, saveConfigToAppFiles } from "../../common/kube-helpers";
|
||||
|
||||
const kubeConfigBase = path.join(app.getPath("userData"), "kubeconfigs")
|
||||
ensureDirSync(kubeConfigBase)
|
||||
const storedClusters = store.get("clusters") as any[]
|
||||
if (!storedClusters) return
|
||||
export default migration({
|
||||
version: "3.6.0-beta.1",
|
||||
run(store, printLog) {
|
||||
const migratedClusters: ClusterModel[] = []
|
||||
const storedClusters: ClusterModel[] = store.get("clusters");
|
||||
const kubeConfigBase = path.join((app || remote.app).getPath("userData"), "kubeconfigs")
|
||||
|
||||
console.log("num clusters to migrate: ", storedClusters.length)
|
||||
for (const cluster of storedClusters ) {
|
||||
try {
|
||||
// take the embedded kubeconfig and dump it into a file
|
||||
const kubeConfigFile = writeEmbeddedKubeConfig(cluster.id, cluster.kubeConfig)
|
||||
cluster.kubeConfigPath = kubeConfigFile
|
||||
if (!storedClusters) return;
|
||||
ensureDirSync(kubeConfigBase);
|
||||
|
||||
const kc = new KubeConfig()
|
||||
kc.loadFromFile(cluster.kubeConfigPath)
|
||||
cluster.contextName = kc.getCurrentContext()
|
||||
printLog("Number of clusters to migrate: ", storedClusters.length)
|
||||
for (const cluster of storedClusters) {
|
||||
try {
|
||||
// take the embedded kubeconfig and dump it into a file
|
||||
cluster.kubeConfigPath = saveConfigToAppFiles(cluster.id, cluster.kubeConfig)
|
||||
cluster.contextName = loadConfig(cluster.kubeConfigPath).getCurrentContext();
|
||||
delete cluster.kubeConfig;
|
||||
migratedClusters.push(cluster)
|
||||
} catch (error) {
|
||||
printLog(`Failed to migrate Kubeconfig for cluster "${cluster.id}"`, error)
|
||||
}
|
||||
}
|
||||
|
||||
delete cluster.kubeConfig
|
||||
clusters.push(cluster)
|
||||
} catch(error) {
|
||||
console.error("failed to migrate kubeconfig for cluster:", cluster.id)
|
||||
// "overwrite" the cluster configs
|
||||
if (migratedClusters.length > 0) {
|
||||
store.set("clusters", migratedClusters)
|
||||
}
|
||||
}
|
||||
|
||||
// "overwrite" the cluster configs
|
||||
if (clusters.length > 0) {
|
||||
store.set("clusters", clusters)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,19 @@
|
||||
// Cluster store migrations
|
||||
|
||||
import version200Beta2 from "./2.0.0-beta.2"
|
||||
import version241 from "./2.4.1"
|
||||
import version260Beta2 from "./2.6.0-beta.2"
|
||||
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"
|
||||
|
||||
export default {
|
||||
...version200Beta2,
|
||||
...version241,
|
||||
...version260Beta2,
|
||||
...version260Beta3,
|
||||
...version270Beta0,
|
||||
...version270Beta1,
|
||||
...version360Beta1,
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import Config from "conf";
|
||||
import { isTestEnv } from "../common/vars";
|
||||
|
||||
export interface MigrationOpts {
|
||||
version: string;
|
||||
run(storeConfig: Config<any>, log: (...args: any[]) => void): void;
|
||||
}
|
||||
|
||||
function infoLog(...args: any[]) {
|
||||
if (isTestEnv) return;
|
||||
console.log(...args);
|
||||
}
|
||||
|
||||
export function migration<S = any>({ version, run }: MigrationOpts) {
|
||||
return {
|
||||
[version]: (storeConfig: Config<S>) => {
|
||||
infoLog(`STORE MIGRATION (${storeConfig.path}): ${version}`,);
|
||||
run(storeConfig, infoLog);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,4 +1,9 @@
|
||||
// Add / reset "lastSeenAppVersion"
|
||||
export function migration(store: any) {
|
||||
store.set("lastSeenAppVersion", "0.0.0");
|
||||
}
|
||||
import { migration } from "../migration-wrapper";
|
||||
|
||||
export default migration({
|
||||
version: "2.1.0-beta.4",
|
||||
run(store) {
|
||||
store.set("lastSeenAppVersion", "0.0.0");
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,7 @@
|
||||
// User store migrations
|
||||
|
||||
import version210Beta4 from "./2.1.0-beta.4"
|
||||
|
||||
export default {
|
||||
...version210Beta4,
|
||||
}
|
||||
Reference in new issue
Block a user