mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Automatically sync all kubeConfigPaths (#3227)
This commit is contained in:
parent
fe443f462b
commit
497e47b277
@ -1,25 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "kube-object-event-status",
|
|
||||||
"version": "0.1.0",
|
|
||||||
"description": "Adds kube object status from events",
|
|
||||||
"renderer": "dist/renderer.js",
|
|
||||||
"lens": {
|
|
||||||
"metadata": {},
|
|
||||||
"styles": []
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"build": "webpack && npm pack",
|
|
||||||
"dev": "webpack --watch",
|
|
||||||
"test": "echo NO TESTS"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"dist/**/*"
|
|
||||||
],
|
|
||||||
"dependencies": {},
|
|
||||||
"devDependencies": {
|
|
||||||
"@k8slens/extensions": "file:../../src/extensions/npm/extensions",
|
|
||||||
"ts-loader": "^8.0.4",
|
|
||||||
"typescript": "^4.0.3",
|
|
||||||
"webpack": "^4.44.2"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -3,7 +3,7 @@
|
|||||||
"productName": "OpenLens",
|
"productName": "OpenLens",
|
||||||
"description": "OpenLens - Open Source IDE for Kubernetes",
|
"description": "OpenLens - Open Source IDE for Kubernetes",
|
||||||
"homepage": "https://github.com/lensapp/lens",
|
"homepage": "https://github.com/lensapp/lens",
|
||||||
"version": "5.0.2",
|
"version": "5.0.3-beta.1",
|
||||||
"main": "static/build/main.js",
|
"main": "static/build/main.js",
|
||||||
"copyright": "© 2021 OpenLens Authors",
|
"copyright": "© 2021 OpenLens Authors",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@ -20,4 +20,4 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export * from "./user-store";
|
export * from "./user-store";
|
||||||
export type { KubeconfigSyncEntry, KubeconfigSyncValue } from "./preferences-helpers";
|
export type { KubeconfigSyncEntry, KubeconfigSyncValue, UserPreferencesModel } from "./preferences-helpers";
|
||||||
|
|||||||
@ -31,6 +31,7 @@ import path from "path";
|
|||||||
import { fileNameMigration } from "../../migrations/user-store";
|
import { fileNameMigration } from "../../migrations/user-store";
|
||||||
import { ObservableToggleSet, toJS } from "../../renderer/utils";
|
import { ObservableToggleSet, toJS } from "../../renderer/utils";
|
||||||
import { DESCRIPTORS, KubeconfigSyncValue, UserPreferencesModel } from "./preferences-helpers";
|
import { DESCRIPTORS, KubeconfigSyncValue, UserPreferencesModel } from "./preferences-helpers";
|
||||||
|
import logger from "../../main/logger";
|
||||||
|
|
||||||
export interface UserStoreModel {
|
export interface UserStoreModel {
|
||||||
lastSeenAppVersion: string;
|
lastSeenAppVersion: string;
|
||||||
@ -155,8 +156,8 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
|
|||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
protected fromStore(data: Partial<UserStoreModel> = {}) {
|
protected fromStore({ lastSeenAppVersion, preferences }: Partial<UserStoreModel> = {}) {
|
||||||
const { lastSeenAppVersion, preferences } = data;
|
logger.debug("UserStore.fromStore()", { lastSeenAppVersion, preferences });
|
||||||
|
|
||||||
if (lastSeenAppVersion) {
|
if (lastSeenAppVersion) {
|
||||||
this.lastSeenAppVersion = lastSeenAppVersion;
|
this.lastSeenAppVersion = lastSeenAppVersion;
|
||||||
|
|||||||
@ -138,8 +138,8 @@ app.on("ready", async () => {
|
|||||||
|
|
||||||
logger.info("💾 Loading stores");
|
logger.info("💾 Loading stores");
|
||||||
|
|
||||||
UserStore.createInstance().startMainReactions();
|
|
||||||
ClusterStore.createInstance().provideInitialFromMain();
|
ClusterStore.createInstance().provideInitialFromMain();
|
||||||
|
UserStore.createInstance().startMainReactions();
|
||||||
HotbarStore.createInstance();
|
HotbarStore.createInstance();
|
||||||
ExtensionsStore.createInstance();
|
ExtensionsStore.createInstance();
|
||||||
FilesystemProvisionerStore.createInstance();
|
FilesystemProvisionerStore.createInstance();
|
||||||
|
|||||||
@ -148,8 +148,8 @@ export default {
|
|||||||
|
|
||||||
store.set("hotbars", hotbars);
|
store.set("hotbars", hotbars);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (!(error.code === "ENOENT" && error.path.endsWith("lens-workspace-store.json"))) {
|
if (error.code !== "ENOENT") {
|
||||||
// ignore lens-workspace-store.json being missing
|
// ignore files being missing
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
75
src/migrations/user-store/5.0.3-beta.1.ts
Normal file
75
src/migrations/user-store/5.0.3-beta.1.ts
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/**
|
||||||
|
* 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 { app } from "electron";
|
||||||
|
import { existsSync, readJsonSync } from "fs-extra";
|
||||||
|
import path from "path";
|
||||||
|
import os from "os";
|
||||||
|
import { ClusterStore, ClusterStoreModel } from "../../common/cluster-store";
|
||||||
|
import type { KubeconfigSyncEntry, UserPreferencesModel } from "../../common/user-store";
|
||||||
|
import { MigrationDeclaration, migrationLog } from "../helpers";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
version: "5.0.3-beta.1",
|
||||||
|
run(store) {
|
||||||
|
try {
|
||||||
|
const { syncKubeconfigEntries = [], ...preferences }: UserPreferencesModel = store.get("preferences") ?? {};
|
||||||
|
const { clusters = [] }: ClusterStoreModel = readJsonSync(path.resolve(app.getPath("userData"), "lens-cluster-store.json")) ?? {};
|
||||||
|
const syncPaths = new Set(syncKubeconfigEntries.map(s => s.filePath));
|
||||||
|
|
||||||
|
syncPaths.add(path.join(os.homedir(), ".kube"));
|
||||||
|
|
||||||
|
for (const cluster of clusters) {
|
||||||
|
const dirOfKubeconfig = path.dirname(cluster.kubeConfigPath);
|
||||||
|
|
||||||
|
if (dirOfKubeconfig === ClusterStore.storedKubeConfigFolder) {
|
||||||
|
migrationLog(`Skipping ${cluster.id} because kubeConfigPath is under ClusterStore.storedKubeConfigFolder`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (syncPaths.has(cluster.kubeConfigPath) || syncPaths.has(dirOfKubeconfig)) {
|
||||||
|
migrationLog(`Skipping ${cluster.id} because kubeConfigPath is already being synced`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!existsSync(cluster.kubeConfigPath)) {
|
||||||
|
migrationLog(`Skipping ${cluster.id} because kubeConfigPath no longer exists`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
migrationLog(`Adding ${cluster.kubeConfigPath} from ${cluster.id} to sync paths`);
|
||||||
|
syncPaths.add(cluster.kubeConfigPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedSyncEntries: KubeconfigSyncEntry[] = [...syncPaths].map(filePath => ({ filePath }));
|
||||||
|
|
||||||
|
migrationLog("Final list of synced paths", updatedSyncEntries);
|
||||||
|
store.set("preferences", { ...preferences, syncKubeconfigEntries: updatedSyncEntries });
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
|
||||||
|
if (error.code !== "ENOENT") {
|
||||||
|
// ignore files being missing
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
} as MigrationDeclaration;
|
||||||
@ -25,6 +25,7 @@ import { joinMigrations } from "../helpers";
|
|||||||
|
|
||||||
import version210Beta4 from "./2.1.0-beta.4";
|
import version210Beta4 from "./2.1.0-beta.4";
|
||||||
import version500Alpha3 from "./5.0.0-alpha.3";
|
import version500Alpha3 from "./5.0.0-alpha.3";
|
||||||
|
import version503Beta1 from "./5.0.3-beta.1";
|
||||||
import { fileNameMigration } from "./file-name-migration";
|
import { fileNameMigration } from "./file-name-migration";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@ -34,4 +35,5 @@ export {
|
|||||||
export default joinMigrations(
|
export default joinMigrations(
|
||||||
version210Beta4,
|
version210Beta4,
|
||||||
version500Alpha3,
|
version500Alpha3,
|
||||||
|
version503Beta1,
|
||||||
);
|
);
|
||||||
|
|||||||
@ -59,14 +59,7 @@ describe("Extensions", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ExtensionInstallationStateStore.reset();
|
ExtensionInstallationStateStore.reset();
|
||||||
UserStore.resetInstance();
|
|
||||||
|
|
||||||
UserStore.createInstance();
|
|
||||||
|
|
||||||
ExtensionDiscovery.resetInstance();
|
|
||||||
ExtensionDiscovery.createInstance().uninstallExtension = jest.fn(() => Promise.resolve());
|
|
||||||
|
|
||||||
ExtensionLoader.resetInstance();
|
|
||||||
ExtensionLoader.createInstance().addExtension({
|
ExtensionLoader.createInstance().addExtension({
|
||||||
id: "extensionId",
|
id: "extensionId",
|
||||||
manifest: {
|
manifest: {
|
||||||
@ -79,10 +72,15 @@ describe("Extensions", () => {
|
|||||||
isEnabled: true,
|
isEnabled: true,
|
||||||
isCompatible: true
|
isCompatible: true
|
||||||
});
|
});
|
||||||
|
ExtensionDiscovery.createInstance().uninstallExtension = jest.fn(() => Promise.resolve());
|
||||||
|
UserStore.createInstance();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
mockFs.restore();
|
mockFs.restore();
|
||||||
|
UserStore.resetInstance();
|
||||||
|
ExtensionDiscovery.resetInstance();
|
||||||
|
ExtensionLoader.resetInstance();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("disables uninstall and disable buttons while uninstalling", async () => {
|
it("disables uninstall and disable buttons while uninstalling", async () => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user