-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2650 from mturley/dw-localqueues
DW: Fetch LocalQueues, pass them down in context, use them for "quota is not set" empty state
- Loading branch information
Showing
14 changed files
with
466 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { LocalQueueKind } from '~/k8sTypes'; | ||
import { genUID } from '~/__mocks__/mockUtils'; | ||
|
||
type MockResourceConfigType = { | ||
name?: string; | ||
namespace?: string; | ||
}; | ||
|
||
export const mockLocalQueueK8sResource = ({ | ||
name = 'test-local-queue', | ||
namespace = 'test-project', | ||
}: MockResourceConfigType): LocalQueueKind => ({ | ||
apiVersion: 'kueue.x-k8s.io/v1beta1', | ||
kind: 'LocalQueue', | ||
metadata: { | ||
creationTimestamp: '2024-03-26T14:12:10Z', | ||
generation: 1, | ||
name, | ||
namespace, | ||
uid: genUID('localqueue'), | ||
}, | ||
spec: { | ||
clusterQueue: 'test-cluster-queue', | ||
}, | ||
status: { | ||
pendingWorkloads: 0, | ||
reservingWorkloads: 0, | ||
admittedWorkloads: 0, | ||
conditions: [ | ||
{ | ||
lastTransitionTime: '2024-03-26T15:49:12Z', | ||
message: 'Can submit new workloads to clusterQueue', | ||
reason: 'Ready', | ||
status: 'True', | ||
type: 'Active', | ||
}, | ||
], | ||
flavorUsage: [ | ||
{ | ||
name: 'test-flavor', | ||
resources: [ | ||
{ name: 'cpu', total: '0' }, | ||
{ name: 'memory', total: '0' }, | ||
{ name: 'nvidia.com/gpu', total: '0' }, | ||
], | ||
}, | ||
], | ||
flavorsReservation: [ | ||
{ | ||
name: 'test-flavor', | ||
resources: [ | ||
{ name: 'cpu', total: '0' }, | ||
{ name: 'memory', total: '0' }, | ||
{ name: 'nvidia.com/gpu', total: '0' }, | ||
], | ||
}, | ||
], | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { k8sListResourceItems } from '@openshift/dynamic-plugin-sdk-utils'; | ||
import { mockLocalQueueK8sResource } from '~/__mocks__/mockLocalQueueK8sResource'; | ||
import { LocalQueueKind } from '~/k8sTypes'; | ||
import { listLocalQueues } from '~/api/k8s/localQueues'; | ||
|
||
jest.mock('@openshift/dynamic-plugin-sdk-utils', () => ({ | ||
k8sListResourceItems: jest.fn(), | ||
})); | ||
|
||
const k8sListResourceItemsMock = jest.mocked(k8sListResourceItems<LocalQueueKind>); | ||
|
||
const mockedLocalQueue = mockLocalQueueK8sResource({ | ||
name: 'test-local-queue', | ||
namespace: 'test-project', | ||
}); | ||
|
||
describe('listLocalQueues', () => { | ||
it('should fetch and return localqueues', async () => { | ||
k8sListResourceItemsMock.mockResolvedValue([mockedLocalQueue]); | ||
const result = await listLocalQueues('test-project'); | ||
expect(k8sListResourceItemsMock).toHaveBeenCalledWith({ | ||
model: { | ||
apiGroup: 'kueue.x-k8s.io', | ||
apiVersion: 'v1beta1', | ||
kind: 'LocalQueue', | ||
plural: 'localqueues', | ||
}, | ||
queryOptions: { ns: 'test-project' }, | ||
}); | ||
expect(k8sListResourceItemsMock).toHaveBeenCalledTimes(1); | ||
expect(result).toStrictEqual([mockedLocalQueue]); | ||
}); | ||
|
||
it('should handle errors and rethrow', async () => { | ||
k8sListResourceItemsMock.mockRejectedValue(new Error('error1')); | ||
await expect(listLocalQueues('test-project')).rejects.toThrow('error1'); | ||
expect(k8sListResourceItemsMock).toHaveBeenCalledTimes(1); | ||
expect(k8sListResourceItemsMock).toHaveBeenCalledWith({ | ||
model: { | ||
apiGroup: 'kueue.x-k8s.io', | ||
apiVersion: 'v1beta1', | ||
kind: 'LocalQueue', | ||
plural: 'localqueues', | ||
}, | ||
queryOptions: { ns: 'test-project' }, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.