From 545b4b87444cf7175badc20323e6de9a2592cd28 Mon Sep 17 00:00:00 2001 From: Sharon Gratch Date: Wed, 13 Nov 2024 21:15:13 +0200 Subject: [PATCH] Display a Warnning if preserve static IPs are enabled with pod network Reference:https://issues.redhat.com/browse/MTV-1503 In case there is no critical error for a plan and in addition, the plan is set to enable the preserve static IPs for the VMs while at least one of the destination network mappings is set to 'Pod Networking' type => then display a warning alert at the head of plan page. Signed-off-by: Sharon Gratch --- .../en/plugin__forklift-console-plugin.json | 4 ++ .../details/components/PlanPageHeadings.tsx | 49 +++++++++++++++++-- .../components/PlanWarningCondition.tsx | 27 ++++++++++ .../Plans/views/details/components/index.ts | 1 + 4 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 packages/forklift-console-plugin/src/modules/Plans/views/details/components/PlanWarningCondition.tsx diff --git a/packages/forklift-console-plugin/locales/en/plugin__forklift-console-plugin.json b/packages/forklift-console-plugin/locales/en/plugin__forklift-console-plugin.json index e3448bcb9..fc67b574b 100644 --- a/packages/forklift-console-plugin/locales/en/plugin__forklift-console-plugin.json +++ b/packages/forklift-console-plugin/locales/en/plugin__forklift-console-plugin.json @@ -197,6 +197,7 @@ "First root device": "First root device", "Flavor": "Flavor", "Folder": "Folder", + "For fixing, update the destination network mappings to avoid using the 'Pod Networking' type.": "For fixing, update the destination network mappings to avoid using the 'Pod Networking' type.", "GPUs/Host Devices": "GPUs/Host Devices", "Hide from view": "Hide from view", "Hide values": "Hide values", @@ -373,6 +374,7 @@ "Preserve static IPs": "Preserve static IPs", "Preserve the CPU model and flags the VM runs with in its oVirt cluster.": "Preserve the CPU model and flags the VM runs with in its oVirt cluster.", "Preserve the static IPs of virtual machines migrated from vSphere.": "Preserve the static IPs of virtual machines migrated from vSphere.", + "Preserving static IPs of VMs might fail": "Preserving static IPs of VMs might fail", "Product": "Product", "Progress": "Progress", "Project": "Project", @@ -483,6 +485,8 @@ "The Manager CA certificate unless it was replaced by a third-party certificate, in which case, enter the Manager Apache CA certificate.": "The Manager CA certificate unless it was replaced by a third-party certificate, in which case, enter the Manager Apache CA certificate.", "The password for the ESXi host admin": "The password for the ESXi host admin", "The plan is not ready - ": "The plan is not ready - ", + "The plan is set to preserve the static IPs of VMs mapped to a Pod network type. This is not supported and therefore VM IPs can be changed during the migration process.": "The plan is set to preserve the static IPs of VMs mapped to a Pod network type. This is not supported and therefore VM IPs can be changed during the migration process.", + "The plan migration might not work as expected - ": "The plan migration might not work as expected - ", "The provider is not ready - ": "The provider is not ready - ", "The provider is not ready.": "The provider is not ready.", "The provider's CA certificate will be validated.": "The provider's CA certificate will be validated.", diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/details/components/PlanPageHeadings.tsx b/packages/forklift-console-plugin/src/modules/Plans/views/details/components/PlanPageHeadings.tsx index c01927c5b..0a5756015 100644 --- a/packages/forklift-console-plugin/src/modules/Plans/views/details/components/PlanPageHeadings.tsx +++ b/packages/forklift-console-plugin/src/modules/Plans/views/details/components/PlanPageHeadings.tsx @@ -7,13 +7,20 @@ import { useModal } from 'src/modules/Providers/modals'; import { PageHeadings } from 'src/modules/Providers/utils'; import { useForkliftTranslation } from 'src/utils'; -import { PlanModel, PlanModelGroupVersionKind, V1beta1Plan } from '@kubev2v/types'; +import { + NetworkMapModelGroupVersionKind, + PlanModel, + PlanModelGroupVersionKind, + V1beta1NetworkMap, + V1beta1Plan, +} from '@kubev2v/types'; import { useK8sWatchResource } from '@openshift-console/dynamic-plugin-sdk'; import { Button, Level, LevelItem, PageSection } from '@patternfly/react-core'; import StartIcon from '@patternfly/react-icons/dist/esm/icons/play-icon'; import ReStartIcon from '@patternfly/react-icons/dist/esm/icons/redo-icon'; import PlanCriticalCondition from './PlanCriticalCondition'; +import PlanWarningCondition from './PlanWarningCondition'; export const PlanPageHeadings: React.FC<{ name: string; namespace: string }> = ({ name, @@ -22,13 +29,20 @@ export const PlanPageHeadings: React.FC<{ name: string; namespace: string }> = ( const { t } = useForkliftTranslation(); const { showModal } = useModal(); - const [plan, loaded, error] = useK8sWatchResource({ + const [plan, planLoaded, planError] = useK8sWatchResource({ groupVersionKind: PlanModelGroupVersionKind, namespaced: true, name, namespace, }); + const [netMaps, netMapsLoaded, netMapsError] = useK8sWatchResource({ + groupVersionKind: NetworkMapModelGroupVersionKind, + namespaced: true, + isList: true, + namespace, + }); + const permissions = useGetDeleteAndEditAccessReview({ model: PlanModel, namespace, @@ -44,10 +58,25 @@ export const PlanPageHeadings: React.FC<{ name: string; namespace: string }> = ( const buttonStartIcon = canReStart ? : ; const criticalCondition = - loaded && - !error && + planLoaded && + !planError && plan?.status?.conditions?.find((condition) => condition?.category === 'Critical'); + /** + * Check if the preserve static IPs is enabled with pod networking mapping. + */ + const preserveIpsWithPodMapCondition = (): boolean => { + if (!netMapsLoaded || netMapsError) return false; + + const isPreserveStaticIPs = plan?.spec?.preserveStaticIPs; + const planNetMaps = netMaps + ? netMaps.find((net) => net?.metadata?.name === plan?.spec?.map?.network?.name) + : null; + const isMapToPod = planNetMaps?.spec?.map.find((map) => map.destination.type === 'pod') != null; + + return isPreserveStaticIPs && isMapToPod; + }; + if (criticalCondition) { alerts.push( = ( key={'providerCriticalCondition'} />, ); + } else if (preserveIpsWithPodMapCondition()) { + alerts.push( + , + ); } const onClick = () => { diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/details/components/PlanWarningCondition.tsx b/packages/forklift-console-plugin/src/modules/Plans/views/details/components/PlanWarningCondition.tsx new file mode 100644 index 000000000..4da45a574 --- /dev/null +++ b/packages/forklift-console-plugin/src/modules/Plans/views/details/components/PlanWarningCondition.tsx @@ -0,0 +1,27 @@ +import React from 'react'; +import { useTranslation } from 'react-i18next'; +import Linkify from 'react-linkify'; + +import { Alert, Text, TextContent, TextVariants } from '@patternfly/react-core'; + +export const PlanWarningCondition: React.FC<{ + type: string; + message: string; + suggestion: string; +}> = ({ type, message, suggestion }) => { + const { t } = useTranslation(); + return ( + + + + {message || '-'} +
+
+ {suggestion || '-'} +
+
+
+ ); +}; + +export default PlanWarningCondition; diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/details/components/index.ts b/packages/forklift-console-plugin/src/modules/Plans/views/details/components/index.ts index 4d84d088a..a96999400 100644 --- a/packages/forklift-console-plugin/src/modules/Plans/views/details/components/index.ts +++ b/packages/forklift-console-plugin/src/modules/Plans/views/details/components/index.ts @@ -7,6 +7,7 @@ export * from './MappingListItem'; export * from './MigrationsSection'; export * from './PlanCriticalCondition'; export * from './PlanPageHeadings'; +export * from './PlanWarningCondition'; export * from './ProvidersSection'; export * from './SettingsSection'; export * from './Suspend';