Skip to content

Commit

Permalink
Hide and un-schedulable sizes from the Size selection (opendatahub-io…
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-phillips-18 authored Aug 27, 2021
1 parent f5fe431 commit 76aa6dd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
38 changes: 24 additions & 14 deletions jupyterhub_singleuser_profiles/ui/src/SizesForm/SizesForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ const SizesForm: React.FC<ImageFormProps> = ({ uiConfig }) => {
return;
}
const promises = sizeList.map((size) => APIGet(`${SINGLE_SIZE_PATH}/${size}`));
Promise.all(promises).then((results) => {
Promise.all(promises).then((results: SizeDescription[]) => {
if (!cancelled) {
setSizeDescriptions(results as SizeDescription[]);
setSizeDescriptions(results);
}
});
return () => {
Expand Down Expand Up @@ -96,20 +96,30 @@ const SizesForm: React.FC<ImageFormProps> = ({ uiConfig }) => {
['Default'],
);

const getDescription = (size: string): string => {
const description = sizeDescriptions?.find((desc) => desc?.name === size);
if (description) {
return (
`Limits: ${description.resources.limits.cpu} CPU, ${description.resources.limits.memory} Memory ` +
`Requests: ${description.resources.requests.cpu} CPU, ${description.resources.requests.memory} Memory`
return sizes.reduce((acc, size) => {
const sizeDescription = sizeDescriptions?.find((desc) => desc?.name === size);
if (!sizeDescription) {
acc.push(
<SelectOption
key={size}
value={size}
description="Resources set based on administrator configurations"
/>,
);
} else if (sizeDescription.schedulable !== false) {
acc.push(
<SelectOption
key={size}
value={size}
description={
`Limits: ${sizeDescription.resources.limits.cpu} CPU, ${sizeDescription.resources.limits.memory} Memory ` +
`Requests: ${sizeDescription.resources.requests.cpu} CPU, ${sizeDescription.resources.requests.memory} Memory`
}
/>,
);
}
return 'Resources set based on administrator configurations';
};

return sizes.map((size) => (
<SelectOption key={size} value={size} description={getDescription(size)} />
));
return acc;
}, [] as React.ReactElement[]);
}, [sizeList, sizeDescriptions]);

const gpuOptions = React.useMemo(() => {
Expand Down
19 changes: 18 additions & 1 deletion jupyterhub_singleuser_profiles/ui/src/__mock__/mockData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type MockDataType = {
['size/Small']: SizeDescription;
['size/Medium']: SizeDescription;
['size/Large']: SizeDescription;
['size/Huge']: SizeDescription;
[UI_CONFIG_PATH]: UiConfigType;
[DEFAULT_IMAGE_PATH]: string;
};
Expand All @@ -26,7 +27,7 @@ export const mockData: MockDataType = {
last_selected_size: 'Default',
},
[DEFAULT_IMAGE_PATH]: 's2i-generic-data-science-notebook:v0.0.4',
[SIZES_PATH]: ['Small', 'Medium', 'Large'],
[SIZES_PATH]: ['Small', 'Medium', 'Large', 'Huge'],
[IMAGE_PATH]: [
{
description:
Expand Down Expand Up @@ -390,6 +391,7 @@ export const mockData: MockDataType = {
memory: '1Gi',
},
},
schedulable: true,
},
['size/Medium']: {
name: 'Medium',
Expand All @@ -403,6 +405,7 @@ export const mockData: MockDataType = {
memory: '2Gi',
},
},
schedulable: true,
},
['size/Large']: {
name: 'Large',
Expand All @@ -417,6 +420,20 @@ export const mockData: MockDataType = {
},
},
},
['size/Huge']: {
name: 'Huge',
resources: {
limits: {
cpu: 16,
memory: '18Gi',
},
requests: {
cpu: 8,
memory: '8Gi',
},
},
schedulable: false,
},
[UI_CONFIG_PATH]: {
envVarConfig: {
categories: [
Expand Down
1 change: 1 addition & 0 deletions jupyterhub_singleuser_profiles/ui/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export type SizeDescription = {
memory: string;
};
};
schedulable?: boolean;
};

//
Expand Down

0 comments on commit 76aa6dd

Please sign in to comment.