Skip to content

Commit

Permalink
Render VM name as resource link for local cluster
Browse files Browse the repository at this point in the history
Signed-off-by: Radoslaw Szwajkowski <[email protected]>
  • Loading branch information
rszwajko committed Nov 28, 2023
1 parent 5f7dc23 commit a388259
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { ResourceField, RowProps } from '@kubev2v/common';
import { Td, Tr } from '@patternfly/react-table';

import { PowerStateCellRenderer } from './components/PowerStateCellRenderer';
import { VMCellProps, VmData, VMNameCellRenderer } from './components';
import { VmResourceLinkRenderer } from './components/VmResourceLinkRenderer';
import { VMCellProps, VmData } from './components';
import { getVmTemplate } from './utils';

const cellRenderers: Record<string, React.FC<VMCellProps>> = {
name: VMNameCellRenderer,
name: VmResourceLinkRenderer,
status: PowerStateCellRenderer,
template: ({ data }) => <TableCell>{getVmTemplate(data?.vm)}</TableCell>,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ProviderVirtualMachine } from '@kubev2v/types';
export interface VmData {
vm: ProviderVirtualMachine;
name: string;
isProviderLocalTarget?: boolean;
}

export interface VMCellProps {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import { TableCell } from 'src/modules/Providers/utils';
import { groupVersionKindForObj } from 'src/utils/resources';

import { ResourceLink } from '@openshift-console/dynamic-plugin-sdk';

import { VMCellProps } from './VMCellProps';
import { VMNameCellRenderer } from './VMNameCellRenderer';

export const VmResourceLinkRenderer: React.FC<VMCellProps> = (props) => {
const { name, isProviderLocalTarget, vm } = props.data;
if (vm.providerType === 'openshift' && isProviderLocalTarget) {
return (
<TableCell>
<ResourceLink
name={name}
groupVersionKind={groupVersionKindForObj(vm.object)}
namespace={vm.namespace}
/>
</TableCell>
);
}

return <VMNameCellRenderer {...props} />;
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useProviderInventory, UseProviderInventoryParams } from 'src/modules/Providers/hooks';
import { ProviderData } from 'src/modules/Providers/utils';
import { isProviderLocalTarget } from 'src/utils/resources';

import { ProviderVirtualMachine } from '@kubev2v/types';

Expand Down Expand Up @@ -44,6 +45,7 @@ export const useInventoryVms = (
providerType: provider?.spec?.type,
} as ProviderVirtualMachine,
name: vm.name,
isProviderLocalTarget: isProviderLocalTarget(validProvider),
}))
: [];

Expand Down
5 changes: 4 additions & 1 deletion packages/mocks/src/definitions/basic/vms.mock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable @cspell/spellchecker */
import { OpenshiftVM, OVirtVM, VSphereVM } from '@kubev2v/types';

import { NAMESPACE_FORKLIFT } from '../utils';

import { MOCK_DISK_ATTACHMENTS } from './disks.mock';
import { MOCK_NICS } from './nicProfiles.mock';
import {
Expand Down Expand Up @@ -376,7 +378,7 @@ export const MOCK_OPENSHIFT_VMS: { [uid in OpenshiftProviderIDs]: OpenshiftVM[]
// source: https://kubevirt.io/user-guide/virtual_machines/templates/
{
name: 'rheltinyvm',
namespace: '',
namespace: NAMESPACE_FORKLIFT,
selfLink: `providers/openshift/${OPENSHIFT_HOST_UID}/vms/3dcaf3ec-6b51-4ca0-8345-6d61841731d7`,
uid: '',
version: '',
Expand Down Expand Up @@ -404,6 +406,7 @@ export const MOCK_OPENSHIFT_VMS: { [uid in OpenshiftProviderIDs]: OpenshiftVM[]
['vm.kubevirt.io/template.version']: '0.11.3',
},
name: 'rheltinyvm',
namespace: NAMESPACE_FORKLIFT,
},
spec: {
dataVolumeTemplates: [
Expand Down

0 comments on commit a388259

Please sign in to comment.