Skip to content

Commit

Permalink
Display a Warnning if preserve static IPs are enabled with pod network
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
sgratch committed Nov 28, 2024
1 parent de8df09 commit e8f26a2
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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.",
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -13,7 +14,7 @@ export const NetworkMapCriticalConditions: React.FC<{ type: string; message: str
<Alert title={type} variant="danger">
<TextContent className="forklift-providers-list-header__alert">
<Text component={TextVariants.p}>
<Linkify>{message || '-'}</Linkify>
<Linkify>{message || EMPTY_MSG}</Linkify>
<br />
{t('To troubleshoot, check the Forklift controller pod logs.')}
</Text>
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -13,7 +14,7 @@ export const PlanCriticalConditions: React.FC<{ type: string; message: string }>
<Alert title={type} variant="danger">
<TextContent className="forklift-providers-list-header__alert">
<Text component={TextVariants.p}>
<Linkify>{message || '-'}</Linkify>
<Linkify>{message || EMPTY_MSG}</Linkify>
<br />
{t('To troubleshoot, check the Forklift controller pod logs.')}
</Text>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
<Alert title={t('The plan is not ready - ') + type} variant="danger">
<Alert title={t('The plan is not ready') + ' - ' + type} variant={AlertVariant.danger}>
<TextContent className="forklift-providers-list-header__alert">
<Text component={TextVariants.p}>
<Linkify>{message || '-'}</Linkify>
<Linkify>{message || EMPTY_MSG}</Linkify>
{'. '}
{t('To troubleshoot, check the Forklift controller pod logs.')}
</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -22,13 +29,20 @@ export const PlanPageHeadings: React.FC<{ name: string; namespace: string }> = (
const { t } = useForkliftTranslation();
const { showModal } = useModal();

const [plan, loaded, error] = useK8sWatchResource<V1beta1Plan>({
const [plan, planLoaded, planError] = useK8sWatchResource<V1beta1Plan>({
groupVersionKind: PlanModelGroupVersionKind,
namespaced: true,
name,
namespace,
});

const [netMaps, netMapsLoaded, netMapsError] = useK8sWatchResource<V1beta1NetworkMap[]>({
groupVersionKind: NetworkMapModelGroupVersionKind,
namespaced: true,
isList: true,
namespace,
});

const permissions = useGetDeleteAndEditAccessReview({
model: PlanModel,
namespace,
Expand All @@ -44,10 +58,27 @@ export const PlanPageHeadings: React.FC<{ name: string; namespace: string }> = (
const buttonStartIcon = canReStart ? <ReStartIcon /> : <StartIcon />;

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(
<PlanCriticalCondition
Expand All @@ -56,6 +87,18 @@ export const PlanPageHeadings: React.FC<{ name: string; namespace: string }> = (
key={'providerCriticalCondition'}
/>,
);
} else if (preserveIpsWithPodMapCondition()) {
alerts.push(
<PlanWarningCondition
type={t('Preserving static IPs of VMs might fail')}
message={t(
'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.',
)}
suggestion={t(
"For fixing, update the destination network mappings to avoid using the 'Pod Networking' type.",
)}
/>,
);
}

const onClick = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
<Alert
title={t('The plan migration might not work as expected') + ' - ' + type}
variant={AlertVariant.warning}
>
<TextContent className="forklift-providers-list-header__alert">
<Text component={TextVariants.p}>
<Linkify>{message || EMPTY_MSG}</Linkify>
<br />
<br />
<Linkify>{suggestion || EMPTY_MSG}</Linkify>
</Text>
</TextContent>
</Alert>
);
};

export default PlanWarningCondition;
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -10,10 +11,10 @@ export const ProviderCriticalCondition: React.FC<{ type: string; message: string
}) => {
const { t } = useTranslation();
return (
<Alert title={t('The provider is not ready - ') + type} variant="danger">
<Alert title={t('The provider is not ready') + ' - ' + type} variant="danger">
<TextContent className="forklift-providers-list-header__alert">
<Text component={TextVariants.p}>
<Linkify>{message || '-'}</Linkify>
<Linkify>{message || EMPTY_MSG}</Linkify>
{'. '}
{t('To troubleshoot, check the Forklift controller pod logs.')}
</Text>
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -13,7 +14,7 @@ export const StorageMapCriticalConditions: React.FC<{ type: string; message: str
<Alert title={type} variant="danger">
<TextContent className="forklift-providers-list-header__alert">
<Text component={TextVariants.p}>
<Linkify>{message || '-'}</Linkify>
<Linkify>{message || EMPTY_MSG}</Linkify>
<br />
{t('To troubleshoot, check the Forklift controller pod logs.')}
</Text>
Expand Down
1 change: 1 addition & 0 deletions packages/forklift-console-plugin/src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const EMPTY_MSG = '-';
1 change: 1 addition & 0 deletions packages/forklift-console-plugin/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @index(['./*', /style/g], f => `export * from '${f.path}';`)
export * from './constants';
export * from './deepCopy';
export * from './enums';
export * from './fetch';
Expand Down

0 comments on commit e8f26a2

Please sign in to comment.