mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Cascade different refactorings to eliminate global shared state from app paths
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
1 parent
908a40975e
commit
9d33fff906
336 files changed
+9105
-3307
No files matched your search
@@ -27,8 +27,13 @@ import fse from "fs-extra";
|
||||
import { loadConfigFromFileSync } from "../../common/kube-helpers";
|
||||
import { MigrationDeclaration, migrationLog } from "../helpers";
|
||||
import type { ClusterModel } from "../../common/cluster-types";
|
||||
import { getCustomKubeConfigPath, storedKubeConfigFolder } from "../../common/utils";
|
||||
import { AppPaths } from "../../common/app-paths";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-global-function-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import directoryForUserDataInjectable
|
||||
from "../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import directoryForKubeConfigsInjectable
|
||||
from "../../common/app-paths/directory-for-kube-configs/directory-for-kube-configs.injectable";
|
||||
import getCustomKubeConfigDirectoryInjectable
|
||||
from "../../common/app-paths/get-custom-kube-config-directory/get-custom-kube-config-directory.injectable";
|
||||
|
||||
interface Pre360ClusterModel extends ClusterModel {
|
||||
kubeConfig: string;
|
||||
@@ -37,11 +42,16 @@ interface Pre360ClusterModel extends ClusterModel {
|
||||
export default {
|
||||
version: "3.6.0-beta.1",
|
||||
run(store) {
|
||||
const userDataPath = AppPaths.get("userData");
|
||||
const di = getLegacyGlobalDiForExtensionApi();
|
||||
|
||||
const userDataPath = di.inject(directoryForUserDataInjectable);
|
||||
const kubeConfigsPath = di.inject(directoryForKubeConfigsInjectable);
|
||||
const getCustomKubeConfigDirectory = di.inject(getCustomKubeConfigDirectoryInjectable);
|
||||
|
||||
const storedClusters: Pre360ClusterModel[] = store.get("clusters") ?? [];
|
||||
const migratedClusters: ClusterModel[] = [];
|
||||
|
||||
fse.ensureDirSync(storedKubeConfigFolder());
|
||||
fse.ensureDirSync(kubeConfigsPath);
|
||||
|
||||
migrationLog("Number of clusters to migrate: ", storedClusters.length);
|
||||
|
||||
@@ -50,7 +60,7 @@ export default {
|
||||
* migrate kubeconfig
|
||||
*/
|
||||
try {
|
||||
const absPath = getCustomKubeConfigPath(clusterModel.id);
|
||||
const absPath = getCustomKubeConfigDirectory(clusterModel.id);
|
||||
|
||||
// take the embedded kubeconfig and dump it into a file
|
||||
fse.writeFileSync(absPath, clusterModel.kubeConfig, { encoding: "utf-8", mode: 0o600 });
|
||||
|
||||
@@ -23,7 +23,9 @@ import path from "path";
|
||||
import fse from "fs-extra";
|
||||
import type { ClusterModel } from "../../common/cluster-types";
|
||||
import type { MigrationDeclaration } from "../helpers";
|
||||
import { AppPaths } from "../../common/app-paths";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-global-function-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import directoryForUserDataInjectable
|
||||
from "../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
|
||||
interface Pre500WorkspaceStoreModel {
|
||||
workspaces: {
|
||||
@@ -35,7 +37,9 @@ interface Pre500WorkspaceStoreModel {
|
||||
export default {
|
||||
version: "5.0.0-beta.10",
|
||||
run(store) {
|
||||
const userDataPath = AppPaths.get("userData");
|
||||
const di = getLegacyGlobalDiForExtensionApi();
|
||||
|
||||
const userDataPath = di.inject(directoryForUserDataInjectable);
|
||||
|
||||
try {
|
||||
const workspaceData: Pre500WorkspaceStoreModel = fse.readJsonSync(path.join(userDataPath, "lens-workspace-store.json"));
|
||||
|
||||
@@ -24,7 +24,9 @@ import { MigrationDeclaration, migrationLog } from "../helpers";
|
||||
import { generateNewIdFor } from "../utils";
|
||||
import path from "path";
|
||||
import { moveSync, removeSync } from "fs-extra";
|
||||
import { AppPaths } from "../../common/app-paths";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-global-function-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import directoryForUserDataInjectable
|
||||
from "../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
|
||||
function mergePrometheusPreferences(left: ClusterPrometheusPreferences, right: ClusterPrometheusPreferences): ClusterPrometheusPreferences {
|
||||
if (left.prometheus && left.prometheusProvider) {
|
||||
@@ -106,7 +108,11 @@ function moveStorageFolder({ folder, newId, oldId }: { folder: string, newId: st
|
||||
export default {
|
||||
version: "5.0.0-beta.13",
|
||||
run(store) {
|
||||
const folder = path.resolve(AppPaths.get("userData"), "lens-local-storage");
|
||||
const di = getLegacyGlobalDiForExtensionApi();
|
||||
|
||||
const userDataPath = di.inject(directoryForUserDataInjectable);
|
||||
|
||||
const folder = path.resolve(userDataPath, "lens-local-storage");
|
||||
|
||||
const oldClusters: ClusterModel[] = store.get("clusters") ?? [];
|
||||
const clusters = new Map<string, ClusterModel>();
|
||||
|
||||
@@ -23,12 +23,14 @@ import fse from "fs-extra";
|
||||
import { isNull } from "lodash";
|
||||
import path from "path";
|
||||
import * as uuid from "uuid";
|
||||
import { AppPaths } from "../../common/app-paths";
|
||||
import type { ClusterStoreModel } from "../../common/cluster-store";
|
||||
import type { ClusterStoreModel } from "../../common/cluster-store/cluster-store";
|
||||
import { defaultHotbarCells, getEmptyHotbar, Hotbar, HotbarItem } from "../../common/hotbar-types";
|
||||
import { catalogEntity } from "../../main/catalog-sources/general";
|
||||
import { MigrationDeclaration, migrationLog } from "../helpers";
|
||||
import { generateNewIdFor } from "../utils";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-global-function-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import directoryForUserDataInjectable
|
||||
from "../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
|
||||
interface Pre500WorkspaceStoreModel {
|
||||
workspaces: {
|
||||
@@ -48,7 +50,10 @@ export default {
|
||||
run(store) {
|
||||
const rawHotbars = store.get("hotbars");
|
||||
const hotbars: Hotbar[] = Array.isArray(rawHotbars) ? rawHotbars.filter(h => h && typeof h === "object") : [];
|
||||
const userDataPath = AppPaths.get("userData");
|
||||
|
||||
const di = getLegacyGlobalDiForExtensionApi();
|
||||
|
||||
const userDataPath = di.inject(directoryForUserDataInjectable);
|
||||
|
||||
// Hotbars might be empty, if some of the previous migrations weren't run
|
||||
if (hotbars.length === 0) {
|
||||
|
||||
@@ -22,20 +22,29 @@
|
||||
import { existsSync, readFileSync } from "fs";
|
||||
import path from "path";
|
||||
import os from "os";
|
||||
import type { ClusterStoreModel } from "../../common/cluster-store";
|
||||
import type { ClusterStoreModel } from "../../common/cluster-store/cluster-store";
|
||||
import type { KubeconfigSyncEntry, UserPreferencesModel } from "../../common/user-store";
|
||||
import { MigrationDeclaration, migrationLog } from "../helpers";
|
||||
import { isLogicalChildPath, storedKubeConfigFolder } from "../../common/utils";
|
||||
import { AppPaths } from "../../common/app-paths";
|
||||
import { isLogicalChildPath } from "../../common/utils";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-global-function-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import directoryForUserDataInjectable
|
||||
from "../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import directoryForKubeConfigsInjectable
|
||||
from "../../common/app-paths/directory-for-kube-configs/directory-for-kube-configs.injectable";
|
||||
|
||||
export default {
|
||||
version: "5.0.3-beta.1",
|
||||
run(store) {
|
||||
try {
|
||||
const { syncKubeconfigEntries = [], ...preferences }: UserPreferencesModel = store.get("preferences") ?? {};
|
||||
const userData = AppPaths.get("userData");
|
||||
const { clusters = [] }: ClusterStoreModel = JSON.parse(readFileSync(path.resolve(userData, "lens-cluster-store.json"), "utf-8")) ?? {};
|
||||
const extensionDataDir = path.resolve(userData, "extension_data");
|
||||
|
||||
const di = getLegacyGlobalDiForExtensionApi();
|
||||
|
||||
const userDataPath = di.inject(directoryForUserDataInjectable);
|
||||
const kubeConfigsPath = di.inject(directoryForKubeConfigsInjectable);
|
||||
|
||||
const { clusters = [] }: ClusterStoreModel = JSON.parse(readFileSync(path.resolve(userDataPath, "lens-cluster-store.json"), "utf-8")) ?? {};
|
||||
const extensionDataDir = path.resolve(userDataPath, "extension_data");
|
||||
const syncPaths = new Set(syncKubeconfigEntries.map(s => s.filePath));
|
||||
|
||||
syncPaths.add(path.join(os.homedir(), ".kube"));
|
||||
@@ -46,7 +55,7 @@ export default {
|
||||
}
|
||||
const dirOfKubeconfig = path.dirname(cluster.kubeConfigPath);
|
||||
|
||||
if (dirOfKubeconfig === storedKubeConfigFolder()) {
|
||||
if (dirOfKubeconfig === kubeConfigsPath) {
|
||||
migrationLog(`Skipping ${cluster.id} because kubeConfigPath is under the stored KubeConfig folder`);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -21,10 +21,14 @@
|
||||
|
||||
import fse from "fs-extra";
|
||||
import path from "path";
|
||||
import { AppPaths } from "../../common/app-paths";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-global-function-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import directoryForUserDataInjectable
|
||||
from "../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
|
||||
export function fileNameMigration() {
|
||||
const userDataPath = AppPaths.get("userData");
|
||||
const di = getLegacyGlobalDiForExtensionApi();
|
||||
|
||||
const userDataPath = di.inject(directoryForUserDataInjectable);
|
||||
const configJsonPath = path.join(userDataPath, "config.json");
|
||||
const lensUserStoreJsonPath = path.join(userDataPath, "lens-user-store.json");
|
||||
|
||||
|
||||
Reference in new issue
Block a user