From e8f26a2e1f888b43234afb7cd97a4c93bfe16dc3 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 | 8 ++- .../NetworkMapCriticalConditions.tsx | 3 +- .../components/PlanCriticalConditions.tsx | 3 +- .../components/PlanCriticalCondition.tsx | 12 ++--- .../details/components/PlanPageHeadings.tsx | 51 +++++++++++++++++-- .../components/PlanWarningCondition.tsx | 31 +++++++++++ .../Plans/views/details/components/index.ts | 1 + .../components/ProviderCriticalCondition.tsx | 5 +- .../StorageMapCriticalConditions.tsx | 3 +- .../src/utils/constants.ts | 1 + .../src/utils/index.ts | 1 + 11 files changed, 101 insertions(+), 18 deletions(-) create mode 100644 packages/forklift-console-plugin/src/modules/Plans/views/details/components/PlanWarningCondition.tsx create mode 100644 packages/forklift-console-plugin/src/utils/constants.ts 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..171476ee2 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", @@ -482,8 +484,10 @@ "The limit for memory usage by the inventory container, specified in Megabytes (Mi). Default value is 1000Mi.": "The limit for memory usage by the inventory container, specified in Megabytes (Mi). Default value is 1000Mi.", "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 provider is not ready - ": "The provider is not ready - ", + "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.", "The provider's CA certificate won't be validated.": "The provider's CA certificate won't be validated.", diff --git a/packages/forklift-console-plugin/src/modules/NetworkMaps/components/NetworkMapCriticalConditions.tsx b/packages/forklift-console-plugin/src/modules/NetworkMaps/components/NetworkMapCriticalConditions.tsx index e953a6772..3c72f03f7 100644 --- a/packages/forklift-console-plugin/src/modules/NetworkMaps/components/NetworkMapCriticalConditions.tsx +++ b/packages/forklift-console-plugin/src/modules/NetworkMaps/components/NetworkMapCriticalConditions.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { useTranslation } from 'react-i18next'; import Linkify from 'react-linkify'; +import { EMPTY_MSG } from 'src/utils/constants'; import { Alert, Text, TextContent, TextVariants } from '@patternfly/react-core'; @@ -13,7 +14,7 @@ export const NetworkMapCriticalConditions: React.FC<{ type: string; message: str - {message || '-'} + {message || EMPTY_MSG}
{t('To troubleshoot, check the Forklift controller pod logs.')}
diff --git a/packages/forklift-console-plugin/src/modules/Plans/components/PlanCriticalConditions.tsx b/packages/forklift-console-plugin/src/modules/Plans/components/PlanCriticalConditions.tsx index 56305ad7d..aedc2957b 100644 --- a/packages/forklift-console-plugin/src/modules/Plans/components/PlanCriticalConditions.tsx +++ b/packages/forklift-console-plugin/src/modules/Plans/components/PlanCriticalConditions.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { useTranslation } from 'react-i18next'; import Linkify from 'react-linkify'; +import { EMPTY_MSG } from 'src/utils/constants'; import { Alert, Text, TextContent, TextVariants } from '@patternfly/react-core'; @@ -13,7 +14,7 @@ export const PlanCriticalConditions: React.FC<{ type: string; message: string }> - {message || '-'} + {message || EMPTY_MSG}
{t('To troubleshoot, check the Forklift controller pod logs.')}
diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/details/components/PlanCriticalCondition.tsx b/packages/forklift-console-plugin/src/modules/Plans/views/details/components/PlanCriticalCondition.tsx index 208cefcb5..3e6b6cab0 100644 --- a/packages/forklift-console-plugin/src/modules/Plans/views/details/components/PlanCriticalCondition.tsx +++ b/packages/forklift-console-plugin/src/modules/Plans/views/details/components/PlanCriticalCondition.tsx @@ -1,19 +1,17 @@ import React from 'react'; import { useTranslation } from 'react-i18next'; import Linkify from 'react-linkify'; +import { EMPTY_MSG } from 'src/utils/constants'; -import { Alert, Text, TextContent, TextVariants } from '@patternfly/react-core'; +import { Alert, AlertVariant, Text, TextContent, TextVariants } from '@patternfly/react-core'; -export const PlanCriticalCondition: React.FC<{ type: string; message: string }> = ({ - type, - message, -}) => { +const PlanCriticalCondition: React.FC<{ type: string; message: string }> = ({ type, message }) => { const { t } = useTranslation(); return ( - + - {message || '-'} + {message || EMPTY_MSG} {'. '} {t('To troubleshoot, check the Forklift controller pod logs.')} 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..9f1f399d4 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,27 @@ 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 || []).find( + (net) => net?.metadata?.name === plan?.spec?.map?.network?.name, + ); + + const isMapToPod = + planNetMaps?.spec?.map.find((map) => map.destination.type === 'pod') !== undefined; + + 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..be643f94f --- /dev/null +++ b/packages/forklift-console-plugin/src/modules/Plans/views/details/components/PlanWarningCondition.tsx @@ -0,0 +1,31 @@ +import React from 'react'; +import { useTranslation } from 'react-i18next'; +import Linkify from 'react-linkify'; +import { EMPTY_MSG } from 'src/utils/constants'; + +import { Alert, AlertVariant, Text, TextContent, TextVariants } from '@patternfly/react-core'; + +const PlanWarningCondition: React.FC<{ + type: string; + message: string; + suggestion: string; +}> = ({ type, message, suggestion }) => { + const { t } = useTranslation(); + return ( + + + + {message || EMPTY_MSG} +
+
+ {suggestion || EMPTY_MSG} +
+
+
+ ); +}; + +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'; diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/list/components/ProviderCriticalCondition.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/list/components/ProviderCriticalCondition.tsx index 6f7428bc3..b8390304f 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/list/components/ProviderCriticalCondition.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/list/components/ProviderCriticalCondition.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { useTranslation } from 'react-i18next'; import Linkify from 'react-linkify'; +import { EMPTY_MSG } from 'src/utils/constants'; import { Alert, Text, TextContent, TextVariants } from '@patternfly/react-core'; @@ -10,10 +11,10 @@ export const ProviderCriticalCondition: React.FC<{ type: string; message: string }) => { const { t } = useTranslation(); return ( - + - {message || '-'} + {message || EMPTY_MSG} {'. '} {t('To troubleshoot, check the Forklift controller pod logs.')} diff --git a/packages/forklift-console-plugin/src/modules/StorageMaps/components/StorageMapCriticalConditions.tsx b/packages/forklift-console-plugin/src/modules/StorageMaps/components/StorageMapCriticalConditions.tsx index 8175b4f0b..b37e57e55 100644 --- a/packages/forklift-console-plugin/src/modules/StorageMaps/components/StorageMapCriticalConditions.tsx +++ b/packages/forklift-console-plugin/src/modules/StorageMaps/components/StorageMapCriticalConditions.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { useTranslation } from 'react-i18next'; import Linkify from 'react-linkify'; +import { EMPTY_MSG } from 'src/utils/constants'; import { Alert, Text, TextContent, TextVariants } from '@patternfly/react-core'; @@ -13,7 +14,7 @@ export const StorageMapCriticalConditions: React.FC<{ type: string; message: str - {message || '-'} + {message || EMPTY_MSG}
{t('To troubleshoot, check the Forklift controller pod logs.')}
diff --git a/packages/forklift-console-plugin/src/utils/constants.ts b/packages/forklift-console-plugin/src/utils/constants.ts new file mode 100644 index 000000000..8032dfcfc --- /dev/null +++ b/packages/forklift-console-plugin/src/utils/constants.ts @@ -0,0 +1 @@ +export const EMPTY_MSG = '-'; diff --git a/packages/forklift-console-plugin/src/utils/index.ts b/packages/forklift-console-plugin/src/utils/index.ts index 114d532ee..47685e96f 100644 --- a/packages/forklift-console-plugin/src/utils/index.ts +++ b/packages/forklift-console-plugin/src/utils/index.ts @@ -1,4 +1,5 @@ // @index(['./*', /style/g], f => `export * from '${f.path}';`) +export * from './constants'; export * from './deepCopy'; export * from './enums'; export * from './fetch';