Skip to content

Commit

Permalink
Merge pull request #2316 from openshift-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…2261-to-release-4.17

[release-4.17] CNV-50914: Support for ephemeral nic
  • Loading branch information
openshift-merge-bot[bot] authored Dec 16, 2024
2 parents d4d3f53 + c916145 commit 5b26f50
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 14 deletions.
1 change: 1 addition & 0 deletions locales/en/plugin__kubevirt-plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@
"Enter value": "Enter value",
"Environment": "Environment",
"environment disk": "environment disk",
"Ephemeral": "Ephemeral",
"Ephemeral disk (Container image)": "Ephemeral disk (Container image)",
"Error": "Error",
"Error checking for usages of this PVC.": "Error checking for usages of this PVC.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.ephemeral-badge {
margin-left: var(--pf-global--spacer--sm);
}
17 changes: 17 additions & 0 deletions src/utils/components/badges/EphemeralBadge/EphemeralBadge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React, { FC } from 'react';

import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation';
import { Label } from '@patternfly/react-core';

import './EphemeralBadge.scss';

const EphemeralBadge: FC = () => {
const { t } = useKubevirtTranslation();
return (
<Label className="ephemeral-badge" color="purple">
{t('Ephemeral')}
</Label>
);
};

export default EphemeralBadge;
2 changes: 1 addition & 1 deletion src/utils/resources/vm/utils/network/rowData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const getNetworkInterfaceRowData = (
const network = networks?.find((net) => net.name === iface.name);
return {
iface,
metadata: { name: network.name },
metadata: { name: network?.name },
network,
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ const NetworkInterfaceRow: FC<
return (
<>
<TableData activeColumnIDs={activeColumnIDs} id="name">
{network.name}
{network?.name || NO_DATA_DASH}
</TableData>
<TableData activeColumnIDs={activeColumnIDs} id="model">
{iface.model || NO_DATA_DASH}
</TableData>
<TableData activeColumnIDs={activeColumnIDs} id="network">
{network.pod ? t('Pod networking') : network.multus?.networkName || NO_DATA_DASH}
{network?.pod ? t('Pod networking') : network?.multus?.networkName || NO_DATA_DASH}
</TableData>
<TableData activeColumnIDs={activeColumnIDs} id="type">
{getPrintableNetworkInterfaceType(iface)}
Expand All @@ -40,7 +40,7 @@ const NetworkInterfaceRow: FC<
id=""
>
<NetworkInterfaceActions
nicName={network.name}
nicName={network?.name}
nicPresentation={{ iface, network }}
onUpdateVM={onUpdateVM}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {

import useNetworkColumns from '../../hooks/useNetworkColumns';
import useNetworkRowFilters from '../../hooks/useNetworkRowFilters';
import { isPendingHotPlugNIC, isPendingRemoval } from '../../utils/utils';
import { isInterfaceEphemeral, isPendingHotPlugNIC, isPendingRemoval } from '../../utils/utils';

import AutoAttachedNetworkEmptyState from './AutoAttachedNetworkEmptyState';
import NetworkInterfaceRow from './NetworkInterfaceRow';
Expand Down Expand Up @@ -54,7 +54,7 @@ const NetworkInterfaceList: FC<NetworkInterfaceTableProps> = ({ vm, vmi }) => {
loaded={!isEmpty(vm)}
loadError={false}
Row={NetworkInterfaceRow}
rowData={{ isPending, vm }}
rowData={{ isInterfaceEphemeral, isPending, vm }}
unfilteredData={data}
/>
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import React, { FC } from 'react';

import { V1Network, V1VirtualMachine } from '@kubevirt-ui/kubevirt-api/kubevirt';
import {
V1Network,
V1VirtualMachine,
V1VirtualMachineInstanceNetworkInterface,
} from '@kubevirt-ui/kubevirt-api/kubevirt';
import EphemeralBadge from '@kubevirt-utils/components/badges/EphemeralBadge/EphemeralBadge';
import PendingBadge from '@kubevirt-utils/components/badges/PendingBadge/PendingBadge';
import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation';
import { NO_DATA_DASH } from '@kubevirt-utils/resources/vm/utils/constants';
import { NetworkPresentation } from '@kubevirt-utils/resources/vm/utils/network/constants';
import { getPrintableNetworkInterfaceType } from '@kubevirt-utils/resources/vm/utils/network/selectors';
import { RowProps, TableData } from '@openshift-console/dynamic-plugin-sdk';

import { isInterfaceEphemeral } from '../../utils/utils';

import NetworkInterfaceActions from './NetworkInterfaceActions';

export type NetworkInterfaceRowProps = {
Expand All @@ -17,36 +24,45 @@ export type NetworkInterfaceRowProps = {
const NetworkInterfaceRow: FC<
RowProps<
NetworkPresentation,
{ isPending: (network: V1Network) => boolean; vm: V1VirtualMachine }
{
isInterfaceEphemeral: (
network: V1Network,
iface: V1VirtualMachineInstanceNetworkInterface,
) => undefined | V1VirtualMachineInstanceNetworkInterface;
isPending: (network: V1Network) => boolean;
vm: V1VirtualMachine;
}
>
> = ({ activeColumnIDs, obj: { iface, network }, rowData: { isPending, vm } }) => {
const { t } = useKubevirtTranslation();
const ephemeralNic = isInterfaceEphemeral(network, iface);

return (
<>
<TableData activeColumnIDs={activeColumnIDs} id="name">
{network.name}
{isPending(network) && <PendingBadge />}
{network?.name || ephemeralNic?.interfaceName || NO_DATA_DASH}
{isPending(network) && !ephemeralNic && <PendingBadge />}
{ephemeralNic && <EphemeralBadge />}
</TableData>
<TableData activeColumnIDs={activeColumnIDs} id="model">
{iface.model || NO_DATA_DASH}
</TableData>
<TableData activeColumnIDs={activeColumnIDs} id="network">
{network.pod ? t('Pod networking') : network.multus?.networkName || NO_DATA_DASH}
{network?.pod ? t('Pod networking') : network?.multus?.networkName || NO_DATA_DASH}
</TableData>
<TableData activeColumnIDs={activeColumnIDs} id="type">
{getPrintableNetworkInterfaceType(iface)}
</TableData>
<TableData activeColumnIDs={activeColumnIDs} id="macAddress">
{iface.macAddress || NO_DATA_DASH}
{iface?.macAddress || ephemeralNic?.mac || NO_DATA_DASH}
</TableData>
<TableData
activeColumnIDs={activeColumnIDs}
className="dropdown-kebab-pf pf-v5-c-table__action"
id=""
>
<NetworkInterfaceActions
nicName={network.name}
nicName={network?.name}
nicPresentation={{ iface, network }}
vm={vm}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { V1VirtualMachine, V1VirtualMachineInstance } from '@kubevirt-ui/kubevirt-api/kubevirt';
import {
V1Interface,
V1Network,
V1VirtualMachine,
V1VirtualMachineInstance,
V1VirtualMachineInstanceNetworkInterface,
} from '@kubevirt-ui/kubevirt-api/kubevirt';
import { getAutoAttachPodInterface, getInterfaces } from '@kubevirt-utils/resources/vm';
import { DEFAULT_NETWORK_INTERFACE } from '@kubevirt-utils/resources/vm/utils/constants';
import { getVMIInterfaces, getVMIStatusInterfaces } from '@kubevirt-utils/resources/vmi';
Expand Down Expand Up @@ -31,6 +37,14 @@ export const isPendingHotPlugNIC = (
export const interfaceNotFound = (vm: V1VirtualMachine, nicName: string) =>
!Boolean(getInterfaces(vm)?.find((iface) => iface?.name === nicName));

//special case - when u add ephemeral nic from vm console terminal
export const isInterfaceEphemeral = (network: V1Network, iface: V1Interface) => {
const ifaceVMIStatus = iface as V1VirtualMachineInstanceNetworkInterface;
const ifaceVMI = !network && ifaceVMIStatus.infoSource === 'guest-agent' && ifaceVMIStatus;

return ifaceVMI;
};

export const isPendingRemoval = (
vm: V1VirtualMachine,
vmi: V1VirtualMachineInstance,
Expand Down

0 comments on commit 5b26f50

Please sign in to comment.