import "./pod-menu.scss"; import * as React from "react"; import { t, Trans } from "@lingui/macro"; import { MenuItem, SubMenu } from "../menu"; import { IPodContainer, Pod, nodesApi } 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 } 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) { hideDetails(); const { object: pod } = this.props const containerParam = container ? `-c ${container}` : "" let command = `kubectl exec -i -t -n ${pod.getNs()} ${pod.getName()} ${containerParam} "--"` if (pod.getSelectedNodeOs() === "windows") { command = `${command} powershell` } else { command = `${command} sh -c "clear; (bash || ash || sh)"` } terminalStore.sendCommand(command, { enter: true, newTab: true, }); } showLogs(container: IPodContainer) { PodLogsDialog.open(this.props.object, container); } renderShellMenu() { 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() { 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() { const { ...menuProps } = this.props; return ( {this.renderShellMenu()} {this.renderLogsMenu()} ) } }