import * as React from "react"; import { t, Trans } from "@lingui/macro"; import { Node } from "../../api/endpoints/nodes.api"; import { createTerminalTab, terminalStore } from "../dock/terminal.store"; import { KubeObjectMenu, KubeObjectMenuProps } from "../kube-object/kube-object-menu"; import { ConfirmDialog } from "../confirm-dialog"; import { MenuItem } from "../menu"; import { Icon } from "../icon"; import { _i18n } from "../../i18n"; import { hideDetails } from "../../navigation"; export function NodeMenu(props: KubeObjectMenuProps): JSX.Element { const { object: node, toolbar } = props; if (!node) { return null; } const nodeName = node.getName(); const sendToTerminal = (command: string): void => { terminalStore.sendCommand(command, { enter: true, newTab: true, }); hideDetails(); }; const shell = (): void => { createTerminalTab({ title: _i18n._(t`Node`) + `: ${nodeName}`, node: nodeName, }); hideDetails(); }; const cordon = (): void => { sendToTerminal(`kubectl cordon ${nodeName}`); }; const unCordon = (): void => { sendToTerminal(`kubectl uncordon ${nodeName}`); }; const drain = (): void => { const command = `kubectl drain ${nodeName} --delete-local-data --ignore-daemonsets --force`; ConfirmDialog.open({ ok: () => sendToTerminal(command), labelOk: _i18n._(t`Drain Node`), message: (

Are you sure you want to drain {nodeName}?

), }); }; return ( Shell {!node.isUnschedulable() && ( Cordon )} {node.isUnschedulable() && ( Uncordon )} Drain ); }