mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
show lens-metrics on cluster settings
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
1 parent
7b1b8e6321
commit
8b0b7fcbb2
18 files changed
+311
-84
No files matched your search
@@ -34,7 +34,6 @@ export class KubernetesCluster extends CatalogEntity<CatalogEntityMetadata, Kube
|
||||
async onContextMenuOpen(context: CatalogEntityContextMenuContext) {
|
||||
context.menuItems = [
|
||||
{
|
||||
icon: "settings",
|
||||
title: "Settings",
|
||||
onlyVisibleForSource: "local",
|
||||
onClick: async () => context.navigate(`/entity/${this.metadata.uid}/settings`)
|
||||
@@ -43,7 +42,6 @@ export class KubernetesCluster extends CatalogEntity<CatalogEntityMetadata, Kube
|
||||
|
||||
if (this.metadata.labels["file"]?.startsWith(ClusterStore.storedKubeConfigFolder)) {
|
||||
context.menuItems.push({
|
||||
icon: "delete",
|
||||
title: "Delete",
|
||||
onlyVisibleForSource: "local",
|
||||
onClick: async () => ClusterStore.getInstance().removeById(this.metadata.uid),
|
||||
@@ -54,14 +52,20 @@ export class KubernetesCluster extends CatalogEntity<CatalogEntityMetadata, Kube
|
||||
}
|
||||
|
||||
if (this.status.phase == "connected") {
|
||||
context.menuItems.unshift({
|
||||
icon: "link_off",
|
||||
context.menuItems.push({
|
||||
title: "Disconnect",
|
||||
onClick: async () => {
|
||||
ClusterStore.getInstance().deactivate(this.metadata.uid);
|
||||
requestMain(clusterDisconnectHandler, this.metadata.uid);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
context.menuItems.push({
|
||||
title: "Connect",
|
||||
onClick: async () => {
|
||||
context.navigate(`/cluster/${this.metadata.uid}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const category = catalogCategoryRegistry.getCategoryForEntity<KubernetesClusterCategory>(this);
|
||||
|
||||
@@ -62,7 +62,6 @@ export interface CatalogEntityActionContext {
|
||||
}
|
||||
|
||||
export interface CatalogEntityContextMenu {
|
||||
icon: string;
|
||||
title: string;
|
||||
onlyVisibleForSource?: string; // show only if empty or if matches with entity source
|
||||
onClick: () => void | Promise<void>;
|
||||
@@ -71,6 +70,10 @@ export interface CatalogEntityContextMenu {
|
||||
}
|
||||
}
|
||||
|
||||
export interface CatalogEntityAddMenu extends CatalogEntityContextMenu {
|
||||
icon: string;
|
||||
}
|
||||
|
||||
export interface CatalogEntitySettingsMenu {
|
||||
group?: string;
|
||||
title: string;
|
||||
@@ -90,7 +93,7 @@ export interface CatalogEntitySettingsContext {
|
||||
|
||||
export interface CatalogEntityAddMenuContext {
|
||||
navigate: (url: string) => void;
|
||||
menuItems: CatalogEntityContextMenu[];
|
||||
menuItems: CatalogEntityAddMenu[];
|
||||
}
|
||||
|
||||
export type CatalogEntitySpec = Record<string, any>;
|
||||
|
||||
@@ -46,14 +46,20 @@ if (ipcMain) {
|
||||
}
|
||||
});
|
||||
|
||||
handleRequest(clusterKubectlApplyAllHandler, (event, clusterId: ClusterId, resources: string[]) => {
|
||||
handleRequest(clusterKubectlApplyAllHandler, async (event, clusterId: ClusterId, resources: string[]) => {
|
||||
appEventBus.emit({name: "cluster", action: "kubectl-apply-all"});
|
||||
const cluster = ClusterStore.getInstance().getById(clusterId);
|
||||
|
||||
if (cluster) {
|
||||
const applier = new ResourceApplier(cluster);
|
||||
|
||||
applier.kubectlApplyAll(resources);
|
||||
try {
|
||||
const stdout = await applier.kubectlApplyAll(resources);
|
||||
|
||||
return { stdout };
|
||||
} catch (error: any) {
|
||||
return { stderr: error };
|
||||
}
|
||||
} else {
|
||||
throw `${clusterId} is not a valid cluster id`;
|
||||
}
|
||||
|
||||
@@ -99,9 +99,9 @@ export abstract class ClusterFeature {
|
||||
}
|
||||
|
||||
if (app) {
|
||||
await new ResourceApplier(clusterModel).kubectlApplyAll(resources);
|
||||
return await new ResourceApplier(clusterModel).kubectlApplyAll(resources);
|
||||
} else {
|
||||
await requestMain(clusterKubectlApplyAllHandler, cluster.metadata.uid, resources);
|
||||
return await requestMain(clusterKubectlApplyAllHandler, cluster.metadata.uid, resources);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ export * from "../../renderer/components/checkbox";
|
||||
export * from "../../renderer/components/radio";
|
||||
export * from "../../renderer/components/select";
|
||||
export * from "../../renderer/components/slider";
|
||||
export * from "../../renderer/components/switch";
|
||||
export * from "../../renderer/components/input/input";
|
||||
|
||||
// command-overlay
|
||||
|
||||
@@ -67,16 +67,19 @@ export class ResourceApplier {
|
||||
const cmd = `"${kubectlPath}" apply --kubeconfig "${proxyKubeconfigPath}" -o json -f "${tmpDir}"`;
|
||||
|
||||
console.log("shooting manifests with:", cmd);
|
||||
exec(cmd, (error, stdout, stderr) => {
|
||||
exec(cmd, (error, stdout) => {
|
||||
if (error) {
|
||||
reject(`Error applying manifests:${error}`);
|
||||
}
|
||||
const splittedError = error.toString().split(`.yaml": `);
|
||||
|
||||
if (stderr != "") {
|
||||
reject(stderr);
|
||||
if (splittedError[1]) {
|
||||
reject(`Error applying manifests: ${splittedError[1]}`);
|
||||
} else {
|
||||
reject(`Error applying manifests:${error}`);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(stdout);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,6 +9,7 @@ export {
|
||||
CatalogEntityKindData,
|
||||
CatalogEntityActionContext,
|
||||
CatalogEntityAddMenuContext,
|
||||
CatalogEntityAddMenu,
|
||||
CatalogEntityContextMenu,
|
||||
CatalogEntityContextMenuContext
|
||||
} from "../../common/catalog";
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Icon } from "../icon";
|
||||
import { disposeOnUnmount, observer } from "mobx-react";
|
||||
import { observable, reaction } from "mobx";
|
||||
import { autobind } from "../../../common/utils";
|
||||
import { CatalogCategory, CatalogEntityAddMenuContext, CatalogEntityContextMenu } from "../../api/catalog-entity";
|
||||
import { CatalogCategory, CatalogEntityAddMenuContext, CatalogEntityAddMenu } from "../../api/catalog-entity";
|
||||
import { EventEmitter } from "events";
|
||||
import { navigate } from "../../navigation";
|
||||
|
||||
@@ -16,7 +16,7 @@ export type CatalogAddButtonProps = {
|
||||
@observer
|
||||
export class CatalogAddButton extends React.Component<CatalogAddButtonProps> {
|
||||
@observable protected isOpen = false;
|
||||
protected menuItems = observable.array<CatalogEntityContextMenu>([]);
|
||||
protected menuItems = observable.array<CatalogEntityAddMenu>([]);
|
||||
|
||||
componentDidMount() {
|
||||
disposeOnUnmount(this, [
|
||||
|
||||
@@ -8,7 +8,6 @@ import { navigate } from "../../navigation";
|
||||
import { kebabCase } from "lodash";
|
||||
import { PageLayout } from "../layout/page-layout";
|
||||
import { MenuItem, MenuActions } from "../menu";
|
||||
import { Icon } from "../icon";
|
||||
import { CatalogEntityContextMenu, CatalogEntityContextMenuContext, catalogEntityRunContext } from "../../api/catalog-entity";
|
||||
import { Badge } from "../badge";
|
||||
import { HotbarStore } from "../../../common/hotbar-store";
|
||||
@@ -115,16 +114,16 @@ export class Catalog extends React.Component {
|
||||
|
||||
return (
|
||||
<MenuActions onOpen={() => item.onContextMenuOpen(this.contextMenu)}>
|
||||
<MenuItem key="add-to-hotbar" onClick={() => this.addToHotbar(item) }>
|
||||
<Icon material="add" small interactive={true} title="Add to hotbar"/> Add to Hotbar
|
||||
</MenuItem>
|
||||
{
|
||||
menuItems.map((menuItem, index) => (
|
||||
<MenuItem key={index} onClick={() => this.onMenuItemClick(menuItem)}>
|
||||
<Icon material={menuItem.icon} small interactive={true} title={menuItem.title} /> {menuItem.title}
|
||||
{menuItem.title}
|
||||
</MenuItem>
|
||||
))
|
||||
}
|
||||
<MenuItem key="add-to-hotbar" onClick={() => this.addToHotbar(item) }>
|
||||
Add to Hotbar
|
||||
</MenuItem>
|
||||
</MenuActions>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -36,9 +36,15 @@ export class EntitySettings extends React.Component<Props> {
|
||||
async componentDidMount() {
|
||||
const { hash } = navigation.location;
|
||||
|
||||
this.ensureActiveTab();
|
||||
if (hash) {
|
||||
const item = this.menuItems.find((item) => item.title === hash.slice(1));
|
||||
|
||||
document.getElementById(hash.slice(1))?.scrollIntoView();
|
||||
if (item) {
|
||||
this.activeTab = item.id;
|
||||
}
|
||||
}
|
||||
|
||||
this.ensureActiveTab();
|
||||
}
|
||||
|
||||
onTabChange = (tabId: string) => {
|
||||
|
||||
@@ -159,16 +159,16 @@ export class HotbarIcon extends React.Component<Props> {
|
||||
position={{right: true, bottom: true }} // FIXME: position does not work
|
||||
open={() => onOpen()}
|
||||
close={() => this.toggleMenu()}>
|
||||
<MenuItem key="remove-from-hotbar" onClick={() => this.remove(entity) }>
|
||||
<Icon material="clear" small interactive={true} title="Remove from hotbar"/> Remove from Hotbar
|
||||
</MenuItem>
|
||||
{ this.contextMenu && menuItems.map((menuItem) => {
|
||||
return (
|
||||
<MenuItem key={menuItem.title} onClick={() => this.onMenuItemClick(menuItem) }>
|
||||
<Icon material={menuItem.icon} small interactive={true} title={menuItem.title}/> {menuItem.title}
|
||||
{menuItem.title}
|
||||
</MenuItem>
|
||||
);
|
||||
})}
|
||||
<MenuItem key="remove-from-hotbar" onClick={() => this.remove(entity) }>
|
||||
Remove from Hotbar
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
{children}
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
.Menu {
|
||||
--bgc: #{$contentColor};
|
||||
--bgc: #{$layoutBackground};
|
||||
|
||||
position: absolute;
|
||||
display: flex;
|
||||
@@ -8,6 +8,8 @@
|
||||
list-style: none;
|
||||
border: 1px solid $borderColor;
|
||||
z-index: 101;
|
||||
box-shadow: rgba(0,0,0,0.24) 0px 8px 16px 0px;
|
||||
border-radius: 4px;
|
||||
|
||||
&.portal {
|
||||
left: -1000px;
|
||||
|
||||
Reference in new issue
Block a user