From 7499b981c5ee73c081a2204387c2e20c65f57bd3 Mon Sep 17 00:00:00 2001 From: Jari Kolehmainen Date: Wed, 18 Mar 2020 18:26:54 +0200 Subject: [PATCH] support shell to windows pod (powershell) (#136) Signed-off-by: Jari Kolehmainen --- dashboard/client/api/endpoints/nodes.api.ts | 9 +++++++++ dashboard/client/api/endpoints/pods.api.ts | 4 ++++ .../client/components/+workloads-pods/pod-menu.tsx | 13 ++++++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/dashboard/client/api/endpoints/nodes.api.ts b/dashboard/client/api/endpoints/nodes.api.ts index 877b2c7ad4..c7f2905e8d 100644 --- a/dashboard/client/api/endpoints/nodes.api.ts +++ b/dashboard/client/api/endpoints/nodes.api.ts @@ -145,6 +145,15 @@ export class Node extends KubeObject { return this.status.nodeInfo.kubeletVersion; } + getOperatingSystem(): string { + const label = this.getLabels().find(label => label.startsWith("kubernetes.io/os=")) + if (label) { + return label.split("=", 2)[1] + } + + return "linux" + } + isUnschedulable() { return this.spec.unschedulable } diff --git a/dashboard/client/api/endpoints/pods.api.ts b/dashboard/client/api/endpoints/pods.api.ts index ebba1657c5..bed1e52928 100644 --- a/dashboard/client/api/endpoints/pods.api.ts +++ b/dashboard/client/api/endpoints/pods.api.ts @@ -401,6 +401,10 @@ export class Pod extends WorkloadKubeObject { ); return probe; } + + getNodeName() { + return this.spec?.nodeName + } } export const podsApi = new PodsApi({ diff --git a/dashboard/client/components/+workloads-pods/pod-menu.tsx b/dashboard/client/components/+workloads-pods/pod-menu.tsx index 6d42a9e2e0..9ec4384d17 100644 --- a/dashboard/client/components/+workloads-pods/pod-menu.tsx +++ b/dashboard/client/components/+workloads-pods/pod-menu.tsx @@ -3,7 +3,7 @@ import "./pod-menu.scss"; import * as React from "react"; import { t, Trans } from "@lingui/macro"; import { MenuItem, SubMenu } from "../menu"; -import { IPodContainer, Pod } from "../../api/endpoints"; +import { IPodContainer, Pod, nodesApi } from "../../api/endpoints"; import { Icon } from "../icon"; import { StatusBrick } from "../status-brick"; import { PodLogsDialog } from "./pod-logs-dialog"; @@ -17,11 +17,18 @@ interface Props extends KubeObjectMenuProps { } export class PodMenu extends React.Component { - execShell(container?: string) { + async execShell(container?: string) { hideDetails(); const { object: pod } = this.props const containerParam = container ? `-c ${container}` : "" - const command = `kubectl exec -i -t -n ${pod.getNs()} ${pod.getName()} ${containerParam} "--" sh -c "((clear && bash) || (clear && ash) || (clear && sh))"` + const node = await nodesApi.get({name: pod.getNodeName()}) + let command = `kubectl exec -i -t -n ${pod.getNs()} ${pod.getName()} ${containerParam} "--"` + if (node.getOperatingSystem() == "windows") { + command = `${command} powershell` + } else { + command = `${command} sh -c "clear; (bash || ash || sh)"` + } + terminalStore.sendCommand(command, { enter: true, newTab: true,