Skip to content

Commit

Permalink
fix styling and existing check for no CQ
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin <[email protected]>
  • Loading branch information
KPostOffice committed Dec 4, 2024
1 parent 3607ad0 commit 3b09d3d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { Bullseye, Alert, Spinner } from '@patternfly/react-core';
import { ClusterQueueKind, LocalQueueKind, WorkloadKind } from '~/k8sTypes';
import { FetchStateObject } from '~/types';
import { DEFAULT_LIST_FETCH_STATE, DEFAULT_VALUE_FETCH_STATE } from '~/utilities/const';
import { DEFAULT_LIST_FETCH_STATE } from '~/utilities/const';
import { SupportedArea, conditionalArea } from '~/concepts/areas';
import useSyncPreferredProject from '~/concepts/projects/useSyncPreferredProject';
import { ProjectsContext, byName } from '~/concepts/projects/ProjectsContext';
Expand Down Expand Up @@ -66,7 +66,6 @@ export const DistributedWorkloadsContextProvider =
const clusterQueues = useMakeFetchObject<ClusterQueueKind[]>(useClusterQueues(refreshRate));
// We only support one ClusterQueue, but if the user has created multiple we use the first one with resourceGroups


const workloads = useMakeFetchObject<WorkloadKind[]>(useWorkloads(namespace, refreshRate));

const projectCurrentMetrics = useDWProjectCurrentMetrics(
Expand Down
14 changes: 12 additions & 2 deletions frontend/src/concepts/distributedWorkloads/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,20 @@ describe('getQueueRequestedResources', () => {

describe('getTotalSharedQuota', () => {
it('correctly parses and adds up total resources from clusterQueue resourceGroups', () => {
const mockClusterQueue = mockClusterQueueK8sResource({});
expect(getTotalSharedQuota(mockClusterQueue)).toEqual({
const mockClusterQueues = [mockClusterQueueK8sResource({})];
expect(getTotalSharedQuota(mockClusterQueues)).toEqual({
cpuCoresRequested: 100,
memoryBytesRequested: 68719476736,
} satisfies WorkloadRequestedResources);
});
it('correctley parses and adds up total resources from multiple clusterQueues', () => {
const mockClusterQueues = [
mockClusterQueueK8sResource({ name: 'test-clusterqueue-1' }),
mockClusterQueueK8sResource({ name: 'test-clusterqueue-2' }),
];
expect(getTotalSharedQuota(mockClusterQueues)).toEqual({
cpuCoresRequested: 200,
memoryBytesRequested: 137438953472,
} satisfies WorkloadRequestedResources);
});
});
32 changes: 16 additions & 16 deletions frontend/src/concepts/distributedWorkloads/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,23 +244,23 @@ export const getTotalSharedQuota = (
clusterQueues?: ClusterQueueKind[],
): WorkloadRequestedResources => {
const sumFromResourceGroups = (units: UnitOption[], attribute: ContainerResourceAttributes) =>
(clusterQueues || []).map(
(clusterQueue) =>
(clusterQueue?.spec.resourceGroups || []).reduce(
(resourceGroupsTotal, resourceGroup) =>
resourceGroupsTotal +
resourceGroup.flavors.reduce((flavorsTotal, flavor) => {
const [value, unit] = convertToUnit(
String(flavor.resources.find(({ name }) => name === attribute)?.nominalQuota || 0),
units,
'',
);
return unit.unit === '' ? flavorsTotal + value : flavorsTotal;
}, 0),
0,
(clusterQueues || [])
.map((clusterQueue) =>
(clusterQueue.spec.resourceGroups || []).reduce(
(resourceGroupsTotal, resourceGroup) =>
resourceGroupsTotal +
resourceGroup.flavors.reduce((flavorsTotal, flavor) => {
const [value, unit] = convertToUnit(
String(flavor.resources.find(({ name }) => name === attribute)?.nominalQuota || 0),
units,
'',
);
return unit.unit === '' ? flavorsTotal + value : flavorsTotal;
}, 0),
0,
),
)
).reduce((total, current) => total + current, 0
);
.reduce((total, current) => total + current, 0);
return {
cpuCoresRequested: sumFromResourceGroups(CPU_UNITS, ContainerResourceAttributes.CPU),
memoryBytesRequested: sumFromResourceGroups(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const GlobalDistributedWorkloadsTabs: React.FC<GlobalDistributedWorkloadsTabsPro
const tabs = useDistributedWorkloadsTabs();
const activeTab = tabs.find(({ id }) => id === activeTabId);
const { namespace } = useParams<{ namespace: string }>();
const { clusterQueue, localQueues } = React.useContext(DistributedWorkloadsContext);
const requiredFetches = [clusterQueue, localQueues];
const { clusterQueues, localQueues } = React.useContext(DistributedWorkloadsContext);
const requiredFetches = [clusterQueues, localQueues];
const error = requiredFetches.find((f) => !!f.error)?.error;
const loaded = requiredFetches.every((f) => f.loaded);

Expand All @@ -53,9 +53,11 @@ const GlobalDistributedWorkloadsTabs: React.FC<GlobalDistributedWorkloadsTabsPro
return <LoadingState />;
}

if (!clusterQueue.data || localQueues.data.length === 0) {
const nonAdmin = !clusterQueue.data;
const title = `Configure the ${!clusterQueue.data ? 'cluster queue' : 'project queue'}`;
if (clusterQueues.data.length === 0 || localQueues.data.length === 0) {
const nonAdmin = clusterQueues.data.length === 0;
const title = `Configure the ${
clusterQueues.data.length === 0 ? 'cluster queue' : 'project queue'
}`;
const message = nonAdmin
? 'Ask your cluster admin to configure the cluster queue.'
: 'Configure the queue for this project, or select a different project.';
Expand Down

0 comments on commit 3b09d3d

Please sign in to comment.