Skip to content

Commit

Permalink
Add template column for OpenShift VMs
Browse files Browse the repository at this point in the history
Signed-off-by: Radoslaw Szwajkowski <[email protected]>
  • Loading branch information
rszwajko committed Sep 27, 2023
1 parent 6e5209c commit 2c685d4
Show file tree
Hide file tree
Showing 5 changed files with 448 additions and 2 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
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: '',
namespace: '',
selfLink: '',
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',
},
],
};
Loading

0 comments on commit 2c685d4

Please sign in to comment.