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) { const { object: node, toolbar } = props; if (!node) return null; const nodeName = node.getName(); const sendToTerminal = (command: string) => { terminalStore.sendCommand(command, { enter: true, newTab: true, }); hideDetails(); } const shell = () => { createTerminalTab({ title: _i18n._(t`Node: ${nodeName}`), node: nodeName, }); hideDetails(); } const cordon = () => { sendToTerminal(`kubectl cordon ${nodeName}`); } const unCordon = () => { sendToTerminal(`kubectl uncordon ${nodeName}`) } const drain = () => { 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 ); }