1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Refactor cluster settings to catalog entity settings (#2525)

* fix cluster settings page layout

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* cleanup

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* refactor cluster settings to pluggable entity settings

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* fix

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* fix

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* fix gh actions network timeout on yarn install

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* review changes

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2021-04-20 07:05:44 +03:00 committed by GitHub
parent adec401acd
commit 8dde4a1ecb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
51 changed files with 437 additions and 336 deletions

View File

@ -50,7 +50,7 @@ export class KubernetesCluster implements CatalogEntity {
icon: "settings", icon: "settings",
title: "Settings", title: "Settings",
onlyVisibleForSource: "local", onlyVisibleForSource: "local",
onClick: async () => context.navigate(`/cluster/${this.metadata.uid}/settings`) onClick: async () => context.navigate(`/entity/${this.metadata.uid}/settings`)
}, },
{ {
icon: "delete", icon: "delete",

View File

@ -52,11 +52,23 @@ export type CatalogEntityContextMenu = {
} }
}; };
export type CatalogEntitySettingsMenu = {
group?: string;
title: string;
components: {
View: React.ComponentType<any>
};
};
export interface CatalogEntityContextMenuContext { export interface CatalogEntityContextMenuContext {
navigate: (url: string) => void; navigate: (url: string) => void;
menuItems: CatalogEntityContextMenu[]; menuItems: CatalogEntityContextMenu[];
} }
export interface CatalogEntitySettingsContext {
menuItems: CatalogEntityContextMenu[];
}
export interface CatalogEntityAddMenuContext { export interface CatalogEntityAddMenuContext {
navigate: (url: string) => void; navigate: (url: string) => void;
menuItems: CatalogEntityContextMenu[]; menuItems: CatalogEntityContextMenu[];
@ -78,4 +90,5 @@ export interface CatalogEntity extends CatalogEntityData {
onRun: (context: CatalogEntityActionContext) => Promise<void>; onRun: (context: CatalogEntityActionContext) => Promise<void>;
onDetailsOpen: (context: CatalogEntityActionContext) => Promise<void>; onDetailsOpen: (context: CatalogEntityActionContext) => Promise<void>;
onContextMenuOpen: (context: CatalogEntityContextMenuContext) => Promise<void>; onContextMenuOpen: (context: CatalogEntityContextMenuContext) => Promise<void>;
onSettingsOpen?: (context: CatalogEntitySettingsContext) => Promise<void>;
} }

View File

@ -11,7 +11,7 @@ import { dumpConfigYaml } from "./kube-helpers";
import { saveToAppFiles } from "./utils/saveToAppFiles"; import { saveToAppFiles } from "./utils/saveToAppFiles";
import { KubeConfig } from "@kubernetes/client-node"; import { KubeConfig } from "@kubernetes/client-node";
import { handleRequest, requestMain, subscribeToBroadcast, unsubscribeAllFromBroadcast } from "./ipc"; import { handleRequest, requestMain, subscribeToBroadcast, unsubscribeAllFromBroadcast } from "./ipc";
import { ResourceType } from "../renderer/components/+cluster-settings/components/cluster-metrics-setting"; import { ResourceType } from "../renderer/components/cluster-settings/components/cluster-metrics-setting";
export interface ClusterIconUpload { export interface ClusterIconUpload {
clusterId: string; clusterId: string;

View File

@ -211,8 +211,8 @@ export class ExtensionLoader {
this.autoInitExtensions(async (extension: LensRendererExtension) => { this.autoInitExtensions(async (extension: LensRendererExtension) => {
const removeItems = [ const removeItems = [
registries.globalPageRegistry.add(extension.globalPages, extension), registries.globalPageRegistry.add(extension.globalPages, extension),
registries.globalPageMenuRegistry.add(extension.globalPageMenus, extension),
registries.appPreferenceRegistry.add(extension.appPreferences), registries.appPreferenceRegistry.add(extension.appPreferences),
registries.entitySettingRegistry.add(extension.entitySettings),
registries.statusBarRegistry.add(extension.statusBarItems), registries.statusBarRegistry.add(extension.statusBarItems),
registries.commandRegistry.add(extension.commands), registries.commandRegistry.add(extension.commands),
]; ];

View File

@ -3,6 +3,7 @@ import type { Cluster } from "../main/cluster";
import { LensExtension } from "./lens-extension"; import { LensExtension } from "./lens-extension";
import { getExtensionPageUrl } from "./registries/page-registry"; import { getExtensionPageUrl } from "./registries/page-registry";
import { CommandRegistration } from "./registries/command-registry"; import { CommandRegistration } from "./registries/command-registry";
import { EntitySettingRegistration } from "./registries/entity-setting-registry";
export class LensRendererExtension extends LensExtension { export class LensRendererExtension extends LensExtension {
globalPages: PageRegistration[] = []; globalPages: PageRegistration[] = [];
@ -11,6 +12,7 @@ export class LensRendererExtension extends LensExtension {
clusterPageMenus: ClusterPageMenuRegistration[] = []; clusterPageMenus: ClusterPageMenuRegistration[] = [];
kubeObjectStatusTexts: KubeObjectStatusRegistration[] = []; kubeObjectStatusTexts: KubeObjectStatusRegistration[] = [];
appPreferences: AppPreferenceRegistration[] = []; appPreferences: AppPreferenceRegistration[] = [];
entitySettings: EntitySettingRegistration[] = [];
statusBarItems: StatusBarRegistration[] = []; statusBarItems: StatusBarRegistration[] = [];
kubeObjectDetailItems: KubeObjectDetailRegistration[] = []; kubeObjectDetailItems: KubeObjectDetailRegistration[] = [];
kubeObjectMenuItems: KubeObjectMenuRegistration[] = []; kubeObjectMenuItems: KubeObjectMenuRegistration[] = [];

View File

@ -0,0 +1,49 @@
import type React from "react";
import { CatalogEntity } from "../../common/catalog-entity";
import { BaseRegistry } from "./base-registry";
export interface EntitySettingViewProps {
entity: CatalogEntity;
}
export interface EntitySettingComponents {
View: React.ComponentType<EntitySettingViewProps>;
}
export interface EntitySettingRegistration {
title: string;
kind: string;
apiVersions: string[];
source?: string;
id?: string;
components: EntitySettingComponents;
}
export interface RegisteredEntitySetting extends EntitySettingRegistration {
id: string;
}
export class EntitySettingRegistry extends BaseRegistry<EntitySettingRegistration, RegisteredEntitySetting> {
getRegisteredItem(item: EntitySettingRegistration): RegisteredEntitySetting {
return {
id: item.id || item.title.toLowerCase(),
...item,
};
}
getItemsForKind(kind: string, apiVersion: string, source?: string) {
const items = this.getItems().filter((item) => {
return item.kind === kind && item.apiVersions.includes(apiVersion);
});
if (source) {
return items.filter((item) => {
return !item.source || item.source === source;
});
} else {
return items;
}
}
}
export const entitySettingRegistry = new EntitySettingRegistry();

View File

@ -9,3 +9,4 @@ export * from "./kube-object-detail-registry";
export * from "./kube-object-menu-registry"; export * from "./kube-object-menu-registry";
export * from "./kube-object-status-registry"; export * from "./kube-object-status-registry";
export * from "./command-registry"; export * from "./command-registry";
export * from "./entity-setting-registry";

View File

@ -57,5 +57,4 @@ export class ClusterPageMenuRegistry extends PageMenuRegistry<ClusterPageMenuReg
} }
} }
export const globalPageMenuRegistry = new PageMenuRegistry();
export const clusterPageMenuRegistry = new ClusterPageMenuRegistry(); export const clusterPageMenuRegistry = new ClusterPageMenuRegistry();

View File

@ -5,7 +5,6 @@ import { appName, isMac, isWindows, isTestEnv, docsUrl, supportUrl } from "../co
import { addClusterURL } from "../renderer/components/+add-cluster/add-cluster.route"; import { addClusterURL } from "../renderer/components/+add-cluster/add-cluster.route";
import { preferencesURL } from "../renderer/components/+preferences/preferences.route"; import { preferencesURL } from "../renderer/components/+preferences/preferences.route";
import { whatsNewURL } from "../renderer/components/+whats-new/whats-new.route"; import { whatsNewURL } from "../renderer/components/+whats-new/whats-new.route";
import { clusterSettingsURL } from "../renderer/components/+cluster-settings/cluster-settings.route";
import { extensionsURL } from "../renderer/components/+extensions/extensions.route"; import { extensionsURL } from "../renderer/components/+extensions/extensions.route";
import { catalogURL } from "../renderer/components/+catalog/catalog.route"; import { catalogURL } from "../renderer/components/+catalog/catalog.route";
import { menuRegistry } from "../extensions/registries/menu-registry"; import { menuRegistry } from "../extensions/registries/menu-registry";
@ -47,16 +46,6 @@ export function buildMenu(windowManager: WindowManager) {
return menuItems; return menuItems;
} }
function activeClusterOnly(menuItems: MenuItemConstructorOptions[]) {
if (!windowManager.activeClusterId) {
menuItems.forEach(item => {
item.enabled = false;
});
}
return menuItems;
}
async function navigate(url: string) { async function navigate(url: string) {
logger.info(`[MENU]: navigating to ${url}`); logger.info(`[MENU]: navigating to ${url}`);
await windowManager.navigate(url); await windowManager.navigate(url);
@ -112,19 +101,6 @@ export function buildMenu(windowManager: WindowManager) {
navigate(addClusterURL()); navigate(addClusterURL());
} }
}, },
...activeClusterOnly([
{
label: "Cluster Settings",
accelerator: "CmdOrCtrl+Shift+S",
click() {
navigate(clusterSettingsURL({
params: {
clusterId: windowManager.activeClusterId
}
}));
}
}
]),
...ignoreOnMac([ ...ignoreOnMac([
{ type: "separator" }, { type: "separator" },
{ {

View File

@ -44,6 +44,10 @@ export class CatalogEntityRegistry {
return this._items; return this._items;
} }
getById(id: string) {
return this._items.find((entity) => entity.metadata.uid === id);
}
getItemsForApiKind<T extends CatalogEntity>(apiVersion: string, kind: string): T[] { getItemsForApiKind<T extends CatalogEntity>(apiVersion: string, kind: string): T[] {
const items = this._items.filter((item) => item.apiVersion === apiVersion && item.kind === kind); const items = this._items.filter((item) => item.apiVersion === apiVersion && item.kind === kind);

View File

@ -345,7 +345,7 @@ export class AddCluster extends React.Component {
return ( return (
<DropFileInput onDropFiles={this.onDropKubeConfig}> <DropFileInput onDropFiles={this.onDropKubeConfig}>
<PageLayout className="AddClusters" header={<><Icon svg="logo-lens" big /> <h2>Add Clusters</h2></>} showOnTop={true}> <PageLayout className="AddClusters" showOnTop={true}>
<h2>Add Clusters from Kubeconfig</h2> <h2>Add Clusters from Kubeconfig</h2>
{this.renderInfo()} {this.renderInfo()}
{this.renderKubeConfigSource()} {this.renderKubeConfigSource()}

View File

@ -1,12 +0,0 @@
import type { IClusterViewRouteParams } from "../cluster-manager/cluster-view.route";
import type { RouteProps } from "react-router";
import { buildURL } from "../../../common/utils/buildUrl";
export interface IClusterSettingsRouteParams extends IClusterViewRouteParams {
}
export const clusterSettingsRoute: RouteProps = {
path: `/cluster/:clusterId/settings`,
};
export const clusterSettingsURL = buildURL<IClusterSettingsRouteParams>(clusterSettingsRoute.path);

View File

@ -1,51 +0,0 @@
.ClusterSettings {
$spacing: $padding * 3;
> .content-wrapper {
--flex-gap: #{$spacing};
}
// TODO: move sub-component styles to separate files
.admin-note {
font-size: small;
opacity: 0.5;
margin-left: $margin;
}
.button-area {
margin-top: $margin * 2;
}
.file-loader {
margin-top: $margin * 2;
}
.status-table {
margin: $spacing 0;
.Table {
border: 1px solid var(--drawerSubtitleBackground);
border-radius: $radius;
.TableRow {
&:not(:last-of-type) {
border-bottom: 1px solid var(--drawerSubtitleBackground);
}
.value {
flex-grow: 2;
word-break: break-word;
color: var(--textColorSecondary);
}
.link {
@include pseudo-link;
}
}
}
}
.Input, .Select {
margin-top: $padding;
}
}

View File

@ -1,69 +0,0 @@
import "./cluster-settings.scss";
import React from "react";
import { reaction } from "mobx";
import { RouteComponentProps } from "react-router";
import { observer, disposeOnUnmount } from "mobx-react";
import { Status } from "./status";
import { General } from "./general";
import { Cluster } from "../../../main/cluster";
import { IClusterSettingsRouteParams } from "./cluster-settings.route";
import { clusterStore } from "../../../common/cluster-store";
import { PageLayout } from "../layout/page-layout";
import { requestMain } from "../../../common/ipc";
import { clusterActivateHandler, clusterRefreshHandler } from "../../../common/cluster-ipc";
import { navigation } from "../../navigation";
interface Props extends RouteComponentProps<IClusterSettingsRouteParams> {
}
@observer
export class ClusterSettings extends React.Component<Props> {
get clusterId() {
return this.props.match.params.clusterId;
}
get cluster(): Cluster {
return clusterStore.getById(this.clusterId);
}
componentDidMount() {
const { hash } = navigation.location;
document.getElementById(hash.slice(1))?.scrollIntoView();
disposeOnUnmount(this, [
reaction(() => this.cluster, this.refreshCluster, {
fireImmediately: true,
}),
reaction(() => this.clusterId, clusterId => clusterStore.setActive(clusterId), {
fireImmediately: true,
})
]);
}
refreshCluster = async () => {
if (this.cluster) {
await requestMain(clusterActivateHandler, this.cluster.id);
await requestMain(clusterRefreshHandler, this.cluster.id);
}
};
render() {
const cluster = this.cluster;
if (!cluster) return null;
const header = (
<>
<h2>{cluster.preferences.clusterName}</h2>
</>
);
return (
<PageLayout className="ClusterSettings" header={header} showOnTop={true}>
<Status cluster={cluster}></Status>
<General cluster={cluster}></General>
</PageLayout>
);
}
}

View File

@ -1,28 +0,0 @@
import React from "react";
import { Cluster } from "../../../main/cluster";
import { ClusterNameSetting } from "./components/cluster-name-setting";
import { ClusterProxySetting } from "./components/cluster-proxy-setting";
import { ClusterPrometheusSetting } from "./components/cluster-prometheus-setting";
import { ClusterHomeDirSetting } from "./components/cluster-home-dir-setting";
import { ClusterAccessibleNamespaces } from "./components/cluster-accessible-namespaces";
import { ClusterMetricsSetting } from "./components/cluster-metrics-setting";
import { ShowMetricsSetting } from "./components/show-metrics";
interface Props {
cluster: Cluster;
}
export class General extends React.Component<Props> {
render() {
return <div>
<h2>General</h2>
<ClusterNameSetting cluster={this.props.cluster} />
<ClusterProxySetting cluster={this.props.cluster} />
<ClusterPrometheusSetting cluster={this.props.cluster} />
<ClusterHomeDirSetting cluster={this.props.cluster} />
<ClusterAccessibleNamespaces cluster={this.props.cluster} />
<ClusterMetricsSetting cluster={this.props.cluster}/>
<ShowMetricsSetting cluster={this.props.cluster}/>
</div>;
}
}

View File

@ -1,61 +0,0 @@
import React from "react";
import { Cluster } from "../../../main/cluster";
import { SubTitle } from "../layout/sub-title";
import { Table, TableCell, TableRow } from "../table";
import { autobind } from "../../utils";
import { shell } from "electron";
interface Props {
cluster: Cluster;
}
export class Status extends React.Component<Props> {
@autobind()
openKubeconfig() {
const { cluster } = this.props;
shell.showItemInFolder(cluster.kubeConfigPath);
}
renderStatusRows() {
const { cluster } = this.props;
const rows = [
["Online Status", cluster.online ? "online" : `offline (${cluster.failureReason || "unknown reason"})`],
["Distribution", cluster.metadata.distribution ? String(cluster.metadata.distribution) : "N/A"],
["Kernel Version", cluster.metadata.version ? String(cluster.metadata.version) : "N/A"],
["API Address", cluster.apiUrl || "N/A"],
["Nodes Count", cluster.metadata.nodes ? String(cluster.metadata.nodes) : "N/A"]
];
return (
<Table scrollable={false}>
{rows.map(([name, value]) => {
return (
<TableRow key={name}>
<TableCell>{name}</TableCell>
<TableCell className="value">{value}</TableCell>
</TableRow>
);
})}
<TableRow>
<TableCell>Kubeconfig</TableCell>
<TableCell className="link value" onClick={this.openKubeconfig}>{cluster.kubeConfigPath}</TableCell>
</TableRow>
</Table>
);
}
render() {
return <div>
<h2>Status</h2>
<SubTitle title="Cluster Status"/>
<p>
Cluster status information including: detected distribution, kernel version, and online status.
</p>
<div className="status-table">
{this.renderStatusRows()}
</div>
</div>;
}
}

View File

@ -13,7 +13,7 @@ import { ClusterIssues } from "./cluster-issues";
import { ClusterMetrics } from "./cluster-metrics"; import { ClusterMetrics } from "./cluster-metrics";
import { clusterOverviewStore } from "./cluster-overview.store"; import { clusterOverviewStore } from "./cluster-overview.store";
import { ClusterPieCharts } from "./cluster-pie-charts"; import { ClusterPieCharts } from "./cluster-pie-charts";
import { ResourceType } from "../+cluster-settings/components/cluster-metrics-setting"; import { ResourceType } from "../cluster-settings/components/cluster-metrics-setting";
@observer @observer
export class ClusterOverview extends React.Component { export class ClusterOverview extends React.Component {

View File

@ -0,0 +1,12 @@
import type { RouteProps } from "react-router";
import { buildURL } from "../../../common/utils/buildUrl";
export interface EntitySettingsRouteParams {
entityId: string;
}
export const entitySettingsRoute: RouteProps = {
path: `/entity/:entityId/settings`,
};
export const entitySettingsURL = buildURL<EntitySettingsRouteParams>(entitySettingsRoute.path);

View File

@ -0,0 +1,23 @@
.EntitySettings {
$spacing: $padding * 3;
// TODO: move sub-component styles to separate files
.admin-note {
font-size: small;
opacity: 0.5;
margin-left: $margin;
}
.button-area {
margin-top: $margin * 2;
}
.file-loader {
margin-top: $margin * 2;
}
.Input, .Select {
margin-top: $padding;
}
}

View File

@ -0,0 +1,99 @@
import "./entity-settings.scss";
import React from "react";
import { observable } from "mobx";
import { RouteComponentProps } from "react-router";
import { observer } from "mobx-react";
import { PageLayout } from "../layout/page-layout";
import { navigation } from "../../navigation";
import { Tabs, Tab } from "../tabs";
import { CatalogEntity } from "../../api/catalog-entity";
import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
import { entitySettingRegistry } from "../../../extensions/registries";
import { EntitySettingsRouteParams } from "./entity-settings.route";
interface Props extends RouteComponentProps<EntitySettingsRouteParams> {
}
@observer
export class EntitySettings extends React.Component<Props> {
@observable activeTab: string;
get entityId() {
return this.props.match.params.entityId;
}
get entity(): CatalogEntity {
return catalogEntityRegistry.getById(this.entityId);
}
get menuItems() {
if (!this.entity) return [];
return entitySettingRegistry.getItemsForKind(this.entity.kind, this.entity.apiVersion, this.entity.metadata.source);
}
async componentDidMount() {
const { hash } = navigation.location;
this.ensureActiveTab();
document.getElementById(hash.slice(1))?.scrollIntoView();
}
onTabChange = (tabId: string) => {
this.activeTab = tabId;
};
renderNavigation() {
return (
<>
<h2>{this.entity.metadata.name}</h2>
<Tabs className="flex column" scrollable={false} onChange={this.onTabChange} value={this.activeTab}>
<div className="header">Settings</div>
{ this.menuItems.map((setting) => (
<Tab
key={setting.id}
value={setting.id}
label={setting.title}
data-testid={`${setting.id}-tab`}
/>
))}
</Tabs>
</>
);
}
ensureActiveTab() {
if (!this.activeTab) {
this.activeTab = this.menuItems[0]?.id;
}
}
render() {
if (!this.entity) {
console.error("entity not found", this.entityId);
return null;
}
this.ensureActiveTab();
const activeSetting = this.menuItems.find((setting) => setting.id === this.activeTab);
return (
<PageLayout
className="CatalogEntitySettings"
navigation={this.renderNavigation()}
showOnTop={true}
contentGaps={false}
>
<section>
<h2 data-testid={`${activeSetting.id}-header`}>{activeSetting.title}</h2>
<section>
<activeSetting.components.View entity={this.entity} />
</section>
</section>
</PageLayout>
);
}
}

View File

@ -0,0 +1,4 @@
import "../cluster-settings";
export * from "./entity-settings.route";
export * from "./entity-settings";

View File

@ -482,12 +482,11 @@ export class Extensions extends React.Component {
} }
render() { render() {
const topHeader = <h2>Manage Lens Extensions</h2>;
const { installPath } = this; const { installPath } = this;
return ( return (
<DropFileInput onDropFiles={this.installOnDrop}> <DropFileInput onDropFiles={this.installOnDrop}>
<PageLayout showOnTop className="Extensions" header={topHeader} contentGaps={false}> <PageLayout showOnTop className="Extensions" contentGaps={false}>
<h2>Lens Extensions</h2> <h2>Lens Extensions</h2>
<div> <div>
Add new features and functionality via Lens Extensions. Add new features and functionality via Lens Extensions.

View File

@ -14,7 +14,7 @@ import { IngressCharts } from "./ingress-charts";
import { KubeObjectMeta } from "../kube-object/kube-object-meta"; import { KubeObjectMeta } from "../kube-object/kube-object-meta";
import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry"; import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry";
import { getBackendServiceNamePort } from "../../api/endpoints/ingress.api"; import { getBackendServiceNamePort } from "../../api/endpoints/ingress.api";
import { ResourceType } from "../+cluster-settings/components/cluster-metrics-setting"; import { ResourceType } from "../cluster-settings/components/cluster-metrics-setting";
import { clusterStore } from "../../../common/cluster-store"; import { clusterStore } from "../../../common/cluster-store";
interface Props extends KubeObjectDetailsProps<Ingress> { interface Props extends KubeObjectDetailsProps<Ingress> {

View File

@ -17,7 +17,7 @@ import { PodDetailsList } from "../+workloads-pods/pod-details-list";
import { KubeObjectMeta } from "../kube-object/kube-object-meta"; import { KubeObjectMeta } from "../kube-object/kube-object-meta";
import { KubeEventDetails } from "../+events/kube-event-details"; import { KubeEventDetails } from "../+events/kube-event-details";
import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry"; import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry";
import { ResourceType } from "../+cluster-settings/components/cluster-metrics-setting"; import { ResourceType } from "../cluster-settings/components/cluster-metrics-setting";
import { clusterStore } from "../../../common/cluster-store"; import { clusterStore } from "../../../common/cluster-store";
interface Props extends KubeObjectDetailsProps<Node> { interface Props extends KubeObjectDetailsProps<Node> {

View File

@ -14,7 +14,7 @@ import { VolumeClaimDiskChart } from "./volume-claim-disk-chart";
import { getDetailsUrl, KubeObjectDetailsProps, KubeObjectMeta } from "../kube-object"; import { getDetailsUrl, KubeObjectDetailsProps, KubeObjectMeta } from "../kube-object";
import { PersistentVolumeClaim } from "../../api/endpoints"; import { PersistentVolumeClaim } from "../../api/endpoints";
import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry"; import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry";
import { ResourceType } from "../+cluster-settings/components/cluster-metrics-setting"; import { ResourceType } from "../cluster-settings/components/cluster-metrics-setting";
import { clusterStore } from "../../../common/cluster-store"; import { clusterStore } from "../../../common/cluster-store";
interface Props extends KubeObjectDetailsProps<PersistentVolumeClaim> { interface Props extends KubeObjectDetailsProps<PersistentVolumeClaim> {

View File

@ -18,7 +18,7 @@ import { reaction } from "mobx";
import { PodDetailsList } from "../+workloads-pods/pod-details-list"; import { PodDetailsList } from "../+workloads-pods/pod-details-list";
import { KubeObjectMeta } from "../kube-object/kube-object-meta"; import { KubeObjectMeta } from "../kube-object/kube-object-meta";
import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry"; import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry";
import { ResourceType } from "../+cluster-settings/components/cluster-metrics-setting"; import { ResourceType } from "../cluster-settings/components/cluster-metrics-setting";
import { clusterStore } from "../../../common/cluster-store"; import { clusterStore } from "../../../common/cluster-store";
interface Props extends KubeObjectDetailsProps<DaemonSet> { interface Props extends KubeObjectDetailsProps<DaemonSet> {

View File

@ -19,7 +19,7 @@ import { reaction } from "mobx";
import { PodDetailsList } from "../+workloads-pods/pod-details-list"; import { PodDetailsList } from "../+workloads-pods/pod-details-list";
import { KubeObjectMeta } from "../kube-object/kube-object-meta"; import { KubeObjectMeta } from "../kube-object/kube-object-meta";
import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry"; import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry";
import { ResourceType } from "../+cluster-settings/components/cluster-metrics-setting"; import { ResourceType } from "../cluster-settings/components/cluster-metrics-setting";
import { clusterStore } from "../../../common/cluster-store"; import { clusterStore } from "../../../common/cluster-store";
interface Props extends KubeObjectDetailsProps<Deployment> { interface Props extends KubeObjectDetailsProps<Deployment> {

View File

@ -11,7 +11,7 @@ import { PodContainerPort } from "./pod-container-port";
import { ResourceMetrics } from "../resource-metrics"; import { ResourceMetrics } from "../resource-metrics";
import { IMetrics } from "../../api/endpoints/metrics.api"; import { IMetrics } from "../../api/endpoints/metrics.api";
import { ContainerCharts } from "./container-charts"; import { ContainerCharts } from "./container-charts";
import { ResourceType } from "../+cluster-settings/components/cluster-metrics-setting"; import { ResourceType } from "../cluster-settings/components/cluster-metrics-setting";
import { clusterStore } from "../../../common/cluster-store"; import { clusterStore } from "../../../common/cluster-store";
interface Props { interface Props {

View File

@ -22,7 +22,7 @@ import { getItemMetrics } from "../../api/endpoints/metrics.api";
import { PodCharts, podMetricTabs } from "./pod-charts"; import { PodCharts, podMetricTabs } from "./pod-charts";
import { KubeObjectMeta } from "../kube-object/kube-object-meta"; import { KubeObjectMeta } from "../kube-object/kube-object-meta";
import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry"; import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry";
import { ResourceType } from "../+cluster-settings/components/cluster-metrics-setting"; import { ResourceType } from "../cluster-settings/components/cluster-metrics-setting";
import { clusterStore } from "../../../common/cluster-store"; import { clusterStore } from "../../../common/cluster-store";
interface Props extends KubeObjectDetailsProps<Pod> { interface Props extends KubeObjectDetailsProps<Pod> {

View File

@ -17,7 +17,7 @@ import { PodCharts, podMetricTabs } from "../+workloads-pods/pod-charts";
import { PodDetailsList } from "../+workloads-pods/pod-details-list"; import { PodDetailsList } from "../+workloads-pods/pod-details-list";
import { KubeObjectMeta } from "../kube-object/kube-object-meta"; import { KubeObjectMeta } from "../kube-object/kube-object-meta";
import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry"; import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry";
import { ResourceType } from "../+cluster-settings/components/cluster-metrics-setting"; import { ResourceType } from "../cluster-settings/components/cluster-metrics-setting";
import { clusterStore } from "../../../common/cluster-store"; import { clusterStore } from "../../../common/cluster-store";
interface Props extends KubeObjectDetailsProps<ReplicaSet> { interface Props extends KubeObjectDetailsProps<ReplicaSet> {

View File

@ -18,7 +18,7 @@ import { PodCharts, podMetricTabs } from "../+workloads-pods/pod-charts";
import { PodDetailsList } from "../+workloads-pods/pod-details-list"; import { PodDetailsList } from "../+workloads-pods/pod-details-list";
import { KubeObjectMeta } from "../kube-object/kube-object-meta"; import { KubeObjectMeta } from "../kube-object/kube-object-meta";
import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry"; import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry";
import { ResourceType } from "../+cluster-settings/components/cluster-metrics-setting"; import { ResourceType } from "../cluster-settings/components/cluster-metrics-setting";
import { clusterStore } from "../../../common/cluster-store"; import { clusterStore } from "../../../common/cluster-store";
interface Props extends KubeObjectDetailsProps<StatefulSet> { interface Props extends KubeObjectDetailsProps<StatefulSet> {

View File

@ -1,51 +0,0 @@
import React from "react";
import uniqueId from "lodash/uniqueId";
import { clusterSettingsURL } from "../+cluster-settings";
import { catalogURL } from "../+catalog";
import { clusterStore } from "../../../common/cluster-store";
import { broadcastMessage, requestMain } from "../../../common/ipc";
import { clusterDisconnectHandler } from "../../../common/cluster-ipc";
import { ConfirmDialog } from "../confirm-dialog";
import { Cluster } from "../../../main/cluster";
import { Tooltip } from "../../components//tooltip";
import { IpcRendererNavigationEvents } from "../../navigation/events";
const navigate = (route: string) =>
broadcastMessage(IpcRendererNavigationEvents.NAVIGATE_IN_APP, route);
/**
* Creates handlers for high-level actions
* that could be performed on an individual cluster
* @param cluster Cluster
*/
export const ClusterActions = (cluster: Cluster) => ({
showSettings: () => navigate(clusterSettingsURL({
params: { clusterId: cluster.id }
})),
disconnect: async () => {
clusterStore.deactivate(cluster.id);
navigate(catalogURL());
await requestMain(clusterDisconnectHandler, cluster.id);
},
remove: () => {
const tooltipId = uniqueId("tooltip_target_");
return ConfirmDialog.open({
okButtonProps: {
primary: false,
accent: true,
label: "Remove"
},
ok: () => {
clusterStore.deactivate(cluster.id);
clusterStore.removeById(cluster.id);
navigate(catalogURL());
},
message: <p>
Are you sure want to remove cluster <b id={tooltipId}>{cluster.name}</b>?
<Tooltip targetId={tooltipId}>{cluster.id}</Tooltip>
</p>
});
}
});

View File

@ -9,7 +9,6 @@ import { Catalog, catalogRoute, catalogURL } from "../+catalog";
import { Preferences, preferencesRoute } from "../+preferences"; import { Preferences, preferencesRoute } from "../+preferences";
import { AddCluster, addClusterRoute } from "../+add-cluster"; import { AddCluster, addClusterRoute } from "../+add-cluster";
import { ClusterView } from "./cluster-view"; import { ClusterView } from "./cluster-view";
import { ClusterSettings, clusterSettingsRoute } from "../+cluster-settings";
import { clusterViewRoute } from "./cluster-view.route"; import { clusterViewRoute } from "./cluster-view.route";
import { clusterStore } from "../../../common/cluster-store"; import { clusterStore } from "../../../common/cluster-store";
import { hasLoadedView, initView, lensViews, refreshViews } from "./lens-views"; import { hasLoadedView, initView, lensViews, refreshViews } from "./lens-views";
@ -17,6 +16,7 @@ import { globalPageRegistry } from "../../../extensions/registries/page-registry
import { Extensions, extensionsRoute } from "../+extensions"; import { Extensions, extensionsRoute } from "../+extensions";
import { getMatchedClusterId } from "../../navigation"; import { getMatchedClusterId } from "../../navigation";
import { HotbarMenu } from "../hotbar/hotbar-menu"; import { HotbarMenu } from "../hotbar/hotbar-menu";
import { EntitySettings, entitySettingsRoute } from "../+entity-settings";
@observer @observer
export class ClusterManager extends React.Component { export class ClusterManager extends React.Component {
@ -58,7 +58,7 @@ export class ClusterManager extends React.Component {
<Route component={Extensions} {...extensionsRoute} /> <Route component={Extensions} {...extensionsRoute} />
<Route component={AddCluster} {...addClusterRoute} /> <Route component={AddCluster} {...addClusterRoute} />
<Route component={ClusterView} {...clusterViewRoute} /> <Route component={ClusterView} {...clusterViewRoute} />
<Route component={ClusterSettings} {...clusterSettingsRoute} /> <Route component={EntitySettings} {...entitySettingsRoute} />
{globalPageRegistry.getItems().map(({ url, components: { Page } }) => { {globalPageRegistry.getItems().map(({ url, components: { Page } }) => {
return <Route key={url} path={url} component={Page}/>; return <Route key={url} path={url} component={Page}/>;
})} })}

View File

@ -1,2 +1 @@
export * from "./cluster-manager"; export * from "./cluster-manager";
export * from "./cluster-actions";

View File

@ -1,15 +1,15 @@
import { navigate } from "../../navigation"; import { navigate } from "../../navigation";
import { commandRegistry } from "../../../extensions/registries/command-registry"; import { commandRegistry } from "../../../extensions/registries/command-registry";
import { clusterSettingsURL } from "./cluster-settings.route";
import { clusterStore } from "../../../common/cluster-store"; import { clusterStore } from "../../../common/cluster-store";
import { entitySettingsURL } from "../+entity-settings";
commandRegistry.add({ commandRegistry.add({
id: "cluster.viewCurrentClusterSettings", id: "cluster.viewCurrentClusterSettings",
title: "Cluster: View Settings", title: "Cluster: View Settings",
scope: "global", scope: "global",
action: () => navigate(clusterSettingsURL({ action: () => navigate(entitySettingsURL({
params: { params: {
clusterId: clusterStore.active.id entityId: clusterStore.active.id
} }
})), })),
isActive: (context) => !!context.entity isActive: (context) => !!context.entity

View File

@ -0,0 +1,141 @@
import React from "react";
import { clusterStore } from "../../../common/cluster-store";
import { ClusterProxySetting } from "./components/cluster-proxy-setting";
import { ClusterNameSetting } from "./components/cluster-name-setting";
import { ClusterHomeDirSetting } from "./components/cluster-home-dir-setting";
import { ClusterAccessibleNamespaces } from "./components/cluster-accessible-namespaces";
import { ClusterMetricsSetting } from "./components/cluster-metrics-setting";
import { ShowMetricsSetting } from "./components/show-metrics";
import { ClusterPrometheusSetting } from "./components/cluster-prometheus-setting";
import { ClusterKubeconfig } from "./components/cluster-kubeconfig";
import { entitySettingRegistry } from "../../../extensions/registries";
import { CatalogEntity } from "../../api/catalog-entity";
function getClusterForEntity(entity: CatalogEntity) {
const cluster = clusterStore.getById(entity.metadata.uid);
if (!cluster?.enabled) {
return null;
}
return cluster;
}
entitySettingRegistry.add([
{
apiVersions: ["entity.k8slens.dev/v1alpha1"],
kind: "KubernetesCluster",
source: "local",
title: "General",
components: {
View: (props: { entity: CatalogEntity }) => {
const cluster = getClusterForEntity(props.entity);
if (!cluster) {
return null;
}
return (
<section>
<section>
<ClusterNameSetting cluster={cluster} />
</section>
<section>
<ClusterKubeconfig cluster={cluster} />
</section>
</section>
);
}
}
},
{
apiVersions: ["entity.k8slens.dev/v1alpha1"],
kind: "KubernetesCluster",
title: "Proxy",
components: {
View: (props: { entity: CatalogEntity }) => {
const cluster = getClusterForEntity(props.entity);
if (!cluster) {
return null;
}
return (
<section>
<ClusterProxySetting cluster={cluster} />
</section>
);
}
}
},
{
apiVersions: ["entity.k8slens.dev/v1alpha1"],
kind: "KubernetesCluster",
title: "Terminal",
components: {
View: (props: { entity: CatalogEntity }) => {
const cluster = getClusterForEntity(props.entity);
if (!cluster) {
return null;
}
return (
<section>
<ClusterHomeDirSetting cluster={cluster} />
</section>
);
}
}
},
{
apiVersions: ["entity.k8slens.dev/v1alpha1"],
kind: "KubernetesCluster",
title: "Namespaces",
components: {
View: (props: { entity: CatalogEntity }) => {
const cluster = getClusterForEntity(props.entity);
if (!cluster) {
return null;
}
return (
<section>
<ClusterAccessibleNamespaces cluster={cluster} />
</section>
);
}
}
},
{
apiVersions: ["entity.k8slens.dev/v1alpha1"],
kind: "KubernetesCluster",
source: "local",
title: "Metrics",
components: {
View: (props: { entity: CatalogEntity }) => {
const cluster = getClusterForEntity(props.entity);
if (!cluster) {
return null;
}
return (
<section>
<section>
<ClusterPrometheusSetting cluster={cluster} />
</section>
<section>
<ClusterMetricsSetting cluster={cluster}/>
</section>
<section>
<ShowMetricsSetting cluster={cluster}/>
</section>
</section>
);
}
}
}
]);

View File

@ -17,7 +17,6 @@ export class ClusterAccessibleNamespaces extends React.Component<Props> {
return ( return (
<> <>
<SubTitle title="Accessible Namespaces" id="accessible-namespaces" /> <SubTitle title="Accessible Namespaces" id="accessible-namespaces" />
<p>This setting is useful for manually specifying which namespaces you have access to. This is useful when you do not have permissions to list namespaces.</p>
<EditableList <EditableList
placeholder="Add new namespace..." placeholder="Add new namespace..."
add={(newNamespace) => { add={(newNamespace) => {
@ -30,6 +29,9 @@ export class ClusterAccessibleNamespaces extends React.Component<Props> {
this.props.cluster.accessibleNamespaces = Array.from(this.namespaces); this.props.cluster.accessibleNamespaces = Array.from(this.namespaces);
}} }}
/> />
<small className="hint">
This setting is useful for manually specifying which namespaces you have access to. This is useful when you do not have permissions to list namespaces.
</small>
</> </>
); );
} }

View File

@ -33,7 +33,6 @@ export class ClusterHomeDirSetting extends React.Component<Props> {
return ( return (
<> <>
<SubTitle title="Working Directory"/> <SubTitle title="Working Directory"/>
<p>Terminal working directory.</p>
<Input <Input
theme="round-black" theme="round-black"
value={this.directory} value={this.directory}

View File

@ -0,0 +1,34 @@
import React from "react";
import { Cluster } from "../../../../main/cluster";
import { observer } from "mobx-react";
import { SubTitle } from "../../layout/sub-title";
import { autobind } from "../../../../common/utils";
import { shell } from "electron";
interface Props {
cluster: Cluster;
}
@observer
export class ClusterKubeconfig extends React.Component<Props> {
@autobind()
openKubeconfig() {
const { cluster } = this.props;
shell.showItemInFolder(cluster.kubeConfigPath);
}
render() {
return (
<>
<SubTitle title="Kubeconfig" />
<span>
<a className="link value" onClick={this.openKubeconfig}>{this.props.cluster.kubeConfigPath}</a>
</span>
</>
);
}
}

View File

@ -34,7 +34,6 @@ export class ClusterNameSetting extends React.Component<Props> {
return ( return (
<> <>
<SubTitle title="Cluster Name" /> <SubTitle title="Cluster Name" />
<p>Define cluster name.</p>
<Input <Input
theme="round-black" theme="round-black"
validators={isRequired} validators={isRequired}

View File

@ -81,13 +81,12 @@ export class ClusterPrometheusSetting extends React.Component<Props> {
render() { render() {
return ( return (
<> <>
<SubTitle title="Prometheus"/> <SubTitle title="Prometheus installation method"/>
<p> <p>
Use pre-installed Prometheus service for metrics. Please refer to the{" "} Use pre-installed Prometheus service for metrics. Please refer to the{" "}
<a href="https://github.com/lensapp/lens/blob/master/troubleshooting/custom-prometheus.md" target="_blank" rel="noreferrer">guide</a>{" "} <a href="https://github.com/lensapp/lens/blob/master/troubleshooting/custom-prometheus.md" target="_blank" rel="noreferrer">guide</a>{" "}
for possible configuration changes. for possible configuration changes.
</p> </p>
<p>Prometheus installation method.</p>
<Select <Select
value={this.provider} value={this.provider}
onChange={({value}) => { onChange={({value}) => {

View File

@ -33,7 +33,6 @@ export class ClusterProxySetting extends React.Component<Props> {
return ( return (
<> <>
<SubTitle title="HTTP Proxy" /> <SubTitle title="HTTP Proxy" />
<p>HTTP Proxy server. Used for communicating with Kubernetes API.</p>
<Input <Input
theme="round-black" theme="round-black"
value={this.proxy} value={this.proxy}
@ -42,6 +41,9 @@ export class ClusterProxySetting extends React.Component<Props> {
placeholder="http://<address>:<port>" placeholder="http://<address>:<port>"
validators={this.proxy ? InputValidators.isUrl : undefined} validators={this.proxy ? InputValidators.isUrl : undefined}
/> />
<small className="hint">
HTTP Proxy server. Used for communicating with Kubernetes API.
</small>
</> </>
); );
} }

View File

@ -1,3 +1,2 @@
export * from "./cluster-settings.route";
export * from "./cluster-settings"; export * from "./cluster-settings";
export * from "./cluster-settings.command"; export * from "./cluster-settings.command";

View File

@ -43,6 +43,15 @@
width: 218px; width: 218px;
padding: 60px 0 60px 20px; padding: 60px 0 60px 20px;
h2 {
margin-bottom: 10px;
font-size: 18px;
padding: 6px 10px;
overflow-wrap: anywhere;
color: var(--textColorAccent);
font-weight: 600;
}
.Tabs { .Tabs {
.header { .header {
padding: 6px 10px; padding: 6px 10px;

View File

@ -8,8 +8,6 @@ import { Icon } from "../icon";
export interface PageLayoutProps extends React.DOMAttributes<any> { export interface PageLayoutProps extends React.DOMAttributes<any> {
className?: IClassName; className?: IClassName;
header?: React.ReactNode;
headerClass?: IClassName;
contentClass?: IClassName; contentClass?: IClassName;
provideBackButtonNavigation?: boolean; provideBackButtonNavigation?: boolean;
contentGaps?: boolean; contentGaps?: boolean;
@ -57,7 +55,7 @@ export class PageLayout extends React.Component<PageLayoutProps> {
render() { render() {
const { const {
contentClass, headerClass, provideBackButtonNavigation, contentClass, provideBackButtonNavigation,
contentGaps, showOnTop, navigation, children, ...elemProps contentGaps, showOnTop, navigation, children, ...elemProps
} = this.props; } = this.props;
const className = cssNames("PageLayout", { showOnTop, showNavigation: navigation }, this.props.className); const className = cssNames("PageLayout", { showOnTop, showNavigation: navigation }, this.props.className);

View File

@ -7,7 +7,7 @@ import { isMac } from "../../common/vars";
import { invalidKubeconfigHandler } from "./invalid-kubeconfig-handler"; import { invalidKubeconfigHandler } from "./invalid-kubeconfig-handler";
import { clusterStore } from "../../common/cluster-store"; import { clusterStore } from "../../common/cluster-store";
import { navigate } from "../navigation"; import { navigate } from "../navigation";
import { clusterSettingsURL } from "../components/+cluster-settings"; import { entitySettingsURL } from "../components/+entity-settings";
function sendToBackchannel(backchannel: string, notificationId: string, data: BackchannelArg): void { function sendToBackchannel(backchannel: string, notificationId: string, data: BackchannelArg): void {
notificationsStore.remove(notificationId); notificationsStore.remove(notificationId);
@ -79,7 +79,7 @@ function ListNamespacesForbiddenHandler(event: IpcRendererEvent, ...[clusterId]:
<p>Cluster <b>{clusterStore.active.name}</b> does not have permissions to list namespaces. Please add the namespaces you have access to.</p> <p>Cluster <b>{clusterStore.active.name}</b> does not have permissions to list namespaces. Please add the namespaces you have access to.</p>
<div className="flex gaps row align-left box grow"> <div className="flex gaps row align-left box grow">
<Button active outlined label="Go to Accessible Namespaces Settings" onClick={()=> { <Button active outlined label="Go to Accessible Namespaces Settings" onClick={()=> {
navigate(clusterSettingsURL({ params: { clusterId }, fragment: "accessible-namespaces" })); navigate(entitySettingsURL({ params: { entityId: clusterId }, fragment: "accessible-namespaces" }));
notificationsStore.remove(notificationId); notificationsStore.remove(notificationId);
}} /> }} />
</div> </div>

View File

@ -1,5 +1,4 @@
import { addClusterURL } from "../components/+add-cluster"; import { addClusterURL } from "../components/+add-cluster";
import { clusterSettingsURL } from "../components/+cluster-settings";
import { extensionsURL } from "../components/+extensions"; import { extensionsURL } from "../components/+extensions";
import { catalogURL } from "../components/+catalog"; import { catalogURL } from "../components/+catalog";
import { preferencesURL } from "../components/+preferences"; import { preferencesURL } from "../components/+preferences";
@ -7,6 +6,8 @@ import { clusterViewURL } from "../components/cluster-manager/cluster-view.route
import { LensProtocolRouterRenderer } from "./router"; import { LensProtocolRouterRenderer } from "./router";
import { navigate } from "../navigation/helpers"; import { navigate } from "../navigation/helpers";
import { clusterStore } from "../../common/cluster-store"; import { clusterStore } from "../../common/cluster-store";
import { entitySettingsURL } from "../components/+entity-settings";
import { catalogEntityRegistry } from "../api/catalog-entity-registry";
export function bindProtocolAddRouteHandlers() { export function bindProtocolAddRouteHandlers() {
LensProtocolRouterRenderer LensProtocolRouterRenderer
@ -23,6 +24,19 @@ export function bindProtocolAddRouteHandlers() {
.addInternalHandler("/cluster", () => { .addInternalHandler("/cluster", () => {
navigate(addClusterURL()); navigate(addClusterURL());
}) })
.addInternalHandler("/entity/:entityId/settings", ({ pathname: { entityId } }) => {
const entity = catalogEntityRegistry.getById(entityId);
if (entity) {
navigate(entitySettingsURL({ params: { entityId } }));
} else {
console.log("[APP-HANDLER]: catalog entity with given ID does not exist", { entityId });
}
})
.addInternalHandler("/extensions", () => {
navigate(extensionsURL());
})
// Handlers below are deprecated and only kept for backward compat purposes
.addInternalHandler("/cluster/:clusterId", ({ pathname: { clusterId } }) => { .addInternalHandler("/cluster/:clusterId", ({ pathname: { clusterId } }) => {
const cluster = clusterStore.getById(clusterId); const cluster = clusterStore.getById(clusterId);
@ -36,12 +50,9 @@ export function bindProtocolAddRouteHandlers() {
const cluster = clusterStore.getById(clusterId); const cluster = clusterStore.getById(clusterId);
if (cluster) { if (cluster) {
navigate(clusterSettingsURL({ params: { clusterId } })); navigate(entitySettingsURL({ params: { entityId: clusterId } }));
} else { } else {
console.log("[APP-HANDLER]: cluster with given ID does not exist", { clusterId }); console.log("[APP-HANDLER]: cluster with given ID does not exist", { clusterId });
} }
})
.addInternalHandler("/extensions", () => {
navigate(extensionsURL());
}); });
} }