Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend: add node shell #1603

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion frontend/src/components/App/Settings/SettingsCluster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import React from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch } from 'react-redux';
import { useHistory, useLocation } from 'react-router-dom';
import helpers, { ClusterSettings } from '../../../helpers';
import helpers, { ClusterSettings, DEFAULT_NODE_SHELL_LINUX_IMAGE } from '../../../helpers';
import { useCluster, useClustersConf } from '../../../lib/k8s';
import { deleteCluster, parseKubeConfig, renameCluster } from '../../../lib/k8s/apiProxy';
import { setConfig, setStatelessConfig } from '../../../redux/configSlice';
Expand Down Expand Up @@ -85,6 +85,7 @@ export default function SettingsCluster() {
const { t } = useTranslation(['translation']);
const [defaultNamespace, setDefaultNamespace] = React.useState('default');
const [userDefaultNamespace, setUserDefaultNamespace] = React.useState('');
const [nodeShellLinuxImage, setNodeShellLinuxImage] = React.useState('');
const [newAllowedNamespace, setNewAllowedNamespace] = React.useState('');
const [clusterSettings, setClusterSettings] = React.useState<ClusterSettings | null>(null);
const [cluster, setCluster] = React.useState(useCluster() || '');
Expand Down Expand Up @@ -217,10 +218,32 @@ export default function SettingsCluster() {
}
}, [location.search, clusters]);

React.useEffect(() => {
let timeoutHandle: NodeJS.Timeout | null = null;

if (isEditingNodeShellLinuxImage()) {
// We store the node shell image after a timeout.
timeoutHandle = setTimeout(() => {
storeNewNodeShellLinuxImage(nodeShellLinuxImage);
}, 1000);
}

return () => {
if (timeoutHandle) {
clearTimeout(timeoutHandle);
timeoutHandle = null;
}
};
}, [nodeShellLinuxImage]);

function isEditingDefaultNamespace() {
return clusterSettings?.defaultNamespace !== userDefaultNamespace;
}

function isEditingNodeShellLinuxImage() {
return clusterSettings?.nodeShellLinuxImage !== nodeShellLinuxImage;
}

function storeNewAllowedNamespace(namespace: string) {
setNewAllowedNamespace('');
setClusterSettings((settings: ClusterSettings | null) => {
Expand Down Expand Up @@ -265,6 +288,14 @@ export default function SettingsCluster() {
});
}

function storeNewNodeShellLinuxImage(image: string) {
setClusterSettings((settings: ClusterSettings | null) => {
const newSettings = { ...(settings || {}) };
newSettings.nodeShellLinuxImage = image;
return newSettings;
});
}

const isValidDefaultNamespace = isValidNamespaceFormat(userDefaultNamespace);
const isValidCurrentName = isValidClusterNameFormat(newClusterName);
const isValidNewAllowedNamespace = isValidNamespaceFormat(newAllowedNamespace);
Expand Down Expand Up @@ -504,6 +535,35 @@ export default function SettingsCluster() {
</>
),
},
{
name: t('translation|Node Shell Linux Image'),
value: (
<TextField
onChange={event => {
let value = event.target.value;
value = value.replace(' ', '');
setNodeShellLinuxImage(value);
}}
value={nodeShellLinuxImage}
placeholder={DEFAULT_NODE_SHELL_LINUX_IMAGE}
helperText={t(
'translation|The default image is used for dropping a shell into a node (when not specified directly).'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "when not specified directly" refer to?

)}
InputProps={{
endAdornment: isEditingNodeShellLinuxImage() ? (
<Icon
width={24}
color={theme.palette.text.secondary}
icon="mdi:progress-check"
/>
) : (
<Icon width={24} icon="mdi:check-bold" />
),
sx: { maxWidth: 250 },
}}
/>
),
},
]}
/>
</SectionBox>
Expand Down
Loading
Loading