Skip to content

Commit

Permalink
Merge pull request #2388 from rszwajko/webhookWarning
Browse files Browse the repository at this point in the history
CNV-54166: Admission webhook warning about non existing properties l2bridge and deviceIndex
  • Loading branch information
openshift-merge-bot[bot] authored Jan 27, 2025
2 parents 56d52ce + 48c1605 commit a980168
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,15 @@ const HardwareDevicesModal: FC<HardwareDevicesModalProps> = ({

const disableSubmit = devices.some((device) => isEmpty(device?.deviceName));

const toK8sDevice = ({ deviceName, name }: HardwareDeviceModalRow): V1GPU | V1HostDevice => ({
deviceName,
name,
});

const updatedVM = produceVMDevices(vm, (vmDraft: V1VirtualMachine) => {
vmDraft.spec.template.spec.domain.devices[type] = !isEmpty(devices) ? devices : null;
vmDraft.spec.template.spec.domain.devices[type] = isEmpty(devices)
? null
: devices.map(toK8sDevice);
});

return (
Expand Down
8 changes: 7 additions & 1 deletion src/utils/components/NetworkInterfaceModal/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {
getInterfaces,
getNetworks,
} from '@kubevirt-utils/resources/vm';
import { BRIDGE, UDN_BINDING_NAME } from '@kubevirt-utils/resources/vm/utils/constants';
import {
interfaceLabels,
interfacesTypes,
NetworkPresentation,
} from '@kubevirt-utils/resources/vm/utils/network/constants';
Expand Down Expand Up @@ -128,11 +130,15 @@ export const createInterface = (
interfaceMACAddress: string,
interfaceType = interfacesTypes.bridge,
): V1Interface => {
const resolvedInterfaceProp = interfaceLabels[interfaceType];
const validInterfaceProp: keyof V1Interface =
resolvedInterfaceProp === UDN_BINDING_NAME ? BRIDGE : resolvedInterfaceProp;

return {
[interfaceType?.replace('-', '')?.toLowerCase()]: {},
macAddress: interfaceMACAddress,
model: interfaceModel,
name: nicName,
[validInterfaceProp]: {},
};
};

Expand Down
3 changes: 3 additions & 0 deletions src/utils/resources/vm/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export const DEFAULT_NETWORK_INTERFACE: V1Interface = { masquerade: {}, name: 'd
export const DEFAULT_NETWORK: V1Network = { name: 'default', pod: {} };

export const UDN_BINDING_NAME = 'l2bridge';
export const BRIDGE = 'bridge';
export const MASQUERADE = 'masquerade';
export const SRIOV = 'sriov';

export enum UPDATE_STRATEGIES {
Migration = 'Migration',
Expand Down
31 changes: 26 additions & 5 deletions src/utils/resources/vm/utils/network/constants.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,47 @@
/* eslint-disable require-jsdoc */
import { V1Interface, V1Network } from '@kubevirt-ui/kubevirt-api/kubevirt';

import { UDN_BINDING_NAME } from '../constants';
import { BRIDGE, MASQUERADE, SRIOV, UDN_BINDING_NAME } from '../constants';

export type NetworkPresentation = {
iface: V1Interface;
network: V1Network;
};

const typeHandler = {
get(target, prop) {
get(target: TypeMap, prop: string) {
return target[prop] ?? target.bridge;
},
};

const types = {
const labelHandler = {
get(target: LabelMap, prop: string) {
return target[prop] ?? BRIDGE;
},
};

export type InterfaceTypes =
| typeof BRIDGE
| typeof MASQUERADE
| typeof SRIOV
| typeof UDN_BINDING_NAME;
type LabelMap = { [key: string]: InterfaceTypes };
type TypeMap = { [key in InterfaceTypes]: string };

const types2labels: TypeMap = {
bridge: 'Bridge',
l2bridge: 'L2 bridge',
masquerade: 'Masquerade',
sriov: 'SR-IOV',
[UDN_BINDING_NAME]: 'L2 bridge',
};

export const interfacesTypes = new Proxy(types, typeHandler);
const labels2types: LabelMap = Object.fromEntries(
Object.entries(types2labels).map(
([type, label]: [InterfaceTypes, string]): [string, InterfaceTypes] => [label, type],
),
);

export const interfacesTypes = new Proxy<TypeMap>(types2labels, typeHandler);
export const interfaceLabels = new Proxy<LabelMap>(labels2types, labelHandler);

export const PRIMARY_UDN_BINDING = 'primary-udn-kubevirt-binding';
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import * as React from 'react';
import { WizardDescriptionItem } from '@catalog/wizard/components/WizardDescriptionItem';
import { V1Interface, V1Network } from '@kubevirt-ui/kubevirt-api/kubevirt';
import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation';
import { BRIDGE, MASQUERADE, SRIOV } from '@kubevirt-utils/resources/vm/utils/constants';
import { getNetworkInterfaceRowData } from '@kubevirt-utils/resources/vm/utils/network/rowData';
import { getPrintableNetworkInterfaceType } from '@kubevirt-utils/resources/vm/utils/network/selectors';
import { DescriptionList, Stack, StackItem } from '@patternfly/react-core';

export const interfacesTypes = {
bridge: 'Bridge',
masquerade: 'Masquerade',
sriov: 'SR-IOV',
[BRIDGE]: 'Bridge',
[MASQUERADE]: 'Masquerade',
[SRIOV]: 'SR-IOV',
};

export const WizardOverviewNetworksTable: React.FC<{
Expand Down

0 comments on commit a980168

Please sign in to comment.