Skip to content

Commit

Permalink
Merge pull request opendatahub-io#2940 from rsun19/k8-model-refactor
Browse files Browse the repository at this point in the history
refactored k8 resources
  • Loading branch information
openshift-merge-bot[bot] authored Jun 24, 2024
2 parents 9cbc8b3 + f39488f commit 39ec5ca
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 414 deletions.
15 changes: 3 additions & 12 deletions frontend/src/api/k8s/__tests__/clusterQueues.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { k8sListResourceItems } from '@openshift/dynamic-plugin-sdk-utils';
import { mockClusterQueueK8sResource } from '~/__mocks__/mockClusterQueueK8sResource';
import { ClusterQueueKind } from '~/k8sTypes';
import { listClusterQueues } from '~/api/k8s/clusterQueues';
import { ClusterQueueModel } from '~/api/models/kueue';

jest.mock('@openshift/dynamic-plugin-sdk-utils', () => ({
k8sListResourceItems: jest.fn(),
Expand All @@ -16,12 +17,7 @@ describe('listClusterQueues', () => {
k8sListResourceItemsMock.mockResolvedValue([clusterQueueMock]);
const result = await listClusterQueues();
expect(k8sListResourceItemsMock).toHaveBeenCalledWith({
model: {
apiGroup: 'kueue.x-k8s.io',
apiVersion: 'v1beta1',
kind: 'ClusterQueue',
plural: 'clusterqueues',
},
model: ClusterQueueModel,
queryOptions: {},
});
expect(k8sListResourceItemsMock).toHaveBeenCalledTimes(1);
Expand All @@ -33,12 +29,7 @@ describe('listClusterQueues', () => {
await expect(listClusterQueues()).rejects.toThrow('error1');
expect(k8sListResourceItemsMock).toHaveBeenCalledTimes(1);
expect(k8sListResourceItemsMock).toHaveBeenCalledWith({
model: {
apiGroup: 'kueue.x-k8s.io',
apiVersion: 'v1beta1',
kind: 'ClusterQueue',
plural: 'clusterqueues',
},
model: ClusterQueueModel,
queryOptions: {},
});
});
Expand Down
42 changes: 7 additions & 35 deletions frontend/src/api/k8s/__tests__/configMaps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ describe('createConfigMap', () => {
expect(k8sCreateResourceMock).toHaveBeenCalledTimes(1);
expect(k8sCreateResourceMock).toHaveBeenCalledWith({
fetchOptions: { requestInit: {} },
model: {
apiVersion: 'v1',
kind: 'ConfigMap',
plural: 'configmaps',
},
model: ConfigMapModel,
queryOptions: { queryParams: {} },
resource: configMapMock,
});
Expand All @@ -112,11 +108,7 @@ describe('createConfigMap', () => {
expect(k8sCreateResourceMock).toHaveBeenCalledTimes(1);
expect(k8sCreateResourceMock).toHaveBeenCalledWith({
fetchOptions: { requestInit: {} },
model: {
apiVersion: 'v1',
kind: 'ConfigMap',
plural: 'configmaps',
},
model: ConfigMapModel,
queryOptions: { queryParams: {} },
resource: configMapMock,
});
Expand All @@ -133,11 +125,7 @@ describe('replaceConfigMap', () => {
expect(k8sUpdateResourceMock).toHaveBeenCalledTimes(1);
expect(k8sUpdateResourceMock).toHaveBeenCalledWith({
fetchOptions: { requestInit: {} },
model: {
apiVersion: 'v1',
kind: 'ConfigMap',
plural: 'configmaps',
},
model: ConfigMapModel,
queryOptions: { queryParams: {} },
resource: configMapMock,
});
Expand All @@ -153,11 +141,7 @@ describe('replaceConfigMap', () => {
expect(k8sUpdateResourceMock).toHaveBeenCalledTimes(1);
expect(k8sUpdateResourceMock).toHaveBeenCalledWith({
fetchOptions: { requestInit: {} },
model: {
apiVersion: 'v1',
kind: 'ConfigMap',
plural: 'configmaps',
},
model: ConfigMapModel,
queryOptions: { queryParams: {} },
resource: configMapMock,
});
Expand All @@ -174,11 +158,7 @@ describe('deleteConfigMap', () => {
expect(k8sDeleteResourceMock).toHaveBeenCalledTimes(1);
expect(k8sDeleteResourceMock).toHaveBeenCalledWith({
fetchOptions: { requestInit: {} },
model: {
apiVersion: 'v1',
kind: 'ConfigMap',
plural: 'configmaps',
},
model: ConfigMapModel,
queryOptions: {
name: configMapName,
ns: namespace,
Expand All @@ -196,11 +176,7 @@ describe('deleteConfigMap', () => {
expect(k8sDeleteResourceMock).toHaveBeenCalledTimes(1);
expect(k8sDeleteResourceMock).toHaveBeenCalledWith({
fetchOptions: { requestInit: {} },
model: {
apiVersion: 'v1',
kind: 'ConfigMap',
plural: 'configmaps',
},
model: ConfigMapModel,
queryOptions: {
name: configMapName,
ns: namespace,
Expand All @@ -216,11 +192,7 @@ describe('deleteConfigMap', () => {
expect(k8sDeleteResourceMock).toHaveBeenCalledTimes(1);
expect(k8sDeleteResourceMock).toHaveBeenCalledWith({
fetchOptions: { requestInit: {} },
model: {
apiVersion: 'v1',
kind: 'ConfigMap',
plural: 'configmaps',
},
model: ConfigMapModel,
queryOptions: {
name: configMapName,
ns: namespace,
Expand Down
35 changes: 5 additions & 30 deletions frontend/src/api/k8s/__tests__/inferenceServices.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,7 @@ describe('listInferenceService', () => {
expect(k8sListResourceMock).toHaveBeenCalledTimes(1);
expect(k8sListResourceMock).toHaveBeenCalledWith({
fetchOptions: { requestInit: {} },
model: {
apiGroup: 'serving.kserve.io',
apiVersion: 'v1beta1',
kind: 'InferenceService',
plural: 'inferenceservices',
},
model: InferenceServiceModel,
queryOptions: { queryParams: {} },
});
});
Expand All @@ -344,12 +339,7 @@ describe('listInferenceService', () => {
expect(k8sListResourceMock).toHaveBeenCalledTimes(1);
expect(k8sListResourceMock).toHaveBeenCalledWith({
fetchOptions: { requestInit: {} },
model: {
apiGroup: 'serving.kserve.io',
apiVersion: 'v1beta1',
kind: 'InferenceService',
plural: 'inferenceservices',
},
model: InferenceServiceModel,
queryOptions: { queryParams: {} },
});
});
Expand Down Expand Up @@ -598,12 +588,7 @@ describe('deleteInferenceService', () => {
fetchOptions: {
requestInit: {},
},
model: {
apiGroup: 'serving.kserve.io',
apiVersion: 'v1beta1',
kind: 'InferenceService',
plural: 'inferenceservices',
},
model: InferenceServiceModel,
queryOptions: {
name: 'test',
ns: 'test-project',
Expand All @@ -622,12 +607,7 @@ describe('deleteInferenceService', () => {
fetchOptions: {
requestInit: {},
},
model: {
apiGroup: 'serving.kserve.io',
apiVersion: 'v1beta1',
kind: 'InferenceService',
plural: 'inferenceservices',
},
model: InferenceServiceModel,
queryOptions: {
name: 'test',
ns: 'test-project',
Expand All @@ -645,12 +625,7 @@ describe('deleteInferenceService', () => {
fetchOptions: {
requestInit: {},
},
model: {
apiGroup: 'serving.kserve.io',
apiVersion: 'v1beta1',
kind: 'InferenceService',
plural: 'inferenceservices',
},
model: InferenceServiceModel,
queryOptions: {
name: 'test',
ns: 'test-project',
Expand Down
15 changes: 3 additions & 12 deletions frontend/src/api/k8s/__tests__/localQueues.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { k8sListResourceItems } from '@openshift/dynamic-plugin-sdk-utils';
import { mockLocalQueueK8sResource } from '~/__mocks__/mockLocalQueueK8sResource';
import { LocalQueueKind } from '~/k8sTypes';
import { listLocalQueues } from '~/api/k8s/localQueues';
import { LocalQueueModel } from '~/api/models/kueue';

jest.mock('@openshift/dynamic-plugin-sdk-utils', () => ({
k8sListResourceItems: jest.fn(),
Expand All @@ -19,12 +20,7 @@ describe('listLocalQueues', () => {
k8sListResourceItemsMock.mockResolvedValue([mockedLocalQueue]);
const result = await listLocalQueues('test-project');
expect(k8sListResourceItemsMock).toHaveBeenCalledWith({
model: {
apiGroup: 'kueue.x-k8s.io',
apiVersion: 'v1beta1',
kind: 'LocalQueue',
plural: 'localqueues',
},
model: LocalQueueModel,
queryOptions: { ns: 'test-project' },
});
expect(k8sListResourceItemsMock).toHaveBeenCalledTimes(1);
Expand All @@ -36,12 +32,7 @@ describe('listLocalQueues', () => {
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',
},
model: LocalQueueModel,
queryOptions: { ns: 'test-project' },
});
});
Expand Down
12 changes: 3 additions & 9 deletions frontend/src/api/k8s/__tests__/projects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
updateProject,
useProjects,
} from '~/api/k8s/projects';
import { ProjectModel } from '~/api/models';
import { ProjectModel, ProjectRequestModel } from '~/api/models';
import { ODH_PRODUCT_NAME } from '~/utilities/const';
import { NamespaceApplicationCase } from '~/pages/projects/types';
import { ProjectKind } from '~/k8sTypes';
Expand Down Expand Up @@ -118,12 +118,6 @@ describe('createProject', () => {
applied,
},
});
const projectRequest = {
apiGroup: 'project.openshift.io',
apiVersion: 'v1',
kind: 'ProjectRequest',
plural: 'projectrequests',
};

it('should create a project when k8s name is given', async () => {
const projectMock = mockProjectK8sResource({ k8sName });
Expand All @@ -133,7 +127,7 @@ describe('createProject', () => {
expect(result).toStrictEqual(k8sName);
expect(k8sCreateResourceMock).toHaveBeenCalledTimes(1);
expect(k8sCreateResourceMock).toHaveBeenCalledWith({
model: projectRequest,
model: ProjectRequestModel,
resource: {
apiVersion: 'project.openshift.io/v1',
kind: 'ProjectRequest',
Expand All @@ -156,7 +150,7 @@ describe('createProject', () => {
expect(result).toStrictEqual(displayName);
expect(k8sCreateResourceMock).toHaveBeenCalledTimes(1);
expect(k8sCreateResourceMock).toHaveBeenCalledWith({
model: projectRequest,
model: ProjectRequestModel,
resource: {
apiVersion: 'project.openshift.io/v1',
kind: 'ProjectRequest',
Expand Down
19 changes: 10 additions & 9 deletions frontend/src/api/k8s/__tests__/pvcs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { mock200Status, mock404Error } from '~/__mocks__/mockK8sStatus';
import { mockPVCK8sResource } from '~/__mocks__/mockPVCK8sResource';
import { assemblePvc, createPvc, deletePvc, getDashboardPvcs, updatePvc } from '~/api/k8s/pvcs';
import { PVCModel } from '~/api/models/k8s';
import { PersistentVolumeClaimKind } from '~/k8sTypes';
import { CreatingStorageObject } from '~/pages/projects/types';

Expand Down Expand Up @@ -80,7 +81,7 @@ describe('getDashboardPvcs', () => {
k8sListResourceItemsMock.mockResolvedValue([pvcMock]);
const result = await getDashboardPvcs('projectName');
expect(k8sListResourceItemsMock).toHaveBeenCalledWith({
model: { apiVersion: 'v1', kind: 'PersistentVolumeClaim', plural: 'persistentvolumeclaims' },
model: PVCModel,
queryOptions: {
ns: 'projectName',
queryParams: { labelSelector: 'opendatahub.io/dashboard=true' },
Expand All @@ -94,7 +95,7 @@ describe('getDashboardPvcs', () => {
await expect(getDashboardPvcs('projectName')).rejects.toThrow('error1');
expect(k8sListResourceItemsMock).toHaveBeenCalledTimes(1);
expect(k8sListResourceItemsMock).toHaveBeenCalledWith({
model: { apiVersion: 'v1', kind: 'PersistentVolumeClaim', plural: 'persistentvolumeclaims' },
model: PVCModel,
queryOptions: {
ns: 'projectName',
queryParams: { labelSelector: 'opendatahub.io/dashboard=true' },
Expand All @@ -109,7 +110,7 @@ describe('createPvc', () => {
const result = await createPvc(data, 'namespace');
expect(k8sCreateResourceMock).toHaveBeenCalledWith({
fetchOptions: { requestInit: {} },
model: { apiVersion: 'v1', kind: 'PersistentVolumeClaim', plural: 'persistentvolumeclaims' },
model: PVCModel,
queryOptions: { queryParams: {} },
resource: createAssemblePvcs(['ReadWriteOnce']),
});
Expand All @@ -122,7 +123,7 @@ describe('createPvc', () => {
await expect(createPvc(data, 'namespace')).rejects.toThrow('error1');
expect(k8sCreateResourceMock).toHaveBeenCalledWith({
fetchOptions: { requestInit: {} },
model: { apiVersion: 'v1', kind: 'PersistentVolumeClaim', plural: 'persistentvolumeclaims' },
model: PVCModel,
queryOptions: { queryParams: {} },
resource: createAssemblePvcs(['ReadWriteOnce']),
});
Expand All @@ -136,7 +137,7 @@ describe('updatePvc', () => {
const result = await updatePvc(data, assemblePvcResult, 'namespace');
expect(k8sUpdateResourceMock).toHaveBeenCalledWith({
fetchOptions: { requestInit: {} },
model: { apiVersion: 'v1', kind: 'PersistentVolumeClaim', plural: 'persistentvolumeclaims' },
model: PVCModel,
queryOptions: { queryParams: {} },
resource: createAssemblePvcs(['ReadWriteOnce']),
});
Expand All @@ -150,7 +151,7 @@ describe('updatePvc', () => {
expect(k8sUpdateResourceMock).toHaveBeenCalledTimes(1);
expect(k8sUpdateResourceMock).toHaveBeenCalledWith({
fetchOptions: { requestInit: {} },
model: { apiVersion: 'v1', kind: 'PersistentVolumeClaim', plural: 'persistentvolumeclaims' },
model: PVCModel,
queryOptions: { queryParams: {} },
resource: createAssemblePvcs(['ReadWriteOnce']),
});
Expand All @@ -163,7 +164,7 @@ describe('deletePvc', () => {
k8sDeleteResourceMock.mockResolvedValue(mockK8sStatus);
const result = await deletePvc('pvcName', 'namespace');
expect(k8sDeleteResourceMock).toHaveBeenCalledWith({
model: { apiVersion: 'v1', kind: 'PersistentVolumeClaim', plural: 'persistentvolumeclaims' },
model: PVCModel,
queryOptions: { name: 'pvcName', ns: 'namespace' },
});
expect(k8sDeleteResourceMock).toHaveBeenCalledTimes(1);
Expand All @@ -175,7 +176,7 @@ describe('deletePvc', () => {
k8sDeleteResourceMock.mockResolvedValue(mockK8sStatus);
const result = await deletePvc('pvcName', 'namespace');
expect(k8sDeleteResourceMock).toHaveBeenCalledWith({
model: { apiVersion: 'v1', kind: 'PersistentVolumeClaim', plural: 'persistentvolumeclaims' },
model: PVCModel,
queryOptions: { name: 'pvcName', ns: 'namespace' },
});
expect(k8sDeleteResourceMock).toHaveBeenCalledTimes(1);
Expand All @@ -187,7 +188,7 @@ describe('deletePvc', () => {
await expect(deletePvc('pvcName', 'namespace')).rejects.toThrow('error1');
expect(k8sDeleteResourceMock).toHaveBeenCalledTimes(1);
expect(k8sDeleteResourceMock).toHaveBeenCalledWith({
model: { apiVersion: 'v1', kind: 'PersistentVolumeClaim', plural: 'persistentvolumeclaims' },
model: PVCModel,
queryOptions: { name: 'pvcName', ns: 'namespace' },
});
});
Expand Down
Loading

0 comments on commit 39ec5ca

Please sign in to comment.