Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add template column for OpenShift VMs #742

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -34,6 +34,18 @@ const openShiftVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [
},
sortable: true,
},
{
resourceFieldId: 'template',
jsonPath: "$.vm.object.metadata.labels['vm.kubevirt.io/template']",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice !, didn't know you can do this 👍

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,14 +1,17 @@
import React from 'react';
import { TableCell } from 'src/modules/Providers/utils';

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 { getVmTemplate } from './utils';

const cellRenderers: Record<string, React.FC<VMCellProps>> = {
name: VMNameCellRenderer,
status: PowerStateCellRenderer,
template: ({ data }) => <TableCell>{getVmTemplate(data?.vm)}</TableCell>,
};

const renderTd = ({ resourceData, resourceFieldId, resourceFields }: RenderTdProps) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @index(['./*', /style/g], f => `export * from '${f.path}';`)
export * from './getHighestPriorityConcern';
export * from './getVmPowerState';
export * from './vmProps';
// @endindex
Original file line number Diff line number Diff line change
@@ -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;
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