From 703b6f4c8ace795276ca4cbb9980c8af09975c20 Mon Sep 17 00:00:00 2001 From: Radoslaw Szwajkowski Date: Fri, 29 Sep 2023 12:27:14 +0200 Subject: [PATCH] Retrieve VM template via jsonpath and accessor method Signed-off-by: Radoslaw Szwajkowski --- .../tabs/VirtualMachines/OpenShiftVirtualMachinesList.tsx | 4 +--- .../tabs/VirtualMachines/OpenShiftVirtualMachinesRow.tsx | 8 ++------ .../details/tabs/VirtualMachines/utils/helpers/vmProps.ts | 6 ++++++ 3 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/helpers/vmProps.ts diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenShiftVirtualMachinesList.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenShiftVirtualMachinesList.tsx index 8a4a5c8e9..b278e8391 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenShiftVirtualMachinesList.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenShiftVirtualMachinesList.tsx @@ -1,7 +1,6 @@ import React from 'react'; import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common'; -import { OpenshiftVM } from '@kubev2v/types'; import { ProviderVirtualMachinesList } from './components/ProviderVirtualMachinesList'; import { VmData } from './components'; @@ -37,8 +36,7 @@ const openShiftVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [ }, { resourceFieldId: 'template', - jsonPath: (data: VmData) => - (data?.vm as OpenshiftVM)?.object?.metadata?.labels?.['vm.kubevirt.io/template'] ?? '', + jsonPath: "$.vm.object.metadata.labels['vm.kubevirt.io/template']", label: t('Template'), isVisible: true, isIdentity: false, diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenShiftVirtualMachinesRow.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenShiftVirtualMachinesRow.tsx index c7927a1fd..990b0f0f2 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenShiftVirtualMachinesRow.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenShiftVirtualMachinesRow.tsx @@ -2,20 +2,16 @@ import React from 'react'; import { TableCell } from 'src/modules/Providers/utils'; import { ResourceField, RowProps } from '@kubev2v/common'; -import { OpenshiftVM } from '@kubev2v/types'; import { Td, Tr } from '@patternfly/react-table'; import { PowerStateCellRenderer } from './components/PowerStateCellRenderer'; +import { getVmTemplate } from './utils/helpers/vmProps'; import { VMCellProps, VmData, VMNameCellRenderer } from './components'; const cellRenderers: Record> = { name: VMNameCellRenderer, status: PowerStateCellRenderer, - template: ({ data }) => ( - - {(data?.vm as OpenshiftVM)?.object?.metadata?.labels?.['vm.kubevirt.io/template'] ?? ''} - - ), + template: ({ data }) => {getVmTemplate(data?.vm)}, }; const renderTd = ({ resourceData, resourceFieldId, resourceFields }: RenderTdProps) => { diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/helpers/vmProps.ts b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/helpers/vmProps.ts new file mode 100644 index 000000000..8237a419e --- /dev/null +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/helpers/vmProps.ts @@ -0,0 +1,6 @@ +import { ProviderVirtualMachine } from '@kubev2v/types'; + +export const getVmTemplate = (vm: ProviderVirtualMachine): string | undefined => + vm?.providerType === 'openshift' + ? vm.object?.metadata?.labels?.['vm.kubevirt.io/template'] + : undefined;