Skip to content
Merged
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
13 changes: 13 additions & 0 deletions console-extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,19 @@
}
}
},
{
"type": "console.action/resource-provider",
"properties": {
"model": {
"group": "kueue.x-k8s.io",
"version": "v1beta2",
"kind": "LocalQueue"
},
"provider": {
"$codeRef": "localQueueActionsProvider.useLocalQueueActionsProvider"
}
}
},
{
"type": "console.action/resource-provider",
"properties": {
Expand Down
4 changes: 4 additions & 0 deletions locales/en/plugin__pipelines-console-plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"Add when expression": "Add when expression",
"Add workspace": "Add workspace",
"Adding this task may take a few moments.": "Adding this task may take a few moments.",
"Admitted Workloads": "Admitted Workloads",
"Advanced options": "Advanced options",
"All": "All",
"All Clusters": "All Clusters",
Expand Down Expand Up @@ -303,6 +304,7 @@
"Last run duration": "Last run duration",
"Last run status": "Last run status",
"Last run time": "Last run time",
"Last Updated": "Last Updated",
"Last week": "Last week",
"Last year": "Last year",
"Learn more": "Learn more",
Expand All @@ -312,6 +314,7 @@
"Loading clusters": "Loading clusters",
"Loading events...": "Loading events...",
"Local Queue": "Local Queue",
"LocalQueues": "LocalQueues",
"Log snippet": "Log snippet",
"Logs": "Logs",
"Low": "Low",
Expand Down Expand Up @@ -401,6 +404,7 @@
"Password or token for Git authentication. Required if a ca.crt or .gitconfig file is not specified.": "Password or token for Git authentication. Required if a ca.crt or .gitconfig file is not specified.",
"Pause event streaming": "Pause event streaming",
"Pending": "Pending",
"Pending Workloads": "Pending Workloads",
"Per Pipeline": "Per Pipeline",
"Per Repository": "Per Repository",
"Permissions to the mounted drive": "Permissions to the mounted drive",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@
"pipelineRunActionsProvider": "./utils/pipelineRun-actions-provider.tsx",
"taskRunActionsProvider": "./utils/taskRun-actions-provider.tsx",
"approvalTaskActionsProvider": "./utils/approvalTask-actions-provider.tsx",
"clusterQueueActionsProvider": "./utils/clusterQueue-actions-provider.ts"
"clusterQueueActionsProvider": "./utils/clusterQueue-actions-provider.ts",
"localQueueActionsProvider": "./utils/localQueue-actions-provider.ts"
},
"dependencies": {
"@console/pluginAPI": ">=4.22"
Expand Down
61 changes: 61 additions & 0 deletions src/components/hooks/__tests__/useMultiKueueResources.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import {
import { WORKLOAD_KUEUE_UID_LABEL } from '../../../consts';
import {
ClusterQueueModel,
LocalQueueModel,
MultiKueueClusterModel,
WorkloadModel,
} from '../../../models';
import { testHook } from '../../../test-data/utils/hooks-utils';
import {
ClusterQueueKind,
LocalQueueKind,
MultiKueueClusterKind,
PipelineRunKind,
} from '../../../types';
Expand All @@ -20,6 +22,7 @@ import {
useClusterQueues,
useGetClusterQueue,
useGetMultiKueueCluster,
useLocalQueues,
useWorkloads,
} from '../useMultiKueueResources';

Expand Down Expand Up @@ -48,6 +51,12 @@ const clusterQueueGVK = {
kind: ClusterQueueModel.kind,
};

const localQueueGVK = {
group: LocalQueueModel.apiGroup,
version: LocalQueueModel.apiVersion,
kind: LocalQueueModel.kind,
};

const multiKueueClusterGVK = {
group: MultiKueueClusterModel.apiGroup,
version: MultiKueueClusterModel.apiVersion,
Expand Down Expand Up @@ -146,6 +155,10 @@ describe('useGetClusterQueue', () => {
});

describe('useClusterQueues', () => {
beforeEach(() => {
useMultiClusterProxyServiceMock.mockReturnValue({ isHub: true });
});

it('should watch ClusterQueues', () => {
const clusterQueues: ClusterQueueKind[] = [];
useK8sWatchResourceMock.mockReturnValue([clusterQueues, true, null]);
Expand All @@ -158,6 +171,54 @@ describe('useClusterQueues', () => {
});
expect(result.current).toEqual([clusterQueues, true, null]);
});

it('should skip the watch on a non-hub cluster', () => {
useMultiClusterProxyServiceMock.mockReturnValue({ isHub: false });

testHook(() => useClusterQueues());

expect(useK8sWatchResourceMock).toHaveBeenCalledWith(null);
});
});

describe('useLocalQueues', () => {
beforeEach(() => {
useK8sWatchResourceMock.mockReturnValue([[], true, null]);
useMultiClusterProxyServiceMock.mockReturnValue({ isHub: true });
});

it('should watch LocalQueues in the requested namespace', () => {
const localQueues: LocalQueueKind[] = [];
useK8sWatchResourceMock.mockReturnValue([localQueues, true, null]);

const { result } = testHook(() => useLocalQueues('test-namespace'));

expect(useK8sWatchResourceMock).toHaveBeenCalledWith({
isList: true,
groupVersionKind: localQueueGVK,
namespace: 'test-namespace',
namespaced: true,
});
expect(result.current).toEqual([localQueues, true, null]);
});

it('should watch LocalQueues across namespaces for the all-namespaces route', () => {
testHook(() => useLocalQueues('-'));

expect(useK8sWatchResourceMock).toHaveBeenCalledWith({
isList: true,
groupVersionKind: localQueueGVK,
namespaced: true,
});
});

it('should skip the watch on a non-hub cluster', () => {
useMultiClusterProxyServiceMock.mockReturnValue({ isHub: false });

testHook(() => useLocalQueues('test-namespace'));

expect(useK8sWatchResourceMock).toHaveBeenCalledWith(null);
});
});

describe('useWorkloads', () => {
Expand Down
23 changes: 14 additions & 9 deletions src/components/hooks/useMultiKueueResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,21 @@ export const useWorkloads = (
};

export const useClusterQueues = (): [ClusterQueueKind[], boolean, unknown] => {
const { isHub } = useMultiClusterProxyService({});

const watchOptions = useMemo(
() => ({
isList: true,
groupVersionKind: {
group: ClusterQueueModel.apiGroup,
kind: ClusterQueueModel.kind,
version: ClusterQueueModel.apiVersion,
},
}),
[],
() =>
isHub
Comment thread
anwesha-palit-redhat marked this conversation as resolved.
Resolved
? {
isList: true,
groupVersionKind: {
group: ClusterQueueModel.apiGroup,
kind: ClusterQueueModel.kind,
version: ClusterQueueModel.apiVersion,
},
}
: null,
[isHub],
);

return useK8sWatchResource<ClusterQueueKind[]>(watchOptions);
Expand Down
70 changes: 70 additions & 0 deletions src/components/localqueues/LocalQueueRow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import {
getGroupVersionKindForModel,
ResourceLink,
Timestamp,
} from '@openshift-console/dynamic-plugin-sdk';
import {
actionsCellProps,
getNameCellProps,
LazyActionMenu,
} from '@openshift-console/dynamic-plugin-sdk-internal';
import { GetDataViewRows } from '@openshift-console/dynamic-plugin-sdk-internal/lib/api/internal-types';
import { LocalQueueModel } from '../../models';
import { LocalQueueKind } from '../../types';
import { getReferenceForModel } from '../pipelines-overview/utils';
import { localQueueColumnIds } from './useLocalQueuesColumns';
import { getLastUpdatedTimestamp } from './utils';

export const getLocalQueueDataViewRows: GetDataViewRows<LocalQueueKind> = (
data,
columns,
) =>
data.map(({ obj }) => {
const admitted = obj.status?.admittedWorkloads ?? 0;
const pending = obj.status?.pendingWorkloads ?? 0;
const rowCells = {
[localQueueColumnIds.name]: {
cell: (
<ResourceLink
groupVersionKind={getGroupVersionKindForModel(LocalQueueModel)}
name={obj.metadata.name}
namespace={obj.metadata.namespace}
/>
),
props: {
...getNameCellProps('localqueues-list'),
modifier: 'nowrap',
},
},
[localQueueColumnIds.namespace]: {
cell: obj.metadata.namespace,
props: { modifier: 'nowrap' },
},
[localQueueColumnIds.admittedWorkloads]: {
cell: admitted,
props: { modifier: 'nowrap' },
},
[localQueueColumnIds.pendingWorkloads]: {
cell: pending,
props: { modifier: 'nowrap' },
},
[localQueueColumnIds.lastUpdated]: {
cell: <Timestamp timestamp={getLastUpdatedTimestamp(obj)} />,
props: { modifier: 'nowrap' },
},
[localQueueColumnIds.actions]: {
cell: (
<LazyActionMenu
context={{ [getReferenceForModel(LocalQueueModel)]: obj }}
/>
),
props: actionsCellProps,
},
};

return columns.map(({ id }) => ({
id,
cell: rowCells[id]?.cell,
props: rowCells[id]?.props,
}));
});
49 changes: 49 additions & 0 deletions src/components/localqueues/LocalQueuesList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { ListPageBody } from '@openshift-console/dynamic-plugin-sdk';
import { ConsoleDataView } from '@openshift-console/dynamic-plugin-sdk-internal';
import type { FC } from 'react';
import { useTranslation } from 'react-i18next';
import { useParams } from 'react-router';
import { LocalQueueKind } from '../../types';
import { DataViewFilterToolbar } from '../common/DataViewFilterToolbar';
import { useDataViewFilter } from '../hooks/useDataViewFilter';
import { useLocalQueues } from '../hooks/useMultiKueueResources';
import { getLocalQueueDataViewRows } from './LocalQueueRow';
import useLocalQueuesColumns from './useLocalQueuesColumns';

const LocalQueuesList: FC = () => {
const { t } = useTranslation('plugin__pipelines-console-plugin');
const { ns } = useParams();
const namespace = ns ?? '-';
const columns = useLocalQueuesColumns(ns);
const [localQueues, loaded, loadError] = useLocalQueues(namespace);
const { filterValues, onFilterChange, onClearAll, filteredData } =
useDataViewFilter<LocalQueueKind>({
data: localQueues || [],
options: {
getName: (localQueue) => localQueue.metadata.name,
},
});

return (
<ListPageBody>
<DataViewFilterToolbar
filterValues={filterValues}
onFilterChange={onFilterChange}
onClearAll={onClearAll}
hideLabelFilter
/>
<ConsoleDataView<LocalQueueKind>
label={t('LocalQueues')}
columns={columns}
data={filteredData}
loaded={loaded}
loadError={loadError}
getDataViewRows={getLocalQueueDataViewRows}
hideColumnManagement
hideNameLabelFilters
/>
</ListPageBody>
);
};

export default LocalQueuesList;
Loading
Loading