import "./pod-menu.scss"; import * as React from "react"; import { t, Trans } from "@lingui/macro"; import { MenuItem, SubMenu } from "../menu"; import { PodContainer, Pod } from "../../api/endpoints"; import { Icon } from "../icon"; import { StatusBrick } from "../status-brick"; import { PodLogsDialog } from "./pod-logs-dialog"; import { KubeObjectMenu, KubeObjectMenuProps } from "../kube-object/kube-object-menu"; import { cssNames, prevDefault } from "../../utils"; import { terminalStore, createTerminalTab } from "../dock/terminal.store"; import { _i18n } from "../../i18n"; import { hideDetails } from "../../navigation"; interface Props extends KubeObjectMenuProps { } export class PodMenu extends React.Component { async execShell(container?: string): Promise { hideDetails(); const { object: pod } = this.props; const containerParam = container ? `-c ${container}` : ""; let command = `kubectl exec -i -t -n ${pod.getNs()} ${pod.getName()} ${containerParam} "--"`; if (window.navigator.platform !== "Win32") { command = `exec ${command}`; } if (pod.getSelectedNodeOs() === "windows") { command = `${command} powershell`; } else { command = `${command} sh -c "clear; (bash || ash || sh)"`; } const shell = createTerminalTab({ title: _i18n._(t`Pod`) + `: ${pod.getName()} (namespace: ${pod.getNs()})` }); terminalStore.sendCommand(command, { enter: true, tabId: shell.id }); } showLogs(container: PodContainer): void { PodLogsDialog.open(this.props.object, container); } renderShellMenu(): JSX.Element { const { object: pod, toolbar } = this.props; const containers = pod.getRunningContainers(); if (!containers.length) { return; } return ( this.execShell(containers[0].name))}> Shell {containers.length > 1 && ( <> { containers.map(container => { const { name } = container; return ( this.execShell(name))} className="flex align-center"> {name} ); }) } )} ); } renderLogsMenu(): JSX.Element { const { object: pod, toolbar } = this.props; const containers = pod.getAllContainers(); const statuses = pod.getContainerStatuses(); if (!containers.length) { return; } return ( this.showLogs(containers[0]))}> Logs {containers.length > 1 && ( <> { containers.map(container => { const { name } = container; const status = statuses.find(status => status.name === name); const brick = status ? ( ) : null; return ( this.showLogs(container))} className="flex align-center"> {brick} {name} ); }) } )} ); } render(): JSX.Element { const { ...menuProps } = this.props; return ( {this.renderShellMenu()} {this.renderLogsMenu()} ); } }