Use user configured kubectl path in node and pod menu items

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton committed 2021-09-13 14:44:07 -04:00
1 parent 4fa0b8e329
commit 1c058980f6
6 files changed
+81 -17

No files matched your search

+18 -5
View File
@@ -23,6 +23,7 @@
import React from "react";
import { Renderer, Common } from "@k8slens/extensions";
import { inspect } from "util";
type Pod = Renderer.K8sApi.Pod;
@@ -39,6 +40,7 @@ const {
} = Renderer;
const {
Util,
UserPreferences,
} = Common;
export interface PodAttachMenuProps extends Renderer.Component.KubeObjectMenuProps<Pod> {
@@ -47,22 +49,33 @@ export interface PodAttachMenuProps extends Renderer.Component.KubeObjectMenuPro
export class PodAttachMenu extends React.Component<PodAttachMenuProps> {
async attachToPod(container?: string) {
const { object: pod } = this.props;
const containerParam = container ? `-c ${container}` : "";
let command = `kubectl attach -i -t -n ${pod.getNs()} ${pod.getName()} ${containerParam}`;
const commandParts = [
inspect(UserPreferences.getKubectlPath(), false, null, false),
"attach",
"-i",
"-t",
"-n", pod.getNs(),
pod.getName(),
];
if (window.navigator.platform !== "Win32") {
command = `exec ${command}`;
commandParts.unshift("exec");
}
if (container) {
commandParts.push("-c", container);
}
const shell = createTerminalTab({
title: `Pod: ${pod.getName()} (namespace: ${pod.getNs()}) [Attached]`
});
terminalStore.sendCommand(command, {
terminalStore.sendCommand(commandParts.join(" "), {
enter: true,
tabId: shell.id
});
Navigation.hideDetails();
}
+23 -7
View File
@@ -23,6 +23,7 @@
import React from "react";
import { Renderer, Common } from "@k8slens/extensions";
import { inspect } from "util";
type Pod = Renderer.K8sApi.Pod;
@@ -39,6 +40,7 @@ const {
} = Renderer;
const {
Util,
UserPreferences,
} = Common;
export interface PodShellMenuProps extends Renderer.Component.KubeObjectMenuProps<Pod> {
@@ -46,29 +48,43 @@ export interface PodShellMenuProps extends Renderer.Component.KubeObjectMenuProp
export class PodShellMenu extends React.Component<PodShellMenuProps> {
async execShell(container?: string) {
Navigation.hideDetails();
const { object: pod } = this.props;
const containerParam = container ? `-c ${container}` : "";
let command = `kubectl exec -i -t -n ${pod.getNs()} ${pod.getName()} ${containerParam} "--"`;
const commandParts = [
inspect(UserPreferences.getKubectlPath(), false, null, false),
"exec",
"-i",
"-t",
"-n", pod.getNs(),
pod.getName(),
];
if (window.navigator.platform !== "Win32") {
command = `exec ${command}`;
commandParts.unshift("exec");
}
if (container) {
commandParts.push("-c", container);
}
commandParts.push("--");
if (pod.getSelectedNodeOs() === "windows") {
command = `${command} powershell`;
commandParts.push("powershell");
} else {
command = `${command} sh -c "clear; (bash || ash || sh)"`;
commandParts.push('sh -c "clear; (bash || ash || sh)"');
}
const shell = createTerminalTab({
title: `Pod: ${pod.getName()} (namespace: ${pod.getNs()})`
});
terminalStore.sendCommand(command, {
terminalStore.sendCommand(commandParts.join(" "), {
enter: true,
tabId: shell.id
});
Navigation.hideDetails();
}
render() {