From b7cb10521ef8dec5846b88bf6d32cbdb2c9c7f5b Mon Sep 17 00:00:00 2001 From: Jari Kolehmainen Date: Wed, 19 Jan 2022 15:27:34 +0200 Subject: [PATCH] Drop old (< 3.0) cluster-store migrations (#4718) --- src/common/__tests__/cluster-store.test.ts | 154 ------------------- src/migrations/cluster-store/2.0.0-beta.2.ts | 24 --- src/migrations/cluster-store/2.4.1.ts | 22 --- src/migrations/cluster-store/2.6.0-beta.2.ts | 27 ---- src/migrations/cluster-store/2.6.0-beta.3.ts | 53 ------- src/migrations/cluster-store/2.7.0-beta.0.ts | 22 --- src/migrations/cluster-store/2.7.0-beta.1.ts | 35 ----- src/migrations/cluster-store/index.ts | 12 -- 8 files changed, 349 deletions(-) delete mode 100644 src/migrations/cluster-store/2.0.0-beta.2.ts delete mode 100644 src/migrations/cluster-store/2.4.1.ts delete mode 100644 src/migrations/cluster-store/2.6.0-beta.2.ts delete mode 100644 src/migrations/cluster-store/2.6.0-beta.3.ts delete mode 100644 src/migrations/cluster-store/2.7.0-beta.0.ts delete mode 100644 src/migrations/cluster-store/2.7.0-beta.1.ts diff --git a/src/common/__tests__/cluster-store.test.ts b/src/common/__tests__/cluster-store.test.ts index ee93106adf..f11bd2d593 100644 --- a/src/common/__tests__/cluster-store.test.ts +++ b/src/common/__tests__/cluster-store.test.ts @@ -5,7 +5,6 @@ import fs from "fs"; import mockFs from "mock-fs"; -import yaml from "js-yaml"; import path from "path"; import fse from "fs-extra"; import type { Cluster } from "../cluster/cluster"; @@ -334,159 +333,6 @@ users: }); }); - describe("pre 2.0 config with an existing cluster", () => { - beforeEach(() => { - ClusterStore.resetInstance(); - - const mockOpts = { - "some-directory-for-user-data": { - "lens-cluster-store.json": JSON.stringify({ - __internal__: { - migrations: { - version: "1.0.0", - }, - }, - cluster1: minimalValidKubeConfig, - }), - }, - }; - - mockFs(mockOpts); - - clusterStore = mainDi.inject(clusterStoreInjectable); - }); - - afterEach(() => { - mockFs.restore(); - }); - - it("migrates to modern format with kubeconfig in a file", async () => { - const config = clusterStore.clustersList[0].kubeConfigPath; - - expect(fs.readFileSync(config, "utf8")).toContain(`"contexts":[`); - }); - }); - - describe("pre 2.6.0 config with a cluster that has arrays in auth config", () => { - beforeEach(() => { - ClusterStore.resetInstance(); - const mockOpts = { - "some-directory-for-user-data": { - "lens-cluster-store.json": JSON.stringify({ - __internal__: { - migrations: { - version: "2.4.1", - }, - }, - cluster1: { - kubeConfig: JSON.stringify({ - apiVersion: "v1", - clusters: [ - { - cluster: { - server: "https://10.211.55.6:8443", - }, - name: "minikube", - }, - ], - contexts: [ - { - context: { - cluster: "minikube", - user: "minikube", - name: "minikube", - }, - name: "minikube", - }, - ], - "current-context": "minikube", - kind: "Config", - preferences: {}, - users: [ - { - name: "minikube", - user: { - "client-certificate": "/Users/foo/.minikube/client.crt", - "client-key": "/Users/foo/.minikube/client.key", - "auth-provider": { - config: { - "access-token": ["should be string"], - expiry: ["should be string"], - }, - }, - }, - }, - ], - }), - }, - }), - }, - }; - - mockFs(mockOpts); - - clusterStore = mainDi.inject(clusterStoreInjectable); - }); - - afterEach(() => { - mockFs.restore(); - }); - - it("replaces array format access token and expiry into string", async () => { - const file = clusterStore.clustersList[0].kubeConfigPath; - const config = fs.readFileSync(file, "utf8"); - const kc = yaml.load(config) as Record; - - expect(kc.users[0].user["auth-provider"].config["access-token"]).toBe( - "should be string", - ); - expect(kc.users[0].user["auth-provider"].config["expiry"]).toBe( - "should be string", - ); - }); - }); - - describe("pre 2.6.0 config with a cluster icon", () => { - beforeEach(() => { - ClusterStore.resetInstance(); - const mockOpts = { - "some-directory-for-user-data": { - "lens-cluster-store.json": JSON.stringify({ - __internal__: { - migrations: { - version: "2.4.1", - }, - }, - cluster1: { - kubeConfig: minimalValidKubeConfig, - icon: "icon_path", - preferences: { - terminalCWD: "/some-directory-for-user-data", - }, - }, - }), - icon_path: testDataIcon, - }, - }; - - mockFs(mockOpts); - - clusterStore = mainDi.inject(clusterStoreInjectable); - }); - - afterEach(() => { - mockFs.restore(); - }); - - it("moves the icon into preferences", async () => { - const storedClusterData = clusterStore.clustersList[0]; - - expect(Object.prototype.hasOwnProperty.call(storedClusterData, "icon")).toBe(false); - expect(Object.prototype.hasOwnProperty.call(storedClusterData.preferences, "icon")).toBe(true); - expect(storedClusterData.preferences.icon.startsWith("data:;base64,")).toBe(true); - }); - }); - describe("pre 3.6.0-beta.1 config with an existing cluster", () => { beforeEach(() => { ClusterStore.resetInstance(); diff --git a/src/migrations/cluster-store/2.0.0-beta.2.ts b/src/migrations/cluster-store/2.0.0-beta.2.ts deleted file mode 100644 index dafd87bf7f..0000000000 --- a/src/migrations/cluster-store/2.0.0-beta.2.ts +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ - -import type { MigrationDeclaration } from "../helpers"; - -/** - * Early store format had the kubeconfig directly under context name, this moves - * it under the kubeConfig key - */ - -export default { - version: "2.0.0-beta.2", - run(store) { - for (const value of store) { - const contextName = value[0]; - - // Looping all the keys gives out the store internal stuff too... - if (contextName === "__internal__" || Object.prototype.hasOwnProperty.call(value[1], "kubeConfig")) continue; - store.set(contextName, { kubeConfig: value[1] }); - } - }, -} as MigrationDeclaration; diff --git a/src/migrations/cluster-store/2.4.1.ts b/src/migrations/cluster-store/2.4.1.ts deleted file mode 100644 index d53d2536e5..0000000000 --- a/src/migrations/cluster-store/2.4.1.ts +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ - -import type { MigrationDeclaration } from "../helpers"; - -// Cleans up a store that had the state related data stored - -export default { - version: "2.4.1", - run(store) { - 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 || {}}); - } - }, -} as MigrationDeclaration; diff --git a/src/migrations/cluster-store/2.6.0-beta.2.ts b/src/migrations/cluster-store/2.6.0-beta.2.ts deleted file mode 100644 index a91c97a3a7..0000000000 --- a/src/migrations/cluster-store/2.6.0-beta.2.ts +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ - -// Move cluster icon from root to preferences -import type { MigrationDeclaration } from "../helpers"; - -export default { - version: "2.6.0-beta.2", - run(store) { - 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 }); - } - }, -} as MigrationDeclaration; diff --git a/src/migrations/cluster-store/2.6.0-beta.3.ts b/src/migrations/cluster-store/2.6.0-beta.3.ts deleted file mode 100644 index 56d6f39e37..0000000000 --- a/src/migrations/cluster-store/2.6.0-beta.3.ts +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ - -import yaml from "js-yaml"; -import { MigrationDeclaration, migrationLog } from "../helpers"; - -export default { - version: "2.6.0-beta.3", - run(store) { - for (const value of store) { - const clusterKey = value[0]; - - if (clusterKey === "__internal__") continue; - const cluster = value[1]; - - if (!cluster.kubeConfig) continue; - const config = yaml.load(cluster.kubeConfig); - - if (!config || typeof config !== "object" || !Object.prototype.hasOwnProperty.call(config, "users")) { - continue; - } - - const kubeConfig = config as Record; - 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}`; - } - migrationLog(authConfig); - user["auth-provider"].config = authConfig; - kubeConfig.users = [{ - name: userObj.name, - user, - }]; - cluster.kubeConfig = yaml.dump(kubeConfig); - store.set(clusterKey, cluster); - } - } - } - }, -} as MigrationDeclaration; diff --git a/src/migrations/cluster-store/2.7.0-beta.0.ts b/src/migrations/cluster-store/2.7.0-beta.0.ts deleted file mode 100644 index 591ce312f7..0000000000 --- a/src/migrations/cluster-store/2.7.0-beta.0.ts +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ - -// Add existing clusters to "default" workspace -import type { MigrationDeclaration } from "../helpers"; - -export default { - version: "2.7.0-beta.0", - run(store) { - for (const value of store) { - const clusterKey = value[0]; - - if (clusterKey === "__internal__") continue; - const cluster = value[1]; - - cluster.workspace = "default"; - store.set(clusterKey, cluster); - } - }, -} as MigrationDeclaration; diff --git a/src/migrations/cluster-store/2.7.0-beta.1.ts b/src/migrations/cluster-store/2.7.0-beta.1.ts deleted file mode 100644 index 1270c3c712..0000000000 --- a/src/migrations/cluster-store/2.7.0-beta.1.ts +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ - -// Add id for clusters and store them to array -import { v4 as uuid } from "uuid"; -import type { MigrationDeclaration } from "../helpers"; - -export default { - version: "2.7.0-beta.1", - run(store) { - 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); - } - }, -} as MigrationDeclaration; diff --git a/src/migrations/cluster-store/index.ts b/src/migrations/cluster-store/index.ts index 21b3b31e78..4851d01cae 100644 --- a/src/migrations/cluster-store/index.ts +++ b/src/migrations/cluster-store/index.ts @@ -7,24 +7,12 @@ 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"; -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 version500Beta13 from "./5.0.0-beta.13"; import snap from "./snap"; export default joinMigrations( - version200Beta2, - version241, - version260Beta2, - version260Beta3, - version270Beta0, - version270Beta1, version360Beta1, version500Beta10, version500Beta13,