From cc1b31fd0a1c3eaf098ffb948ee95bee6a49cfba Mon Sep 17 00:00:00 2001 From: ppadti Date: Mon, 11 Sep 2023 17:34:21 +0530 Subject: [PATCH] Update Custom Serving Runtime tooltip with Openshift resource information --- frontend/src/k8sTypes.ts | 11 ++++++ .../CustomServingRuntimeTableRow.tsx | 2 +- frontend/src/services/templateService.ts | 3 +- frontend/src/types.ts | 2 +- .../addTypesToK8sListedResources.spec.ts | 36 +++++++++++++++++++ .../utilities/addTypesToK8sListedResources.ts | 14 ++++++++ 6 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 frontend/src/utilities/__tests__/addTypesToK8sListedResources.spec.ts create mode 100644 frontend/src/utilities/addTypesToK8sListedResources.ts diff --git a/frontend/src/k8sTypes.ts b/frontend/src/k8sTypes.ts index d64f49ca57..329d5008be 100644 --- a/frontend/src/k8sTypes.ts +++ b/frontend/src/k8sTypes.ts @@ -758,3 +758,14 @@ export type AcceleratorKind = K8sResourceCommon & { tolerations?: PodToleration[]; }; }; + +// In the SDK TResource extends from K8sResourceCommon, but both kind and apiVersion are mandatory +export type K8sResourceListResult> = { + apiVersion: string; + kind: string; + items: TResource[]; + metadata: { + resourceVersion: string; + continue: string; + }; +}; diff --git a/frontend/src/pages/modelServing/customServingRuntimes/CustomServingRuntimeTableRow.tsx b/frontend/src/pages/modelServing/customServingRuntimes/CustomServingRuntimeTableRow.tsx index 135a66870b..4a991b205e 100644 --- a/frontend/src/pages/modelServing/customServingRuntimes/CustomServingRuntimeTableRow.tsx +++ b/frontend/src/pages/modelServing/customServingRuntimes/CustomServingRuntimeTableRow.tsx @@ -35,7 +35,7 @@ const CustomServingRuntimeTableRow: React.FC }} /> - + {getServingRuntimeDisplayNameFromTemplate(template)} {templateOOTB && } diff --git a/frontend/src/services/templateService.ts b/frontend/src/services/templateService.ts index 44e562331b..5713a7cf73 100644 --- a/frontend/src/services/templateService.ts +++ b/frontend/src/services/templateService.ts @@ -3,6 +3,7 @@ import axios from 'axios'; import YAML from 'yaml'; import { assembleServingRuntimeTemplate } from '~/api'; import { ServingRuntimeKind, TemplateKind } from '~/k8sTypes'; +import { addTypesToK8sListedResources } from '~/utilities/addTypesToK8sListedResources'; export const listTemplatesBackend = async ( namespace?: string, @@ -10,7 +11,7 @@ export const listTemplatesBackend = async ( ): Promise => axios .get(`/api/templates/${namespace}`, { params: { labelSelector } }) - .then((response) => response.data.items) + .then((response) => addTypesToK8sListedResources(response.data, 'Template').items) .catch((e) => Promise.reject(e)); const dryRunServingRuntimeForTemplateCreationBackend = ( diff --git a/frontend/src/types.ts b/frontend/src/types.ts index 48e8be0f8e..50898f5b44 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -289,7 +289,7 @@ type K8sMetadata = { /** * @deprecated -- use the SDK version -- see k8sTypes.ts * All references that use this are un-vetted data against existing types, should be converted over - * to the new K8sResourceCommon from the SDK to keep everythung unified on one front. + * to the new K8sResourceCommon from the SDK to keep everything unified on one front. */ export type K8sResourceCommon = { apiVersion?: string; diff --git a/frontend/src/utilities/__tests__/addTypesToK8sListedResources.spec.ts b/frontend/src/utilities/__tests__/addTypesToK8sListedResources.spec.ts new file mode 100644 index 0000000000..9ad28eb769 --- /dev/null +++ b/frontend/src/utilities/__tests__/addTypesToK8sListedResources.spec.ts @@ -0,0 +1,36 @@ +import { K8sResourceCommon } from '@openshift/dynamic-plugin-sdk-utils'; +import { addTypesToK8sListedResources } from '~/utilities/addTypesToK8sListedResources'; + +const servingRuntimeTemplate = { + apiVersion: 'template.openshift.io/v1', + kind: 'TemplateList', + items: [ + { + metadata: { + name: 'test-model', + annotations: { + 'openshift.io/display-name': 'New OVMS Server', + }, + labels: { + 'opendatahub.io/dashboard': 'true', + }, + }, + }, + ], + metadata: { + resourceVersion: '24348645', + continue: '', + }, +}; + +describe('addTypesToK8sListedResources', () => { + it('should have apiVersion and kind as Template', () => { + const list = addTypesToK8sListedResources(servingRuntimeTemplate, 'Template'); + expect(list).not.toBe(servingRuntimeTemplate); + expect(list.items).toHaveLength(servingRuntimeTemplate.items.length); + list.items.forEach((i: Partial) => { + expect(i.apiVersion).toBe('template.openshift.io/v1'); + expect(i.kind).toBe('Template'); + }); + }); +}); diff --git a/frontend/src/utilities/addTypesToK8sListedResources.ts b/frontend/src/utilities/addTypesToK8sListedResources.ts new file mode 100644 index 0000000000..d11ee3ef8d --- /dev/null +++ b/frontend/src/utilities/addTypesToK8sListedResources.ts @@ -0,0 +1,14 @@ +import { K8sResourceCommon } from '@openshift/dynamic-plugin-sdk-utils'; +import { K8sResourceListResult } from '~/k8sTypes'; + +export const addTypesToK8sListedResources = >( + response: K8sResourceListResult, + kind: string, +): K8sResourceListResult => ({ + ...response, + items: response.items.map((i) => ({ + ...i, + apiVersion: response.apiVersion, + kind, + })), +});