Skip to content

Commit

Permalink
Filter OpenShift VMs by features
Browse files Browse the repository at this point in the history
Signed-off-by: Radoslaw Szwajkowski <rszwajko@redhat.com>
  • Loading branch information
rszwajko committed Oct 31, 2023
1 parent 94d7862 commit 84f7e47
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common';
import { ProviderVirtualMachinesList, VmData } from './components';
import { OpenShiftVirtualMachinesRow } from './OpenShiftVirtualMachinesRow';
import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines';
import { getVmPowerState } from './utils';
import { getOpenShiftFeatureMap, getVmPowerState } from './utils';

const openShiftVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [
{
Expand Down Expand Up @@ -33,6 +33,26 @@ const openShiftVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [
},
sortable: true,
},
{
resourceFieldId: 'features',
jsonPath: (data: VmData) => getOpenShiftFeatureMap(data?.vm),
label: t('Features'),
isVisible: true,
isIdentity: false,
filter: {
type: 'enum',
placeholderLabel: t('Filter by features'),
values: EnumToTuple({
numa: 'NUMA',
gpus: 'GPUs',
hostDevices: 'Host Devices',
persistentTpm: 'Persistent TPM',
persistentEfi: 'Persistent EFI',
dedicatedCpu: 'Dedicated CPU',
}),
},
sortable: true,
},
{
resourceFieldId: 'template',
jsonPath: "$.vm.object.metadata.labels['vm.kubevirt.io/template']",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ export const ProviderVirtualMachinesList: React.FC<ProviderVirtualMachinesListPr
userSettings={userSettings}
extraSupportedFilters={{
concerns: EnumFilter,
features: EnumFilter,
}}
extraSupportedMatchers={[concernsMatcher]}
extraSupportedMatchers={[concernsMatcher, featuresMatcher]}
/>
);
};
Expand All @@ -64,3 +65,8 @@ const concernsMatcher: ValueMatcher = {
matchValue: (concerns: Concern[]) => (filter: string) =>
Array.isArray(concerns) && concerns.some(({ category }) => category === filter),
};

const featuresMatcher: ValueMatcher = {
filterType: 'features',
matchValue: (features: { [key: string]: boolean }) => (filter: string) => !!features?.[filter],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ProviderVirtualMachine, V1DomainSpec } from '@kubev2v/types';

export const getOpenShiftFeatureMap = (vm: ProviderVirtualMachine) => {
if (vm.providerType !== 'openshift') {
return {};
}
const domain: V1DomainSpec = vm.object?.spec?.template?.spec?.domain;
if (!domain) {
return {};
}

return {
numa: !!domain.cpu?.numa,
gpus: !!domain.devices?.gpus?.length,
hostDevices: !!domain?.devices?.hostDevices?.length,
persistentTpm: domain?.devices?.tpm?.persistent,
persistentEfi: domain?.firmware?.bootloader?.efi?.persistent,

Check warning on line 17 in packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/helpers/getOpenShiftFeatureMap.ts

View workflow job for this annotation

GitHub Actions / Run linter and tests

Unknown word: "bootloader"
dedicatedCpu: domain?.cpu?.dedicatedCpuPlacement,
};
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @index(['./*', /style/g], f => `export * from '${f.path}';`)
export * from './getOpenShiftFeatureMap';
export * from './getVmPowerState';
export * from './vmProps';
// @endindex
19 changes: 17 additions & 2 deletions packages/types/src/types/k8s/V1VirtualMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ interface V1VirtualMachineInstanceSpec {

// Specification of the desired behavior of the VirtualMachineInstance on the host.
// Domain DomainSpec `json:"domain"`
domain: DomainSpec;
domain: V1DomainSpec;

// NodeSelector is a selector which must be true for the vmi to fit on a node.
// Selector which must match a node's labels for the vmi to be scheduled on that node.
Expand Down Expand Up @@ -235,7 +235,7 @@ interface V1VirtualMachineInstanceSpec {
//AccessCredentials []AccessCredential `json:"accessCredentials,omitempty"`
}

interface DomainSpec {
export interface V1DomainSpec {
// Resources describes the Compute Resources required by this vmi.
// Resources ResourceRequirements `json:"resources,omitempty"`
resources?: {
Expand All @@ -251,6 +251,8 @@ interface DomainSpec {
cores: number;
sockets: number;
threads: number;
dedicatedCpuPlacement?: boolean;
numa?: unknown;
};

// Memory allow specifying the VMI memory features.
Expand All @@ -264,6 +266,13 @@ interface DomainSpec {
// Firmware.
// +optional
// Firmware *Firmware `json:"firmware,omitempty"`
firmware?: {
bootloader?: {

Check warning on line 270 in packages/types/src/types/k8s/V1VirtualMachine.ts

View workflow job for this annotation

GitHub Actions / Run linter and tests

Unknown word: "bootloader"
efi?: {
persistent?: boolean;
};
};
};

// Clock sets the clock and timers of the vmi.
// +optional
Expand Down Expand Up @@ -355,6 +364,7 @@ interface Devices {
// +optional
// +listType=atomic
// GPUs []GPU `json:"gpus,omitempty"`
gpus?: unknown[];

// Filesystems describes filesystem which is connected to the vmi.
// +optional
Expand All @@ -365,4 +375,9 @@ interface Devices {
// +optional
// +listType=atomic
// HostDevices []HostDevice `json:"hostDevices,omitempty"`
hostDevices?: unknown[];

tpm?: {
persistent?: boolean;
};
}
1 change: 1 addition & 0 deletions packages/types/src/types/k8s/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export * from './K8sResourceCondition';
export * from './V1Namespace';
export * from './V1NetworkAttachmentDefinition';
export * from './V1Secret';
export * from './V1VirtualMachine';
// @endindex

0 comments on commit 84f7e47

Please sign in to comment.