mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Merge remote-tracking branch 'origin/master' into watch-api-fixes
# Conflicts: # src/renderer/components/+namespaces/namespace.store.ts
This commit is contained in:
commit
3394b74f10
28 files changed
+8406
-85
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import requestPromise from "request-promise-native";
|
||||
import packageInfo from "../../../package.json";
|
||||
|
||||
export function getAppVersion(): string {
|
||||
@@ -11,3 +12,13 @@ export function getBundledKubectlVersion(): string {
|
||||
export function getBundledExtensions(): string[] {
|
||||
return packageInfo.lens?.extensions || [];
|
||||
}
|
||||
|
||||
export async function getAppVersionFromProxyServer(proxyPort: number): Promise<string> {
|
||||
const response = await requestPromise({
|
||||
method: "GET",
|
||||
uri: `http://localhost:${proxyPort}/version`,
|
||||
resolveWithFullResponse: true
|
||||
});
|
||||
|
||||
return JSON.parse(response.body).version;
|
||||
}
|
||||
@@ -3,7 +3,18 @@
|
||||
import React from "react";
|
||||
import { BaseRegistry } from "./base-registry";
|
||||
|
||||
export interface StatusBarRegistration {
|
||||
interface StatusBarComponents {
|
||||
Item?: React.ComponentType;
|
||||
}
|
||||
|
||||
interface StatusBarRegistrationV2 {
|
||||
components: StatusBarComponents;
|
||||
}
|
||||
|
||||
export interface StatusBarRegistration extends StatusBarRegistrationV2 {
|
||||
/**
|
||||
* @deprecated use components.Item instead
|
||||
*/
|
||||
item?: React.ReactNode;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import logger from "./logger";
|
||||
|
||||
/**
|
||||
* Installs Electron developer tools in the development build.
|
||||
* The dependency is not bundled to the production build.
|
||||
*/
|
||||
export const installDeveloperTools = async () => {
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
logger.info("🤓 Installing developer tools");
|
||||
const { default: devToolsInstaller, REACT_DEVELOPER_TOOLS } = await import("electron-devtools-installer");
|
||||
|
||||
return devToolsInstaller([REACT_DEVELOPER_TOOLS]);
|
||||
|
||||
@@ -26,6 +26,7 @@ import { InstalledExtension, extensionDiscovery } from "../extensions/extension-
|
||||
import type { LensExtensionId } from "../extensions/lens-extension";
|
||||
import { installDeveloperTools } from "./developer-tools";
|
||||
import { filesystemProvisionerStore } from "./extension-filesystem";
|
||||
import { getAppVersion, getAppVersionFromProxyServer } from "../common/utils";
|
||||
import { bindBroadcastHandlers } from "../common/ipc";
|
||||
|
||||
const workingDir = path.join(app.getPath("appData"), appName);
|
||||
@@ -62,6 +63,7 @@ if (process.env.LENS_DISABLE_GPU) {
|
||||
|
||||
app.on("ready", async () => {
|
||||
logger.info(`🚀 Starting Lens from "${workingDir}"`);
|
||||
logger.info("🐚 Syncing shell environment");
|
||||
await shellSync();
|
||||
|
||||
bindBroadcastHandlers();
|
||||
@@ -70,6 +72,7 @@ app.on("ready", async () => {
|
||||
app.exit();
|
||||
});
|
||||
|
||||
logger.info(`📡 Checking for app updates`);
|
||||
const updater = new AppUpdater();
|
||||
|
||||
updater.start();
|
||||
@@ -78,6 +81,7 @@ app.on("ready", async () => {
|
||||
|
||||
await installDeveloperTools();
|
||||
|
||||
logger.info("💾 Loading stores");
|
||||
// preload
|
||||
await Promise.all([
|
||||
userStore.load(),
|
||||
@@ -89,6 +93,7 @@ app.on("ready", async () => {
|
||||
|
||||
// find free port
|
||||
try {
|
||||
logger.info("🔑 Getting free port for LensProxy server");
|
||||
proxyPort = await getFreePort();
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
@@ -101,6 +106,7 @@ app.on("ready", async () => {
|
||||
|
||||
// run proxy
|
||||
try {
|
||||
logger.info("🔌 Starting LensProxy");
|
||||
// eslint-disable-next-line unused-imports/no-unused-vars-ts
|
||||
proxyServer = LensProxy.create(proxyPort, clusterManager);
|
||||
} catch (error) {
|
||||
@@ -109,10 +115,27 @@ app.on("ready", async () => {
|
||||
app.exit();
|
||||
}
|
||||
|
||||
// test proxy connection
|
||||
try {
|
||||
logger.info("🔎 Testing LensProxy connection ...");
|
||||
const versionFromProxy = await getAppVersionFromProxyServer(proxyPort);
|
||||
|
||||
if (getAppVersion() !== versionFromProxy) {
|
||||
logger.error(`Proxy server responded with invalid response`);
|
||||
}
|
||||
logger.info("⚡ LensProxy connection OK");
|
||||
} catch (error) {
|
||||
logger.error("Checking proxy server connection failed", error);
|
||||
}
|
||||
|
||||
extensionLoader.init();
|
||||
extensionDiscovery.init();
|
||||
|
||||
logger.info("🖥️ Starting WindowManager");
|
||||
windowManager = WindowManager.getInstance<WindowManager>(proxyPort);
|
||||
|
||||
logger.info("🧩 Initializing extensions");
|
||||
|
||||
// call after windowManager to see splash earlier
|
||||
try {
|
||||
const extensions = await extensionDiscovery.load();
|
||||
|
||||
@@ -29,7 +29,7 @@ export class LensProxy {
|
||||
|
||||
listen(port = this.port): this {
|
||||
this.proxyServer = this.buildCustomProxy().listen(port);
|
||||
logger.info(`LensProxy server has started at ${this.origin}`);
|
||||
logger.info(`[LENS-PROXY]: Proxy server has started at ${this.origin}`);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
+2
-1
@@ -5,7 +5,7 @@ import path from "path";
|
||||
import { readFile } from "fs-extra";
|
||||
import { Cluster } from "./cluster";
|
||||
import { apiPrefix, appName, publicPath, isDevelopment, webpackDevServerPort } from "../common/vars";
|
||||
import { helmRoute, kubeconfigRoute, metricsRoute, portForwardRoute, resourceApplierRoute, watchRoute } from "./routes";
|
||||
import { helmRoute, kubeconfigRoute, metricsRoute, portForwardRoute, resourceApplierRoute, watchRoute, versionRoute } from "./routes";
|
||||
import logger from "./logger";
|
||||
|
||||
export interface RouterRequestOpts {
|
||||
@@ -143,6 +143,7 @@ export class Router {
|
||||
this.handleStaticFile(params.path, response, req);
|
||||
});
|
||||
|
||||
this.router.add({ method: "get", path: "/version"}, versionRoute.getVersion.bind(versionRoute));
|
||||
this.router.add({ method: "get", path: `${apiPrefix}/kubeconfig/service-account/{namespace}/{account}` }, kubeconfigRoute.routeServiceAccountRoute.bind(kubeconfigRoute));
|
||||
|
||||
// Watch API
|
||||
|
||||
@@ -4,3 +4,4 @@ export * from "./port-forward-route";
|
||||
export * from "./watch-route";
|
||||
export * from "./helm-route";
|
||||
export * from "./resource-applier-route";
|
||||
export * from "./version-route";
|
||||
@@ -0,0 +1,13 @@
|
||||
import { LensApiRequest } from "../router";
|
||||
import { LensApi } from "../lens-api";
|
||||
import { getAppVersion } from "../../common/utils";
|
||||
|
||||
class VersionRoute extends LensApi {
|
||||
public async getVersion(request: LensApiRequest) {
|
||||
const { response } = request;
|
||||
|
||||
this.respondJson(response, { version: getAppVersion()}, 200);
|
||||
}
|
||||
}
|
||||
|
||||
export const versionRoute = new VersionRoute();
|
||||
@@ -8,6 +8,7 @@ import { initMenu } from "./menu";
|
||||
import { initTray } from "./tray";
|
||||
import { Singleton } from "../common/utils";
|
||||
import { ClusterFrameInfo, clusterFrameMap } from "../common/cluster-frames";
|
||||
import logger from "./logger";
|
||||
|
||||
export class WindowManager extends Singleton {
|
||||
protected mainWindow: BrowserWindow;
|
||||
@@ -81,10 +82,19 @@ export class WindowManager extends Singleton {
|
||||
this.splashWindow = null;
|
||||
app.dock?.hide(); // hide icon in dock (mac-os)
|
||||
});
|
||||
|
||||
this.mainWindow.webContents.on("did-fail-load", (_event, code, desc) => {
|
||||
logger.error(`[WINDOW-MANAGER]: Failed to load Main window`, { code, desc });
|
||||
});
|
||||
|
||||
this.mainWindow.webContents.on("did-finish-load", () => {
|
||||
logger.info("[WINDOW-MANAGER]: Main window loaded");
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
if (showSplash) await this.showSplash();
|
||||
logger.info(`[WINDOW-MANAGER]: Loading Main window from url: ${this.mainUrl} ...`);
|
||||
await this.mainWindow.loadURL(this.mainUrl);
|
||||
this.mainWindow.show();
|
||||
this.splashWindow?.close();
|
||||
|
||||
@@ -71,6 +71,7 @@ export class KubeWatchApi {
|
||||
return [];
|
||||
}
|
||||
|
||||
// TODO: optimize - check when all namespaces are selected and then request all in one
|
||||
if (api.isNamespaced && !this.cluster.isGlobalWatchEnabled) {
|
||||
return this.namespaces.map(namespace => api.getWatchUrl(namespace));
|
||||
}
|
||||
|
||||
@@ -85,10 +85,9 @@ export class NamespaceSelectFilter extends React.Component {
|
||||
const namespaces = namespaceStore.getContextNamespaces();
|
||||
|
||||
switch (namespaces.length) {
|
||||
case 0:
|
||||
case namespaceStore.allowedNamespaces.length:
|
||||
return <>All namespaces</>;
|
||||
case 0:
|
||||
return <>Select a namespace</>;
|
||||
case 1:
|
||||
return <>Namespace: {namespaces[0]}</>;
|
||||
default:
|
||||
@@ -116,7 +115,7 @@ export class NamespaceSelectFilter extends React.Component {
|
||||
if (namespace) {
|
||||
namespaceStore.toggleContext(namespace);
|
||||
} else {
|
||||
namespaceStore.toggleAll(); // "All namespaces" option clicked
|
||||
namespaceStore.resetContext(); // "All namespaces" clicked, empty list considered as "all"
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -14,14 +14,19 @@ describe("<BottomBar />", () => {
|
||||
expect(container).toBeInstanceOf(HTMLElement);
|
||||
});
|
||||
|
||||
// some defensive testing
|
||||
it("renders w/o errors when .getItems() returns edge cases", async () => {
|
||||
it("renders w/o errors when .getItems() returns unexpected (not type complient) data", async () => {
|
||||
statusBarRegistry.getItems = jest.fn().mockImplementationOnce(() => undefined);
|
||||
expect(() => render(<BottomBar />)).not.toThrow();
|
||||
statusBarRegistry.getItems = jest.fn().mockImplementationOnce(() => "hello");
|
||||
expect(() => render(<BottomBar />)).not.toThrow();
|
||||
statusBarRegistry.getItems = jest.fn().mockImplementationOnce(() => 6);
|
||||
expect(() => render(<BottomBar />)).not.toThrow();
|
||||
statusBarRegistry.getItems = jest.fn().mockImplementationOnce(() => null);
|
||||
expect(() => render(<BottomBar />)).not.toThrow();
|
||||
statusBarRegistry.getItems = jest.fn().mockImplementationOnce(() => []);
|
||||
expect(() => render(<BottomBar />)).not.toThrow();
|
||||
statusBarRegistry.getItems = jest.fn().mockImplementationOnce(() => [{}]);
|
||||
expect(() => render(<BottomBar />)).not.toThrow();
|
||||
statusBarRegistry.getItems = jest.fn().mockImplementationOnce(() => { return {};});
|
||||
expect(() => render(<BottomBar />)).not.toThrow();
|
||||
});
|
||||
|
||||
@@ -4,16 +4,48 @@ import React from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import { Icon } from "../icon";
|
||||
import { workspaceStore } from "../../../common/workspace-store";
|
||||
import { statusBarRegistry } from "../../../extensions/registries";
|
||||
import { StatusBarRegistration, statusBarRegistry } from "../../../extensions/registries";
|
||||
import { CommandOverlay } from "../command-palette/command-container";
|
||||
import { ChooseWorkspace } from "../+workspaces";
|
||||
|
||||
@observer
|
||||
export class BottomBar extends React.Component {
|
||||
renderRegisteredItem(registration: StatusBarRegistration) {
|
||||
const { item } = registration;
|
||||
|
||||
if (item) {
|
||||
return typeof item === "function" ? item() : item;
|
||||
}
|
||||
|
||||
return <registration.components.Item />;
|
||||
}
|
||||
|
||||
renderRegisteredItems() {
|
||||
const items = statusBarRegistry.getItems();
|
||||
|
||||
if (!Array.isArray(items)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="extensions box grow flex gaps justify-flex-end">
|
||||
{items.map((registration, index) => {
|
||||
if (!registration?.item && !registration?.components?.Item) {
|
||||
return;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex align-center gaps item" key={index}>
|
||||
{this.renderRegisteredItem(registration)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { currentWorkspace } = workspaceStore;
|
||||
// in case .getItems() returns undefined
|
||||
const items = statusBarRegistry.getItems() ?? [];
|
||||
|
||||
return (
|
||||
<div className="BottomBar flex gaps">
|
||||
@@ -21,20 +53,7 @@ export class BottomBar extends React.Component {
|
||||
<Icon smallest material="layers"/>
|
||||
<span className="workspace-name" data-test-id="current-workspace-name">{currentWorkspace.name}</span>
|
||||
</div>
|
||||
<div className="extensions box grow flex gaps justify-flex-end">
|
||||
{Array.isArray(items) && items.map(({ item }, index) => {
|
||||
if (!item) return;
|
||||
|
||||
return (
|
||||
<div
|
||||
className="flex align-center gaps item"
|
||||
key={index}
|
||||
>
|
||||
{typeof item === "function" ? item() : item}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{this.renderRegisteredItems()}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user