From f39488ffad1d81040acb8d557977ab43f841832a Mon Sep 17 00:00:00 2001 From: Robert Sun <107655677+rsun19@users.noreply.github.com> Date: Thu, 20 Jun 2024 23:45:10 -0400 Subject: [PATCH] refactored k8 resources --- .../api/k8s/__tests__/clusterQueues.spec.ts | 15 +- .../src/api/k8s/__tests__/configMaps.spec.ts | 42 +--- .../k8s/__tests__/inferenceServices.spec.ts | 35 +--- .../src/api/k8s/__tests__/localQueues.spec.ts | 15 +- .../src/api/k8s/__tests__/projects.spec.ts | 12 +- frontend/src/api/k8s/__tests__/pvcs.spec.ts | 19 +- .../api/k8s/__tests__/roleBindings.spec.ts | 78 ++----- .../src/api/k8s/__tests__/secrets.spec.ts | 23 ++- .../api/k8s/__tests__/servingRuntimes.spec.ts | 190 +++--------------- .../src/api/k8s/__tests__/workloads.spec.ts | 15 +- .../src/api/pipelines/__tests__/k8s.spec.ts | 65 ++---- .../storage/__tests__/useProjectPvcs.spec.ts | 7 +- 12 files changed, 102 insertions(+), 414 deletions(-) diff --git a/frontend/src/api/k8s/__tests__/clusterQueues.spec.ts b/frontend/src/api/k8s/__tests__/clusterQueues.spec.ts index ba6fcd1aac..0c550fa753 100644 --- a/frontend/src/api/k8s/__tests__/clusterQueues.spec.ts +++ b/frontend/src/api/k8s/__tests__/clusterQueues.spec.ts @@ -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(), @@ -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); @@ -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: {}, }); }); diff --git a/frontend/src/api/k8s/__tests__/configMaps.spec.ts b/frontend/src/api/k8s/__tests__/configMaps.spec.ts index b685ce909c..bd712f9527 100644 --- a/frontend/src/api/k8s/__tests__/configMaps.spec.ts +++ b/frontend/src/api/k8s/__tests__/configMaps.spec.ts @@ -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, }); @@ -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, }); @@ -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, }); @@ -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, }); @@ -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, @@ -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, @@ -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, diff --git a/frontend/src/api/k8s/__tests__/inferenceServices.spec.ts b/frontend/src/api/k8s/__tests__/inferenceServices.spec.ts index 9810d8973f..5b4da94a1e 100644 --- a/frontend/src/api/k8s/__tests__/inferenceServices.spec.ts +++ b/frontend/src/api/k8s/__tests__/inferenceServices.spec.ts @@ -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: {} }, }); }); @@ -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: {} }, }); }); @@ -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', @@ -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', @@ -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', diff --git a/frontend/src/api/k8s/__tests__/localQueues.spec.ts b/frontend/src/api/k8s/__tests__/localQueues.spec.ts index dc36c9beb1..8ffa77e590 100644 --- a/frontend/src/api/k8s/__tests__/localQueues.spec.ts +++ b/frontend/src/api/k8s/__tests__/localQueues.spec.ts @@ -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(), @@ -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); @@ -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' }, }); }); diff --git a/frontend/src/api/k8s/__tests__/projects.spec.ts b/frontend/src/api/k8s/__tests__/projects.spec.ts index 297f7a578f..a6a863a65f 100644 --- a/frontend/src/api/k8s/__tests__/projects.spec.ts +++ b/frontend/src/api/k8s/__tests__/projects.spec.ts @@ -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'; @@ -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 }); @@ -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', @@ -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', diff --git a/frontend/src/api/k8s/__tests__/pvcs.spec.ts b/frontend/src/api/k8s/__tests__/pvcs.spec.ts index 54ba19c8c4..b645fce99b 100644 --- a/frontend/src/api/k8s/__tests__/pvcs.spec.ts +++ b/frontend/src/api/k8s/__tests__/pvcs.spec.ts @@ -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'; @@ -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' }, @@ -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' }, @@ -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']), }); @@ -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']), }); @@ -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']), }); @@ -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']), }); @@ -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); @@ -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); @@ -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' }, }); }); diff --git a/frontend/src/api/k8s/__tests__/roleBindings.spec.ts b/frontend/src/api/k8s/__tests__/roleBindings.spec.ts index 81e6b7ade5..7d79ff4f77 100644 --- a/frontend/src/api/k8s/__tests__/roleBindings.spec.ts +++ b/frontend/src/api/k8s/__tests__/roleBindings.spec.ts @@ -23,6 +23,7 @@ import { listRoleBindings, patchRoleBindingOwnerRef, } from '~/api/k8s/roleBindings'; +import { RoleBindingModel } from '~/api/models/k8s'; jest.mock('@openshift/dynamic-plugin-sdk-utils', () => ({ k8sListResource: jest.fn(), @@ -214,12 +215,7 @@ describe('listRoleBindings', () => { k8sListResourceMock.mockResolvedValue(mockK8sResourceList([roleBindingMock])); const result = await listRoleBindings(); expect(k8sListResourceMock).toHaveBeenCalledWith({ - model: { - apiGroup: 'rbac.authorization.k8s.io', - apiVersion: 'v1', - kind: 'RoleBinding', - plural: 'rolebindings', - }, + model: RoleBindingModel, queryOptions: {}, }); expect(k8sListResourceMock).toHaveBeenCalledTimes(1); @@ -230,12 +226,7 @@ describe('listRoleBindings', () => { k8sListResourceMock.mockResolvedValue(mockK8sResourceList([roleBindingMock])); const result = await listRoleBindings(namespace, 'labelSelector'); expect(k8sListResourceMock).toHaveBeenCalledWith({ - model: { - apiGroup: 'rbac.authorization.k8s.io', - apiVersion: 'v1', - kind: 'RoleBinding', - plural: 'rolebindings', - }, + model: RoleBindingModel, queryOptions: { ns: namespace, queryParams: { labelSelector: 'labelSelector' } }, }); expect(k8sListResourceMock).toHaveBeenCalledTimes(1); @@ -247,12 +238,7 @@ describe('listRoleBindings', () => { await expect(listRoleBindings()).rejects.toThrow('error1'); expect(k8sListResourceMock).toHaveBeenCalledTimes(1); expect(k8sListResourceMock).toHaveBeenCalledWith({ - model: { - apiGroup: 'rbac.authorization.k8s.io', - apiVersion: 'v1', - kind: 'RoleBinding', - plural: 'rolebindings', - }, + model: RoleBindingModel, queryOptions: {}, }); }); @@ -263,12 +249,7 @@ describe('getRoleBinding', () => { k8sGetResourceMock.mockResolvedValue(roleBindingMock); const result = await getRoleBinding('projectName', 'rbName'); expect(k8sGetResourceMock).toHaveBeenCalledWith({ - model: { - apiGroup: 'rbac.authorization.k8s.io', - apiVersion: 'v1', - kind: 'RoleBinding', - plural: 'rolebindings', - }, + model: RoleBindingModel, queryOptions: { name: 'rbName', ns: 'projectName' }, }); expect(k8sGetResourceMock).toHaveBeenCalledTimes(1); @@ -280,12 +261,7 @@ describe('getRoleBinding', () => { await expect(getRoleBinding('projectName', 'rbName')).rejects.toThrow('error1'); expect(k8sGetResourceMock).toHaveBeenCalledTimes(1); expect(k8sGetResourceMock).toHaveBeenCalledWith({ - model: { - apiGroup: 'rbac.authorization.k8s.io', - apiVersion: 'v1', - kind: 'RoleBinding', - plural: 'rolebindings', - }, + model: RoleBindingModel, queryOptions: { name: 'rbName', ns: 'projectName' }, }); }); @@ -297,12 +273,7 @@ describe('createRoleBinding', () => { const result = await createRoleBinding(roleBindingMock); expect(k8sCreateResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'rbac.authorization.k8s.io', - apiVersion: 'v1', - kind: 'RoleBinding', - plural: 'rolebindings', - }, + model: RoleBindingModel, queryOptions: { queryParams: {} }, resource: roleBindingMock, }); @@ -316,12 +287,7 @@ describe('createRoleBinding', () => { expect(k8sCreateResourceMock).toHaveBeenCalledTimes(1); expect(k8sCreateResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'rbac.authorization.k8s.io', - apiVersion: 'v1', - kind: 'RoleBinding', - plural: 'rolebindings', - }, + model: RoleBindingModel, queryOptions: { queryParams: {} }, resource: roleBindingObject, }); @@ -335,12 +301,7 @@ describe('deleteRoleBinding', () => { const result = await deleteRoleBinding('rbName', namespace); expect(k8sDeleteResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'rbac.authorization.k8s.io', - apiVersion: 'v1', - kind: 'RoleBinding', - plural: 'rolebindings', - }, + model: RoleBindingModel, queryOptions: { name: 'rbName', ns: namespace, queryParams: {} }, }); expect(k8sDeleteResourceMock).toHaveBeenCalledTimes(1); @@ -353,12 +314,7 @@ describe('deleteRoleBinding', () => { const result = await deleteRoleBinding('rbName', namespace); expect(k8sDeleteResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'rbac.authorization.k8s.io', - apiVersion: 'v1', - kind: 'RoleBinding', - plural: 'rolebindings', - }, + model: RoleBindingModel, queryOptions: { name: 'rbName', ns: namespace, queryParams: {} }, }); expect(k8sDeleteResourceMock).toHaveBeenCalledTimes(1); @@ -371,12 +327,7 @@ describe('deleteRoleBinding', () => { expect(k8sDeleteResourceMock).toHaveBeenCalledTimes(1); expect(k8sDeleteResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'rbac.authorization.k8s.io', - apiVersion: 'v1', - kind: 'RoleBinding', - plural: 'rolebindings', - }, + model: RoleBindingModel, queryOptions: { name: 'rbName', ns: namespace, queryParams: {} }, }); }); @@ -387,12 +338,7 @@ describe('patchRoleBindingOwnerRef', () => { k8sPatchResourceMock.mockResolvedValue(roleBindingMock); const result = await patchRoleBindingOwnerRef('rbName', namespace, []); expect(k8sPatchResourceMock).toHaveBeenCalledWith({ - model: { - apiGroup: 'rbac.authorization.k8s.io', - apiVersion: 'v1', - kind: 'RoleBinding', - plural: 'rolebindings', - }, + model: RoleBindingModel, patches: [{ op: 'replace', path: '/metadata/ownerReferences', value: [] }], queryOptions: { name: 'rbName', ns: namespace }, }); diff --git a/frontend/src/api/k8s/__tests__/secrets.spec.ts b/frontend/src/api/k8s/__tests__/secrets.spec.ts index 133b90725e..3ee1ce7519 100644 --- a/frontend/src/api/k8s/__tests__/secrets.spec.ts +++ b/frontend/src/api/k8s/__tests__/secrets.spec.ts @@ -20,6 +20,7 @@ import { getSecretsByLabel, replaceSecret, } from '~/api/k8s/secrets'; +import { SecretModel } from '~/api/models/k8s'; import { SecretKind } from '~/k8sTypes'; import { genRandomChars } from '~/utilities/string'; @@ -192,7 +193,7 @@ describe('getSecret', () => { const result = await getSecret('projectName', 'secretName'); expect(k8sGetResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { apiVersion: 'v1', kind: 'Secret', plural: 'secrets' }, + model: SecretModel, queryOptions: { name: 'secretName', ns: 'projectName', queryParams: {} }, }); expect(k8sGetResourceMock).toHaveBeenCalledTimes(1); @@ -205,7 +206,7 @@ describe('getSecret', () => { expect(k8sGetResourceMock).toHaveBeenCalledTimes(1); expect(k8sGetResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { apiVersion: 'v1', kind: 'Secret', plural: 'secrets' }, + model: SecretModel, queryOptions: { name: 'secretName', ns: 'projectName', queryParams: {} }, }); }); @@ -218,7 +219,7 @@ describe('getSecretsByLabel', () => { const result = await getSecretsByLabel('label', 'secretName'); expect(k8sListResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { apiVersion: 'v1', kind: 'Secret', plural: 'secrets' }, + model: SecretModel, queryOptions: { ns: 'secretName', queryParams: { labelSelector: 'label' } }, }); expect(k8sListResourceMock).toHaveBeenCalledTimes(1); @@ -231,7 +232,7 @@ describe('getSecretsByLabel', () => { expect(k8sListResourceMock).toHaveBeenCalledTimes(1); expect(k8sListResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { apiVersion: 'v1', kind: 'Secret', plural: 'secrets' }, + model: SecretModel, queryOptions: { ns: 'secretName', queryParams: { labelSelector: 'label' } }, }); }); @@ -244,7 +245,7 @@ describe('createSecret', () => { const result = await createSecret(assembleSecret('secret', data, 'aws')); expect(k8sCreateResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { apiVersion: 'v1', kind: 'Secret', plural: 'secrets' }, + model: SecretModel, queryOptions: { queryParams: {} }, resource: { ...assembleSecretResult, @@ -260,7 +261,7 @@ describe('createSecret', () => { await expect(createSecret(assembleSecret('secret', data, 'aws'))).rejects.toThrow('error1'); expect(k8sCreateResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { apiVersion: 'v1', kind: 'Secret', plural: 'secrets' }, + model: SecretModel, queryOptions: { queryParams: {} }, resource: { ...assembleSecretResult, @@ -278,7 +279,7 @@ describe('replaceSecret', () => { const result = await replaceSecret(assembleSecret('secret', data, 'aws')); expect(k8sUpdateResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { apiVersion: 'v1', kind: 'Secret', plural: 'secrets' }, + model: SecretModel, queryOptions: { queryParams: {} }, resource: { ...assembleSecretResult, @@ -294,7 +295,7 @@ describe('replaceSecret', () => { await expect(replaceSecret(assembleSecret('secret', data, 'aws'))).rejects.toThrow('error1'); expect(k8sUpdateResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { apiVersion: 'v1', kind: 'Secret', plural: 'secrets' }, + model: SecretModel, queryOptions: { queryParams: {} }, resource: { ...assembleSecretResult, @@ -312,7 +313,7 @@ describe('deleteSecret', () => { const result = await deleteSecret('projectName', 'secretName'); expect(k8sDeleteResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { apiVersion: 'v1', kind: 'Secret', plural: 'secrets' }, + model: SecretModel, queryOptions: { name: 'secretName', ns: 'projectName', queryParams: {} }, }); expect(k8sDeleteResourceMock).toHaveBeenCalledTimes(1); @@ -325,7 +326,7 @@ describe('deleteSecret', () => { const result = await deleteSecret('projectName', 'secretName'); expect(k8sDeleteResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { apiVersion: 'v1', kind: 'Secret', plural: 'secrets' }, + model: SecretModel, queryOptions: { name: 'secretName', ns: 'projectName', queryParams: {} }, }); expect(k8sDeleteResourceMock).toHaveBeenCalledTimes(1); @@ -338,7 +339,7 @@ describe('deleteSecret', () => { expect(k8sDeleteResourceMock).toHaveBeenCalledTimes(1); expect(k8sDeleteResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { apiVersion: 'v1', kind: 'Secret', plural: 'secrets' }, + model: SecretModel, queryOptions: { name: 'secretName', ns: 'projectName', queryParams: {} }, }); }); diff --git a/frontend/src/api/k8s/__tests__/servingRuntimes.spec.ts b/frontend/src/api/k8s/__tests__/servingRuntimes.spec.ts index 8651dbc3bc..e9fb706e01 100644 --- a/frontend/src/api/k8s/__tests__/servingRuntimes.spec.ts +++ b/frontend/src/api/k8s/__tests__/servingRuntimes.spec.ts @@ -23,6 +23,7 @@ import { listServingRuntimes, updateServingRuntime, } from '~/api/k8s/servingRuntimes'; +import { ProjectModel, ServingRuntimeModel } from '~/api/models'; import { ProjectKind, ServingRuntimeKind } from '~/k8sTypes'; import { AcceleratorProfileState } from '~/utilities/useAcceleratorProfileState'; @@ -211,12 +212,7 @@ describe('listServingRuntimes', () => { const result = await listServingRuntimes(); expect(k8sListResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'serving.kserve.io', - apiVersion: 'v1alpha1', - kind: 'ServingRuntime', - plural: 'servingruntimes', - }, + model: ServingRuntimeModel, queryOptions: { queryParams: {} }, }); expect(k8sListResourceMock).toHaveBeenCalledTimes(1); @@ -228,12 +224,7 @@ describe('listServingRuntimes', () => { const result = await listServingRuntimes('namespace', 'labelselector'); expect(k8sListResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'serving.kserve.io', - apiVersion: 'v1alpha1', - kind: 'ServingRuntime', - plural: 'servingruntimes', - }, + model: ServingRuntimeModel, queryOptions: { ns: 'namespace', queryParams: { labelSelector: 'labelselector' } }, }); expect(k8sListResourceMock).toHaveBeenCalledTimes(1); @@ -246,12 +237,7 @@ describe('listServingRuntimes', () => { expect(k8sListResourceMock).toHaveBeenCalledTimes(1); expect(k8sListResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'serving.kserve.io', - apiVersion: 'v1alpha1', - kind: 'ServingRuntime', - plural: 'servingruntimes', - }, + model: ServingRuntimeModel, queryOptions: { ns: 'namespace', queryParams: { labelSelector: 'labelselector' } }, }); }); @@ -269,24 +255,14 @@ describe('listScopedServingRuntimes', () => { expect(result).toStrictEqual([mock]); expect(k8sListResourceMock).toHaveBeenNthCalledWith(1, { fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'project.openshift.io', - apiVersion: 'v1', - kind: 'Project', - plural: 'projects', - }, + model: ProjectModel, queryOptions: { queryParams: { labelSelector: 'opendatahub.io/dashboard=true,modelmesh-enabled' }, }, }); expect(k8sListResourceMock).toHaveBeenNthCalledWith(2, { fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'serving.kserve.io', - apiVersion: 'v1alpha1', - kind: 'ServingRuntime', - plural: 'servingruntimes', - }, + model: ServingRuntimeModel, queryOptions: { ns: 'test-model', queryParams: {} }, }); expect(k8sListResourceMock).toHaveBeenCalledTimes(2); @@ -301,24 +277,14 @@ describe('listScopedServingRuntimes', () => { expect(result).toStrictEqual([inferenceServiceMock]); expect(k8sListResourceMock).toHaveBeenNthCalledWith(1, { fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'project.openshift.io', - apiVersion: 'v1', - kind: 'Project', - plural: 'projects', - }, + model: ProjectModel, queryOptions: { queryParams: { labelSelector: 'opendatahub.io/dashboard=true,modelmesh-enabled' }, }, }); expect(k8sListResourceMock).toHaveBeenNthCalledWith(2, { fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'serving.kserve.io', - apiVersion: 'v1alpha1', - kind: 'ServingRuntime', - plural: 'servingruntimes', - }, + model: ServingRuntimeModel, queryOptions: { ns: 'test-model', queryParams: { labelSelector: 'labelSelector' } }, }); expect(k8sListResourceMock).toHaveBeenCalledTimes(2); @@ -332,24 +298,14 @@ describe('listScopedServingRuntimes', () => { await expect(listScopedServingRuntimes('labelSelector')).rejects.toThrow('error'); expect(k8sListResourceMock).toHaveBeenNthCalledWith(1, { fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'project.openshift.io', - apiVersion: 'v1', - kind: 'Project', - plural: 'projects', - }, + model: ProjectModel, queryOptions: { queryParams: { labelSelector: 'opendatahub.io/dashboard=true,modelmesh-enabled' }, }, }); expect(k8sListResourceMock).toHaveBeenNthCalledWith(2, { fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'serving.kserve.io', - apiVersion: 'v1alpha1', - kind: 'ServingRuntime', - plural: 'servingruntimes', - }, + model: ServingRuntimeModel, queryOptions: { ns: 'test-project', queryParams: { labelSelector: 'labelSelector' } }, }); expect(k8sListResourceMock).toHaveBeenCalledTimes(2); @@ -361,12 +317,7 @@ describe('listScopedServingRuntimes', () => { expect(k8sListResourceMock).toHaveBeenCalledTimes(1); expect(k8sListResourceMock).toHaveBeenNthCalledWith(1, { fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'project.openshift.io', - apiVersion: 'v1', - kind: 'Project', - plural: 'projects', - }, + model: ProjectModel, queryOptions: { queryParams: { labelSelector: 'opendatahub.io/dashboard=true,modelmesh-enabled' }, }, @@ -380,12 +331,7 @@ describe('getServingRuntimeContext', () => { const result = await getServingRuntimeContext('namespace', 'labelSelector'); expect(k8sListResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'serving.kserve.io', - apiVersion: 'v1alpha1', - kind: 'ServingRuntime', - plural: 'servingruntimes', - }, + model: ServingRuntimeModel, queryOptions: { ns: 'namespace', queryParams: { labelSelector: 'labelSelector' } }, }); expect(k8sListResourceMock).toHaveBeenCalledTimes(1); @@ -402,24 +348,14 @@ describe('getServingRuntimeContext', () => { const result = await getServingRuntimeContext(); expect(k8sListResourceMock).toHaveBeenNthCalledWith(1, { fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'project.openshift.io', - apiVersion: 'v1', - kind: 'Project', - plural: 'projects', - }, + model: ProjectModel, queryOptions: { queryParams: { labelSelector: 'opendatahub.io/dashboard=true,modelmesh-enabled' }, }, }); expect(k8sListResourceMock).toHaveBeenNthCalledWith(2, { fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'serving.kserve.io', - apiVersion: 'v1alpha1', - kind: 'ServingRuntime', - plural: 'servingruntimes', - }, + model: ServingRuntimeModel, queryOptions: { ns: 'test-model', queryParams: {} }, }); expect(k8sListResourceMock).toHaveBeenCalledTimes(2); @@ -433,24 +369,14 @@ describe('getServingRuntimeContext', () => { await expect(getServingRuntimeContext()).rejects.toThrow('error'); expect(k8sListResourceMock).toHaveBeenNthCalledWith(1, { fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'project.openshift.io', - apiVersion: 'v1', - kind: 'Project', - plural: 'projects', - }, + model: ProjectModel, queryOptions: { queryParams: { labelSelector: 'opendatahub.io/dashboard=true,modelmesh-enabled' }, }, }); expect(k8sListResourceMock).toHaveBeenNthCalledWith(2, { fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'serving.kserve.io', - apiVersion: 'v1alpha1', - kind: 'ServingRuntime', - plural: 'servingruntimes', - }, + model: ServingRuntimeModel, queryOptions: { ns: 'test-project', queryParams: {} }, }); expect(k8sListResourceMock).toHaveBeenCalledTimes(2); @@ -462,12 +388,7 @@ describe('getServingRuntimeContext', () => { expect(k8sListResourceMock).toHaveBeenCalledTimes(1); expect(k8sListResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'serving.kserve.io', - apiVersion: 'v1alpha1', - kind: 'ServingRuntime', - plural: 'servingruntimes', - }, + model: ServingRuntimeModel, queryOptions: { ns: 'namespace', queryParams: { labelSelector: 'labelSelector' } }, }); }); @@ -479,12 +400,7 @@ describe('getServingRuntime', () => { const result = await getServingRuntime('name', 'namespace'); expect(k8sGetResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'serving.kserve.io', - apiVersion: 'v1alpha1', - kind: 'ServingRuntime', - plural: 'servingruntimes', - }, + model: ServingRuntimeModel, queryOptions: { name: 'name', ns: 'namespace', queryParams: {} }, }); expect(k8sGetResourceMock).toHaveBeenCalledTimes(1); @@ -496,12 +412,7 @@ describe('getServingRuntime', () => { expect(k8sGetResourceMock).toHaveBeenCalledTimes(1); expect(k8sGetResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'serving.kserve.io', - apiVersion: 'v1alpha1', - kind: 'ServingRuntime', - plural: 'servingruntimes', - }, + model: ServingRuntimeModel, queryOptions: { name: 'name', ns: 'namespace', queryParams: {} }, }); }); @@ -527,12 +438,7 @@ describe('updateServingRuntime', () => { const result = await updateServingRuntime(option); expect(k8sUpdateResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'serving.kserve.io', - apiVersion: 'v1alpha1', - kind: 'ServingRuntime', - plural: 'servingruntimes', - }, + model: ServingRuntimeModel, queryOptions: { queryParams: {} }, resource: existingData, }); @@ -550,12 +456,7 @@ describe('updateServingRuntime', () => { const result = await updateServingRuntime(option); expect(k8sUpdateResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'serving.kserve.io', - apiVersion: 'v1alpha1', - kind: 'ServingRuntime', - plural: 'servingruntimes', - }, + model: ServingRuntimeModel, queryOptions: { queryParams: {} }, resource: existingData, }); @@ -574,12 +475,7 @@ describe('updateServingRuntime', () => { expect(k8sUpdateResourceMock).toHaveBeenCalledTimes(1); expect(k8sUpdateResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'serving.kserve.io', - apiVersion: 'v1alpha1', - kind: 'ServingRuntime', - plural: 'servingruntimes', - }, + model: ServingRuntimeModel, queryOptions: { queryParams: {} }, resource: existingData, }); @@ -613,12 +509,7 @@ describe('createServingRuntime', () => { const result = await createServingRuntime(option); expect(k8sCreateResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'serving.kserve.io', - apiVersion: 'v1alpha1', - kind: 'ServingRuntime', - plural: 'servingruntimes', - }, + model: ServingRuntimeModel, queryOptions: { queryParams: {} }, resource: { ...existingData, @@ -640,12 +531,7 @@ describe('createServingRuntime', () => { const result = await createServingRuntime(option); expect(k8sCreateResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'serving.kserve.io', - apiVersion: 'v1alpha1', - kind: 'ServingRuntime', - plural: 'servingruntimes', - }, + model: ServingRuntimeModel, queryOptions: { queryParams: {} }, resource: existingData, }); @@ -664,12 +550,7 @@ describe('createServingRuntime', () => { expect(k8sCreateResourceMock).toHaveBeenCalledTimes(1); expect(k8sCreateResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'serving.kserve.io', - apiVersion: 'v1alpha1', - kind: 'ServingRuntime', - plural: 'servingruntimes', - }, + model: ServingRuntimeModel, queryOptions: { queryParams: {} }, resource: existingData, }); @@ -683,12 +564,7 @@ describe('deleteServingRuntime', () => { const result = await deleteServingRuntime('name', 'namespace'); expect(k8sDeleteResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'serving.kserve.io', - apiVersion: 'v1alpha1', - kind: 'ServingRuntime', - plural: 'servingruntimes', - }, + model: ServingRuntimeModel, queryOptions: { name: 'name', ns: 'namespace', queryParams: {} }, }); expect(k8sDeleteResourceMock).toHaveBeenCalledTimes(1); @@ -701,12 +577,7 @@ describe('deleteServingRuntime', () => { const result = await deleteServingRuntime('name', 'namespace'); expect(k8sDeleteResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'serving.kserve.io', - apiVersion: 'v1alpha1', - kind: 'ServingRuntime', - plural: 'servingruntimes', - }, + model: ServingRuntimeModel, queryOptions: { name: 'name', ns: 'namespace', queryParams: {} }, }); expect(k8sDeleteResourceMock).toHaveBeenCalledTimes(1); @@ -719,12 +590,7 @@ describe('deleteServingRuntime', () => { expect(k8sDeleteResourceMock).toHaveBeenCalledTimes(1); expect(k8sDeleteResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'serving.kserve.io', - apiVersion: 'v1alpha1', - kind: 'ServingRuntime', - plural: 'servingruntimes', - }, + model: ServingRuntimeModel, queryOptions: { name: 'name', ns: 'namespace', queryParams: {} }, }); }); diff --git a/frontend/src/api/k8s/__tests__/workloads.spec.ts b/frontend/src/api/k8s/__tests__/workloads.spec.ts index 54e9997658..6f892dd4e1 100644 --- a/frontend/src/api/k8s/__tests__/workloads.spec.ts +++ b/frontend/src/api/k8s/__tests__/workloads.spec.ts @@ -2,6 +2,7 @@ import { k8sListResourceItems } from '@openshift/dynamic-plugin-sdk-utils'; import { mockWorkloadK8sResource } from '~/__mocks__/mockWorkloadK8sResource'; import { WorkloadKind } from '~/k8sTypes'; import { listWorkloads } from '~/api/k8s/workloads'; +import { WorkloadModel } from '~/api/models/kueue'; jest.mock('@openshift/dynamic-plugin-sdk-utils', () => ({ k8sListResourceItems: jest.fn(), @@ -19,12 +20,7 @@ describe('listWorkloads', () => { k8sListResourceItemsMock.mockResolvedValue([mockedWorkload]); const result = await listWorkloads('test-project'); expect(k8sListResourceItemsMock).toHaveBeenCalledWith({ - model: { - apiGroup: 'kueue.x-k8s.io', - apiVersion: 'v1beta1', - kind: 'Workload', - plural: 'workloads', - }, + model: WorkloadModel, queryOptions: { ns: 'test-project' }, }); expect(k8sListResourceItemsMock).toHaveBeenCalledTimes(1); @@ -36,12 +32,7 @@ describe('listWorkloads', () => { await expect(listWorkloads('test-project')).rejects.toThrow('error1'); expect(k8sListResourceItemsMock).toHaveBeenCalledTimes(1); expect(k8sListResourceItemsMock).toHaveBeenCalledWith({ - model: { - apiGroup: 'kueue.x-k8s.io', - apiVersion: 'v1beta1', - kind: 'Workload', - plural: 'workloads', - }, + model: WorkloadModel, queryOptions: { ns: 'test-project' }, }); }); diff --git a/frontend/src/api/pipelines/__tests__/k8s.spec.ts b/frontend/src/api/pipelines/__tests__/k8s.spec.ts index 3855b0088a..c85c31e9ba 100644 --- a/frontend/src/api/pipelines/__tests__/k8s.spec.ts +++ b/frontend/src/api/pipelines/__tests__/k8s.spec.ts @@ -9,6 +9,9 @@ import { mock200Status, mock404Error } from '~/__mocks__/mockK8sStatus'; import { mockRouteK8sResource } from '~/__mocks__/mockRouteK8sResource'; import { mockSecretK8sResource } from '~/__mocks__/mockSecretK8sResource'; import { + DataSciencePipelineApplicationModel, + RouteModel, + SecretModel, createPipelinesCR, deletePipelineCR, getElyraSecret, @@ -40,7 +43,7 @@ describe('getElyraSecret', () => { const result = await getElyraSecret('namespace', opts); expect(k8sGetResourceSecretKindMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { apiVersion: 'v1', kind: 'Secret', plural: 'secrets' }, + model: SecretModel, payload: { dryRun: ['All'] }, queryOptions: { name: 'ds-pipeline-config', ns: 'namespace', queryParams: { dryRun: 'All' } }, }); @@ -54,7 +57,7 @@ describe('getElyraSecret', () => { expect(k8sGetResourceSecretKindMock).toHaveBeenCalledTimes(1); expect(k8sGetResourceSecretKindMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { apiVersion: 'v1', kind: 'Secret', plural: 'secrets' }, + model: SecretModel, payload: { dryRun: ['All'] }, queryOptions: { name: 'ds-pipeline-config', ns: 'namespace', queryParams: { dryRun: 'All' } }, }); @@ -68,7 +71,7 @@ describe('getPipelineAPIRoute', () => { const result = await getPipelineAPIRoute('namespace', 'ds-pipeline-dspa'); expect(k8sGetResourceRouteKindMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { apiGroup: 'route.openshift.io', apiVersion: 'v1', kind: 'Route', plural: 'routes' }, + model: RouteModel, queryOptions: { name: 'ds-pipeline-dspa', ns: 'namespace', queryParams: {} }, }); expect(k8sGetResourceRouteKindMock).toHaveBeenCalledTimes(1); @@ -81,12 +84,7 @@ describe('getPipelineAPIRoute', () => { expect(k8sGetResourceRouteKindMock).toHaveBeenCalledTimes(1); expect(k8sGetResourceRouteKindMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'route.openshift.io', - apiVersion: 'v1', - kind: 'Route', - plural: 'routes', - }, + model: RouteModel, queryOptions: { name: 'ds-pipeline-dspa', ns: 'namespace', @@ -104,12 +102,7 @@ describe('createPipelinesCR', () => { const result = await createPipelinesCR('test-project', DSPipelinemock.spec); expect(k8sCreateResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'datasciencepipelinesapplications.opendatahub.io', - apiVersion: 'v1alpha1', - kind: 'DataSciencePipelinesApplication', - plural: 'datasciencepipelinesapplications', - }, + model: DataSciencePipelineApplicationModel, queryOptions: { queryParams: {} }, resource: DSPipelinemock, }); @@ -123,12 +116,7 @@ describe('createPipelinesCR', () => { expect(k8sCreateResourceMock).toHaveBeenCalledTimes(1); expect(k8sCreateResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'datasciencepipelinesapplications.opendatahub.io', - apiVersion: 'v1alpha1', - kind: 'DataSciencePipelinesApplication', - plural: 'datasciencepipelinesapplications', - }, + model: DataSciencePipelineApplicationModel, queryOptions: { queryParams: {} }, resource: DSPipelinemock, }); @@ -142,12 +130,7 @@ describe('getPipelinesCR', () => { const result = await getPipelinesCR('namespace', 'dspa'); expect(k8sGetResourceDSPipelineKindMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'datasciencepipelinesapplications.opendatahub.io', - apiVersion: 'v1alpha1', - kind: 'DataSciencePipelinesApplication', - plural: 'datasciencepipelinesapplications', - }, + model: DataSciencePipelineApplicationModel, queryOptions: { name: 'dspa', ns: 'namespace', queryParams: {} }, }); expect(k8sGetResourceDSPipelineKindMock).toHaveBeenCalledTimes(1); @@ -160,12 +143,7 @@ describe('getPipelinesCR', () => { expect(k8sGetResourceDSPipelineKindMock).toHaveBeenCalledTimes(1); expect(k8sGetResourceDSPipelineKindMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'datasciencepipelinesapplications.opendatahub.io', - apiVersion: 'v1alpha1', - kind: 'DataSciencePipelinesApplication', - plural: 'datasciencepipelinesapplications', - }, + model: DataSciencePipelineApplicationModel, queryOptions: { name: 'dspa', ns: 'namespace', queryParams: {} }, }); }); @@ -178,12 +156,7 @@ describe('deletePipelineCR', () => { const result = await deletePipelineCR('namespace', 'dspa'); expect(k8sDeleteResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'datasciencepipelinesapplications.opendatahub.io', - apiVersion: 'v1alpha1', - kind: 'DataSciencePipelinesApplication', - plural: 'datasciencepipelinesapplications', - }, + model: DataSciencePipelineApplicationModel, queryOptions: { name: 'dspa', ns: 'namespace', queryParams: {} }, }); expect(k8sDeleteResourceMock).toHaveBeenCalledTimes(1); @@ -196,12 +169,7 @@ describe('deletePipelineCR', () => { const result = await deletePipelineCR('namespace', 'dspa'); expect(k8sDeleteResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'datasciencepipelinesapplications.opendatahub.io', - apiVersion: 'v1alpha1', - kind: 'DataSciencePipelinesApplication', - plural: 'datasciencepipelinesapplications', - }, + model: DataSciencePipelineApplicationModel, queryOptions: { name: 'dspa', ns: 'namespace', queryParams: {} }, }); expect(k8sDeleteResourceMock).toHaveBeenCalledTimes(1); @@ -214,12 +182,7 @@ describe('deletePipelineCR', () => { expect(k8sDeleteResourceMock).toHaveBeenCalledTimes(1); expect(k8sDeleteResourceMock).toHaveBeenCalledWith({ fetchOptions: { requestInit: {} }, - model: { - apiGroup: 'datasciencepipelinesapplications.opendatahub.io', - apiVersion: 'v1alpha1', - kind: 'DataSciencePipelinesApplication', - plural: 'datasciencepipelinesapplications', - }, + model: DataSciencePipelineApplicationModel, queryOptions: { name: 'dspa', ns: 'namespace', queryParams: {} }, }); }); diff --git a/frontend/src/pages/projects/screens/detail/storage/__tests__/useProjectPvcs.spec.ts b/frontend/src/pages/projects/screens/detail/storage/__tests__/useProjectPvcs.spec.ts index 69fb512791..84b5ad0600 100644 --- a/frontend/src/pages/projects/screens/detail/storage/__tests__/useProjectPvcs.spec.ts +++ b/frontend/src/pages/projects/screens/detail/storage/__tests__/useProjectPvcs.spec.ts @@ -2,6 +2,7 @@ import { k8sListResourceItems } from '@openshift/dynamic-plugin-sdk-utils'; import { act } from '@testing-library/react'; import { mockPVCK8sResource } from '~/__mocks__/mockPVCK8sResource'; import { standardUseFetchState, testHook } from '~/__tests__/unit/testUtils/hooks'; +import { PVCModel } from '~/api'; import { LABEL_SELECTOR_DASHBOARD_RESOURCE } from '~/const'; import { PersistentVolumeClaimKind } from '~/k8sTypes'; import useProjectPvcs from '~/pages/projects/screens/detail/storage/useProjectPvcs'; @@ -16,11 +17,7 @@ describe('useProjectPVCs', () => { it('should return dashboard PVCs', async () => { const mockedPVC = [mockPVCK8sResource({})]; const options = { - model: { - apiVersion: 'v1', - kind: 'PersistentVolumeClaim', - plural: 'persistentvolumeclaims', - }, + model: PVCModel, queryOptions: { ns: 'namespace', queryParams: { labelSelector: LABEL_SELECTOR_DASHBOARD_RESOURCE },