Skip to content

CNV-60049: fix interface modal with udn #2583

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

Merged
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 @@ -2,9 +2,10 @@ import { useMemo } from 'react';

import { NetworkAttachmentDefinitionModelGroupVersionKind } from '@kubevirt-ui/kubevirt-api/console';
import useNADListPermissions from '@kubevirt-utils/components/NetworkInterfaceModal/components/hooks/useNADListPermissions';
import { getExtraNADResources } from '@kubevirt-utils/components/NetworkInterfaceModal/components/hooks/utils';
import { getName } from '@kubevirt-utils/resources/shared';
import { PRIMARY_UDN_BINDING } from '@kubevirt-utils/resources/vm/utils/network/constants';
import {
filterUDNNads,
getExtraNADResources,
} from '@kubevirt-utils/components/NetworkInterfaceModal/components/hooks/utils';
import { isEmpty } from '@kubevirt-utils/utils/utils';
import { K8sResourceCommon, useK8sWatchResources } from '@openshift-console/dynamic-plugin-sdk';

Expand All @@ -24,9 +25,8 @@ const useNADsData: UseNADsData = (namespace) => {
const accumulatedData = useMemo(() => {
return (Object.values(data) || [])?.reduce(
(acc, nads) => {
const nadsWithNoPrimaryUDNBinding =
nads?.data?.filter((nad) => getName(nad) !== PRIMARY_UDN_BINDING) || [];
acc.nads.push(...nadsWithNoPrimaryUDNBinding);
const availableNADs = filterUDNNads(nads?.data || []);
acc.nads.push(...availableNADs);
acc.loaded = acc.loaded && (!isEmpty(nads?.loadError) || nads?.loaded);
acc.loadError = isEmpty(nads?.loadError) ? acc.loadError : nads?.loadError;
return acc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {
OPENSHIFT_MULTUS_NS,
OPENSHIFT_SRIOV_NETWORK_OPERATOR_NS,
} from '@kubevirt-utils/constants/constants';
import { getLabel } from '@kubevirt-utils/resources/shared';
import { UDN_LABEL } from '@kubevirt-utils/resources/udn/constants';
import { isEmpty } from '@kubevirt-utils/utils/utils';
import { K8sResourceCommon } from '@openshift-console/dynamic-plugin-sdk';

const resources = {
default: {
Expand Down Expand Up @@ -41,3 +44,6 @@ export const getExtraNADResources = (
return newMap;
}, {});
};

export const filterUDNNads = (nads: K8sResourceCommon[]) =>
nads?.filter((nad) => getLabel(nad, UDN_LABEL) === undefined);
1 change: 1 addition & 0 deletions src/utils/resources/udn/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const LAYER2_TOPOLOGY = 'layer2';
export const LAYER3_TOPOLOGY = 'layer3';
export const LOCALNET_TOPOLOGY = 'localnet';
export const UDN_LABEL = 'k8s.ovn.org/user-defined-network';

export const PrimaryTopologies = [LAYER2_TOPOLOGY, LAYER3_TOPOLOGY];
export const SecondaryTopologies = [LOCALNET_TOPOLOGY];
2 changes: 0 additions & 2 deletions src/utils/resources/vm/utils/network/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,3 @@ const labels2types: LabelMap = Object.fromEntries(

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

export const PRIMARY_UDN_BINDING = 'primary-udn-kubevirt-binding';