Skip to content

Commit

Permalink
Merge pull request #300 from red-hat-data-services/main
Browse files Browse the repository at this point in the history
Last min sync for 1.34
  • Loading branch information
andrewballantyne authored Oct 6, 2023
2 parents b1ae20c + b9f4a84 commit 474ffd8
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 3 deletions.
11 changes: 11 additions & 0 deletions frontend/src/k8sTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TResource extends Partial<K8sResourceCommon>> = {
apiVersion: string;
kind: string;
items: TResource[];
metadata: {
resourceVersion: string;
continue: string;
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const CustomServingRuntimeTableRow: React.FC<CustomServingRuntimeTableRowProps>
}}
/>
<Td dataLabel="Name" width={70} className="pf-u-text-break-word">
<ResourceNameTooltip resource={template.objects[0]}>
<ResourceNameTooltip resource={template}>
{getServingRuntimeDisplayNameFromTemplate(template)}
</ResourceNameTooltip>
{templateOOTB && <Label>Pre-installed</Label>}
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/services/templateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ 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,
labelSelector?: string,
): Promise<TemplateKind[]> =>
axios
.get(`/api/templates/${namespace}`, { params: { labelSelector } })
.then((response) => response.data.items)
.then((response) => addTypesToK8sListedResources<TemplateKind>(response.data, 'Template').items)
.catch((e) => Promise.reject(e));

const dryRunServingRuntimeForTemplateCreationBackend = (
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<K8sResourceCommon>) => {
expect(i.apiVersion).toBe('template.openshift.io/v1');
expect(i.kind).toBe('Template');
});
});
});
14 changes: 14 additions & 0 deletions frontend/src/utilities/addTypesToK8sListedResources.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { K8sResourceCommon } from '@openshift/dynamic-plugin-sdk-utils';
import { K8sResourceListResult } from '~/k8sTypes';

export const addTypesToK8sListedResources = <TResource extends Partial<K8sResourceCommon>>(
response: K8sResourceListResult<TResource>,
kind: string,
): K8sResourceListResult<TResource> => ({
...response,
items: response.items.map((i) => ({
...i,
apiVersion: response.apiVersion,
kind,
})),
});

0 comments on commit 474ffd8

Please sign in to comment.