mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
add cluster icon migration code
Signed-off-by: Sebastian Malton <smalton@mirantis.com>
This commit is contained in:
parent
6e645eade0
commit
0869bb9cb2
@ -1,34 +1,57 @@
|
|||||||
// Move embedded kubeconfig into separate file and add reference to it to cluster settings
|
// Move embedded kubeconfig into separate file and add reference to it to cluster settings
|
||||||
|
// convert file path cluster icons to their base64 encoded versions
|
||||||
|
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { app, remote } from "electron"
|
import { app, remote } from "electron"
|
||||||
import { migration } from "../migration-wrapper";
|
import { migration } from "../migration-wrapper";
|
||||||
import { ensureDirSync } from "fs-extra"
|
import fse from "fs-extra"
|
||||||
import { ClusterModel } from "../../common/cluster-store";
|
import { ClusterModel } from "../../common/cluster-store";
|
||||||
import { loadConfig, saveConfigToAppFiles } from "../../common/kube-helpers";
|
import { loadConfig, saveConfigToAppFiles } from "../../common/kube-helpers";
|
||||||
|
|
||||||
export default migration({
|
export default migration({
|
||||||
version: "3.6.0-beta.1",
|
version: "3.6.0-beta.1",
|
||||||
run(store, printLog) {
|
run(store, printLog) {
|
||||||
const migratedClusters: ClusterModel[] = []
|
|
||||||
const storedClusters: ClusterModel[] = store.get("clusters");
|
|
||||||
const kubeConfigBase = path.join((app || remote.app).getPath("userData"), "kubeconfigs")
|
const kubeConfigBase = path.join((app || remote.app).getPath("userData"), "kubeconfigs")
|
||||||
|
const storedClusters: ClusterModel[] = store.get("clusters") || [];
|
||||||
|
|
||||||
if (!storedClusters) return;
|
if (!storedClusters?.length) return;
|
||||||
ensureDirSync(kubeConfigBase);
|
fse.ensureDirSync(kubeConfigBase);
|
||||||
|
|
||||||
printLog("Number of clusters to migrate: ", storedClusters.length)
|
printLog("Number of clusters to migrate: ", storedClusters.length)
|
||||||
for (const cluster of storedClusters) {
|
const migratedClusters = storedClusters
|
||||||
try {
|
.map(cluster => {
|
||||||
// take the embedded kubeconfig and dump it into a file
|
/**
|
||||||
cluster.kubeConfigPath = saveConfigToAppFiles(cluster.id, cluster.kubeConfig)
|
* migrate kubeconfig
|
||||||
cluster.contextName = loadConfig(cluster.kubeConfigPath).getCurrentContext();
|
*/
|
||||||
delete cluster.kubeConfig;
|
try {
|
||||||
migratedClusters.push(cluster)
|
// take the embedded kubeconfig and dump it into a file
|
||||||
} catch (error) {
|
cluster.kubeConfigPath = saveConfigToAppFiles(cluster.id, cluster.kubeConfig)
|
||||||
printLog(`Failed to migrate Kubeconfig for cluster "${cluster.id}"`, error)
|
cluster.contextName = loadConfig(cluster.kubeConfigPath).getCurrentContext();
|
||||||
}
|
delete cluster.kubeConfig;
|
||||||
}
|
|
||||||
|
} catch (error) {
|
||||||
|
printLog(`Failed to migrate Kubeconfig for cluster "${cluster.id}"`, error)
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* migrate cluster icon
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
if (cluster.preferences.icon) {
|
||||||
|
const fileData = fse.readFileSync(cluster.preferences.icon);
|
||||||
|
cluster.preferences.icon = `data:image;base64, ${fileData.toString('base64')}`;
|
||||||
|
} else {
|
||||||
|
delete cluster.preferences.icon;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
printLog(`Failed to migrate cluster icon for cluster "${cluster.id}"`, error)
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cluster;
|
||||||
|
})
|
||||||
|
.filter(c => c);
|
||||||
|
|
||||||
// "overwrite" the cluster configs
|
// "overwrite" the cluster configs
|
||||||
if (migratedClusters.length > 0) {
|
if (migratedClusters.length > 0) {
|
||||||
|
|||||||
@ -28,7 +28,7 @@ export class ClusterIconSetting extends React.Component<Props> {
|
|||||||
try {
|
try {
|
||||||
if (file) {
|
if (file) {
|
||||||
const buf = Buffer.from(await file.arrayBuffer());
|
const buf = Buffer.from(await file.arrayBuffer());
|
||||||
cluster.preferences.icon = `data:image/jpeg;base64, ${buf.toString('base64')}`;
|
cluster.preferences.icon = `data:image;base64, ${buf.toString('base64')}`;
|
||||||
} else {
|
} else {
|
||||||
// this has to be done as a seperate branch (and not always) because `cluster`
|
// this has to be done as a seperate branch (and not always) because `cluster`
|
||||||
// is observable and triggers an update loop.
|
// is observable and triggers an update loop.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user