Skip to content

Commit

Permalink
frontend: add node shell
Browse files Browse the repository at this point in the history
Fixes headlamp-k8s#996

Signed-off-by: farodin91 <[email protected]>
  • Loading branch information
farodin91 committed Feb 1, 2024
1 parent b52f766 commit be70ef5
Show file tree
Hide file tree
Showing 19 changed files with 431 additions and 146 deletions.
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 @@ -6,7 +6,7 @@ import React from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch } from 'react-redux';
import { useHistory } 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 } from '../../../lib/k8s/apiProxy';
import { setConfig } from '../../../redux/configSlice';
Expand Down Expand Up @@ -53,6 +53,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 classes = useStyles();
Expand Down Expand Up @@ -127,10 +128,32 @@ export default function SettingsCluster() {
};
}, [userDefaultNamespace]);

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;
}

if (!cluster) {
return null;
}
Expand Down Expand Up @@ -163,6 +186,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 isValidNewAllowedNamespace = isValidNamespaceFormat(newAllowedNamespace);
const invalidNamespaceMessage = t(
Expand Down Expand Up @@ -295,6 +326,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).'
)}
InputProps={{
endAdornment: isEditingNodeShellLinuxImage() ? (
<Icon
width={24}
color={theme.palette.text.secondary}
icon="mdi:progress-check"
/>
) : (
<Icon width={24} icon="mdi:check-bold" />
),
className: classes.input,
}}
/>
),
},
]}
/>
</SectionBox>
Expand Down
Loading

0 comments on commit be70ef5

Please sign in to comment.