mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Use user configured kubectl path in node and pod menu items
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
4fa0b8e329
commit
1c058980f6
@ -20,7 +20,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { Renderer } from "@k8slens/extensions";
|
import { Common, Renderer } from "@k8slens/extensions";
|
||||||
|
import { inspect } from "util";
|
||||||
|
|
||||||
type Node = Renderer.K8sApi.Node;
|
type Node = Renderer.K8sApi.Node;
|
||||||
|
|
||||||
@ -34,6 +35,9 @@ const {
|
|||||||
},
|
},
|
||||||
Navigation
|
Navigation
|
||||||
} = Renderer;
|
} = Renderer;
|
||||||
|
const {
|
||||||
|
UserPreferences,
|
||||||
|
} = Common;
|
||||||
|
|
||||||
|
|
||||||
export interface NodeMenuProps extends Renderer.Component.KubeObjectMenuProps<Node> {
|
export interface NodeMenuProps extends Renderer.Component.KubeObjectMenuProps<Node> {
|
||||||
@ -44,6 +48,7 @@ export function NodeMenu(props: NodeMenuProps) {
|
|||||||
|
|
||||||
if (!node) return null;
|
if (!node) return null;
|
||||||
const nodeName = node.getName();
|
const nodeName = node.getName();
|
||||||
|
const kubectlPath = inspect(UserPreferences.getKubectlPath(), false, null, false);
|
||||||
|
|
||||||
const sendToTerminal = (command: string) => {
|
const sendToTerminal = (command: string) => {
|
||||||
terminalStore.sendCommand(command, {
|
terminalStore.sendCommand(command, {
|
||||||
@ -62,15 +67,15 @@ export function NodeMenu(props: NodeMenuProps) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const cordon = () => {
|
const cordon = () => {
|
||||||
sendToTerminal(`kubectl cordon ${nodeName}`);
|
sendToTerminal(`${kubectlPath} cordon ${nodeName}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const unCordon = () => {
|
const unCordon = () => {
|
||||||
sendToTerminal(`kubectl uncordon ${nodeName}`);
|
sendToTerminal(`${kubectlPath} uncordon ${nodeName}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const drain = () => {
|
const drain = () => {
|
||||||
const command = `kubectl drain ${nodeName} --delete-local-data --ignore-daemonsets --force`;
|
const command = `${kubectlPath} drain ${nodeName} --delete-local-data --ignore-daemonsets --force`;
|
||||||
|
|
||||||
ConfirmDialog.open({
|
ConfirmDialog.open({
|
||||||
ok: () => sendToTerminal(command),
|
ok: () => sendToTerminal(command),
|
||||||
|
|||||||
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { Renderer, Common } from "@k8slens/extensions";
|
import { Renderer, Common } from "@k8slens/extensions";
|
||||||
|
import { inspect } from "util";
|
||||||
|
|
||||||
type Pod = Renderer.K8sApi.Pod;
|
type Pod = Renderer.K8sApi.Pod;
|
||||||
|
|
||||||
@ -39,6 +40,7 @@ const {
|
|||||||
} = Renderer;
|
} = Renderer;
|
||||||
const {
|
const {
|
||||||
Util,
|
Util,
|
||||||
|
UserPreferences,
|
||||||
} = Common;
|
} = Common;
|
||||||
|
|
||||||
export interface PodAttachMenuProps extends Renderer.Component.KubeObjectMenuProps<Pod> {
|
export interface PodAttachMenuProps extends Renderer.Component.KubeObjectMenuProps<Pod> {
|
||||||
@ -47,18 +49,29 @@ export interface PodAttachMenuProps extends Renderer.Component.KubeObjectMenuPro
|
|||||||
export class PodAttachMenu extends React.Component<PodAttachMenuProps> {
|
export class PodAttachMenu extends React.Component<PodAttachMenuProps> {
|
||||||
async attachToPod(container?: string) {
|
async attachToPod(container?: string) {
|
||||||
const { object: pod } = this.props;
|
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") {
|
if (window.navigator.platform !== "Win32") {
|
||||||
command = `exec ${command}`;
|
commandParts.unshift("exec");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (container) {
|
||||||
|
commandParts.push("-c", container);
|
||||||
}
|
}
|
||||||
|
|
||||||
const shell = createTerminalTab({
|
const shell = createTerminalTab({
|
||||||
title: `Pod: ${pod.getName()} (namespace: ${pod.getNs()}) [Attached]`
|
title: `Pod: ${pod.getName()} (namespace: ${pod.getNs()}) [Attached]`
|
||||||
});
|
});
|
||||||
|
|
||||||
terminalStore.sendCommand(command, {
|
terminalStore.sendCommand(commandParts.join(" "), {
|
||||||
enter: true,
|
enter: true,
|
||||||
tabId: shell.id
|
tabId: shell.id
|
||||||
});
|
});
|
||||||
|
|||||||
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { Renderer, Common } from "@k8slens/extensions";
|
import { Renderer, Common } from "@k8slens/extensions";
|
||||||
|
import { inspect } from "util";
|
||||||
|
|
||||||
type Pod = Renderer.K8sApi.Pod;
|
type Pod = Renderer.K8sApi.Pod;
|
||||||
|
|
||||||
@ -39,6 +40,7 @@ const {
|
|||||||
} = Renderer;
|
} = Renderer;
|
||||||
const {
|
const {
|
||||||
Util,
|
Util,
|
||||||
|
UserPreferences,
|
||||||
} = Common;
|
} = Common;
|
||||||
|
|
||||||
export interface PodShellMenuProps extends Renderer.Component.KubeObjectMenuProps<Pod> {
|
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> {
|
export class PodShellMenu extends React.Component<PodShellMenuProps> {
|
||||||
async execShell(container?: string) {
|
async execShell(container?: string) {
|
||||||
Navigation.hideDetails();
|
|
||||||
const { object: pod } = this.props;
|
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") {
|
if (window.navigator.platform !== "Win32") {
|
||||||
command = `exec ${command}`;
|
commandParts.unshift("exec");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (container) {
|
||||||
|
commandParts.push("-c", container);
|
||||||
|
}
|
||||||
|
|
||||||
|
commandParts.push("--");
|
||||||
|
|
||||||
if (pod.getSelectedNodeOs() === "windows") {
|
if (pod.getSelectedNodeOs() === "windows") {
|
||||||
command = `${command} powershell`;
|
commandParts.push("powershell");
|
||||||
} else {
|
} else {
|
||||||
command = `${command} sh -c "clear; (bash || ash || sh)"`;
|
commandParts.push('sh -c "clear; (bash || ash || sh)"');
|
||||||
}
|
}
|
||||||
|
|
||||||
const shell = createTerminalTab({
|
const shell = createTerminalTab({
|
||||||
title: `Pod: ${pod.getName()} (namespace: ${pod.getNs()})`
|
title: `Pod: ${pod.getName()} (namespace: ${pod.getNs()})`
|
||||||
});
|
});
|
||||||
|
|
||||||
terminalStore.sendCommand(command, {
|
terminalStore.sendCommand(commandParts.join(" "), {
|
||||||
enter: true,
|
enter: true,
|
||||||
tabId: shell.id
|
tabId: shell.id
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Navigation.hideDetails();
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|||||||
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
import { getAppVersion } from "../../common/utils";
|
import { getAppVersion } from "../../common/utils";
|
||||||
import { ExtensionsStore } from "../extensions-store";
|
import { ExtensionsStore } from "../extensions-store";
|
||||||
|
import * as Preferences from "./user-preferences";
|
||||||
|
|
||||||
export const version = getAppVersion();
|
export const version = getAppVersion();
|
||||||
export { isSnap, isWindows, isMac, isLinux, appName, slackUrl, issuesTrackerUrl } from "../../common/vars";
|
export { isSnap, isWindows, isMac, isLinux, appName, slackUrl, issuesTrackerUrl } from "../../common/vars";
|
||||||
@ -28,3 +29,5 @@ export { isSnap, isWindows, isMac, isLinux, appName, slackUrl, issuesTrackerUrl
|
|||||||
export function getEnabledExtensions(): string[] {
|
export function getEnabledExtensions(): string[] {
|
||||||
return ExtensionsStore.getInstance().enabledExtensions;
|
return ExtensionsStore.getInstance().enabledExtensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export { Preferences };
|
||||||
|
|||||||
@ -35,5 +35,5 @@ export {
|
|||||||
Store,
|
Store,
|
||||||
Types,
|
Types,
|
||||||
Util,
|
Util,
|
||||||
logger
|
logger,
|
||||||
};
|
};
|
||||||
|
|||||||
27
src/extensions/common-api/user-preferences.ts
Normal file
27
src/extensions/common-api/user-preferences.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 OpenLens Authors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { UserStore } from "../../common/user-store";
|
||||||
|
import { bundledKubectlPath } from "../../main/kubectl";
|
||||||
|
|
||||||
|
export function getKubectlPath(): string {
|
||||||
|
return UserStore.getInstance().kubectlBinariesPath || bundledKubectlPath();
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user