Skip to content

Commit

Permalink
Add template column for OpenShift VMs
Browse files Browse the repository at this point in the history
Display the name of the template used to create the VM.
The name is retrieved from label 'vm.kubevirt.io/template'.

Reference-Url: https://kubevirt.io/user-guide/virtual_machines/templates/#relationship-between-templates-and-vms
Signed-off-by: Radoslaw Szwajkowski <[email protected]>
  • Loading branch information
rszwajko committed Sep 28, 2023
1 parent 4683337 commit 4cbc3ef
Show file tree
Hide file tree
Showing 7 changed files with 454 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
"Filter by path": "Filter by path",
"Filter by power state": "Filter by power state",
"Filter by status": "Filter by status",
"Filter by template": "Filter by template",
"Filter by tenant": "Filter by tenant",
"Flavor": "Flavor",
"From": "From",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';

import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common';
import { OpenshiftVM } from '@kubev2v/types';

import { ProviderVirtualMachinesList } from './components/ProviderVirtualMachinesList';
import { VmData } from './components';
Expand Down Expand Up @@ -34,6 +35,19 @@ const openShiftVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [
},
sortable: true,
},
{
resourceFieldId: 'template',
jsonPath: (data: VmData) =>
(data?.vm as OpenshiftVM)?.object?.metadata?.labels?.['vm.kubevirt.io/template'] ?? '',
label: t('Template'),
isVisible: true,
isIdentity: false,
filter: {
type: 'freetext',
placeholderLabel: t('Filter by template'),
},
sortable: true,
},
];

export const OpenShiftVirtualMachinesList: React.FC<ProviderVirtualMachinesProps> = ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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';
Expand All @@ -9,6 +11,11 @@ import { VMCellProps, VmData, VMNameCellRenderer } from './components';
const cellRenderers: Record<string, React.FC<VMCellProps>> = {
name: VMNameCellRenderer,
status: PowerStateCellRenderer,
template: ({ data }) => (
<TableCell>
{(data?.vm as OpenshiftVM)?.object?.metadata?.labels?.['vm.kubevirt.io/template'] ?? ''}
</TableCell>
),
};

const renderTd = ({ resourceData, resourceFieldId, resourceFields }: RenderTdProps) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/mocks/src/definitions/basic/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
MOCK_VMWARE_HOST_TREE,
MOCK_VMWARE_VM_TREE,
} from './tree.mock';
import { MOCK_RHV_VMS, MOCK_VMWARE_VMS } from './vms.mock';
import { MOCK_OPENSHIFT_VMS, MOCK_RHV_VMS, MOCK_VMWARE_VMS } from './vms.mock';

const INVENTORY_PATH = '/api/proxy/plugin/forklift-console-plugin/forklift-inventory/';
const ALL_NAMESPACES_PATH = '/api/kubernetes/apis/forklift.konveyor.io/v1beta1/';
Expand Down Expand Up @@ -89,6 +89,7 @@ const paths = [
inventoryPath: INVENTORY_PATH,
ovirt: MOCK_RHV_VMS,
vsphere: MOCK_VMWARE_VMS,
openshift: MOCK_OPENSHIFT_VMS,
}),
...hosts({
providers: MOCK_INVENTORY_PROVIDERS,
Expand Down
134 changes: 133 additions & 1 deletion packages/mocks/src/definitions/basic/vms.mock.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
/* eslint-disable @cspell/spellchecker */
import { OVirtVM, VSphereVM } from '@kubev2v/types';
import { OpenshiftVM, OVirtVM, VSphereVM } from '@kubev2v/types';

import { MOCK_DISK_ATTACHMENTS } from './disks.mock';
import { MOCK_NICS } from './nicProfiles.mock';
import {
OPENSHIFT_01_UID,
OPENSHIFT_02_UID,
OPENSHIFT_03_UID,
OPENSHIFT_HOST_UID,
OpenshiftProviderIDs,
OVIRT_01_UID,
OVIRT_02_UID,
OVIRT_03_UID,
Expand Down Expand Up @@ -362,3 +367,130 @@ export const MOCK_RHV_VMS: { [uid in OvirtProviderIDs]: OVirtVM[] } = {
},
],
};

export const MOCK_OPENSHIFT_VMS: { [uid in OpenshiftProviderIDs]: OpenshiftVM[] } = {
[OPENSHIFT_01_UID]: [],
[OPENSHIFT_02_UID]: [],
[OPENSHIFT_03_UID]: [],
[OPENSHIFT_HOST_UID]: [
// source: https://kubevirt.io/user-guide/virtual_machines/templates/
{
name: 'rheltinyvm',
namespace: '',
selfLink: `providers/openshift/${OPENSHIFT_HOST_UID}/vms/3dcaf3ec-6b51-4ca0-8345-6d61841731d7`,
uid: '',
version: '',
object: {
kind: 'VirtualMachine',
apiVersion: 'kubevirt.io/v1',
metadata: {
annotations: {
['vm.kubevirt.io/flavor']: 'tiny',
['vm.kubevirt.io/os']: 'rhel8',
['vm.kubevirt.io/validations']: `
{
name: 'minimal-required-memory',
path: 'jsonpath::.spec.domain.resources.requests.memory',
rule: 'integer',
message: 'This VM requires more memory.',
min: 1610612736,
}`,
['vm.kubevirt.io/workload']: 'server',
},
labels: {
app: 'rheltinyvm',
['vm.kubevirt.io/template']: 'rhel8-server-tiny',
['vm.kubevirt.io/template.revision']: '45',
['vm.kubevirt.io/template.version']: '0.11.3',
},
name: 'rheltinyvm',
},
spec: {
dataVolumeTemplates: [
{
apiVersion: 'cdi.kubevirt.io/v1beta1',
kind: 'DataVolume',
metadata: {
name: 'rheltinyvm',
},
spec: {
pvc: {
accessModes: ['ReadWriteMany'],
resources: {
requests: {
storage: '30Gi',
},
},
},
source: {
pvc: {
name: 'rhel',
namespace: 'kubevirt',
},
},
},
},
],
running: false,
template: {
metadata: {
labels: {
['kubevirt.io/domain']: 'rheltinyvm',
['kubevirt.io/size']: 'tiny',
},
},
spec: {
domain: {
cpu: {
cores: 1,
sockets: 1,
threads: 1,
},
devices: {
disks: [
{
disk: {
bus: 'virtio',
},
name: 'rheltinyvm',
},
{
disk: {
bus: 'virtio',
},
name: 'cloudinitdisk',
},
],
interfaces: [
{
masquerade: {},
name: 'default',
},
],
networkInterfaceMultiqueue: true,
rng: {},
},
resources: {
requests: {
memory: '1.5Gi',
},
},
},
networks: [{ name: 'default', pod: {} }],
terminationGracePeriodSeconds: 180,
volumes: [
{
dataVolume: {
name: 'rheltinyvm',
},
name: 'rheltinyvm',
},
],
},
},
},
},
providerType: 'openshift',
},
],
};
4 changes: 4 additions & 0 deletions packages/mocks/src/definitions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
OpenShiftNamespace,
OpenShiftNetworkAttachmentDefinition,
OpenShiftStorageClass,
OpenshiftVM,
OpenstackTreeNode,
OpenstackVolumeType,
OVirtDisk,
Expand Down Expand Up @@ -61,15 +62,18 @@ export const vms = ({
inventoryPath,
vsphere,
ovirt,
openshift,
}: {
providers: ProvidersInventoryList;
inventoryPath: string;
vsphere: { [uid: string]: VSphereVM[] };
ovirt: { [uid: string]: OVirtVM[] };
openshift: { [uid: string]: OpenshiftVM[] };
}) =>
[
...providers.ovirt.map(({ selfLink, uid }) => [selfLink, ovirt[uid] ?? []]),
...providers.vsphere.map(({ selfLink, uid }) => [selfLink, vsphere[uid] ?? []]),
...providers.openshift.map(({ selfLink, uid }) => [selfLink, openshift[uid] ?? []]),
].map(([selfLink, mock]) => [`${inventoryPath}${selfLink}/vms`, mock]);

export const hosts = ({
Expand Down
Loading

0 comments on commit 4cbc3ef

Please sign in to comment.