UNPKG

@kinvolk/headlamp-plugin

Version:

The needed infrastructure for building Headlamp plugins.

63 lines (62 loc) 2.99 kB
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; /* * Copyright 2025 The Kubernetes Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { DEFAULT_NODE_SHELL_NAMESPACE, loadClusterSettings } from '../../helpers/clusterSettings'; import { getCluster } from '../../lib/cluster'; import Pod from '../../lib/k8s/pod'; import { ActionButton, AuthVisible } from '../common'; import { NodeShellTerminal } from './NodeShellTerminal'; function isNodeTerminalEnabled(cluster) { if (cluster === null) { return false; } const clusterSettings = loadClusterSettings(cluster); return clusterSettings.nodeShellTerminal?.isEnabled ?? true; } function nodeTerminalNamespace(cluster) { if (cluster === null) { return DEFAULT_NODE_SHELL_NAMESPACE; } const clusterSettings = loadClusterSettings(cluster); return clusterSettings.nodeShellTerminal?.namespace ?? DEFAULT_NODE_SHELL_NAMESPACE; } export function NodeShellAction(props) { const { item } = props; const { t } = useTranslation(['glossary']); const [showShell, setShowShell] = useState(false); if (item === null) { return _jsx(_Fragment, {}); } const cluster = getCluster(); function isLinux(item) { return item?.status?.nodeInfo?.operatingSystem === 'linux'; } const namepsace = nodeTerminalNamespace(cluster); if (!isNodeTerminalEnabled(cluster)) { return _jsx(_Fragment, {}); } return (_jsxs(_Fragment, { children: [_jsx(AuthVisible, { authVerb: "create", item: Pod, namespace: namepsace, children: _jsx(AuthVisible, { item: Pod, namespace: namepsace, authVerb: "get", subresource: "exec", children: _jsx(ActionButton, { description: isLinux(item) ? t('Node Shell') : t('Node shell is not supported in this OS: {{ nodeOS }}', { nodeOS: item?.status?.nodeInfo?.operatingSystem, }), icon: "mdi:console", onClick: () => setShowShell(true), iconButtonProps: { disabled: !isLinux(item), } }) }) }), _jsx(NodeShellTerminal, { open: showShell, title: t('Shell: {{ itemName }}', { itemName: item.metadata.name }), item: item, onClose: () => { setShowShell(false); } }, "terminal")] })); }