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 13, 2024
1 parent de8df09 commit 6284b5d
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 4 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 @@ -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.",
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,25 @@ 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 failure on line 65 in packages/forklift-console-plugin/src/modules/Plans/views/details/components/PlanPageHeadings.tsx

View workflow job for this annotation

GitHub Actions / Run linter and tests

Delete `·`
* 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(
<PlanCriticalCondition
Expand All @@ -56,6 +85,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,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 (
<Alert title={t('The plan migration might not work as expected - ') + type} variant="warning">
<TextContent className="forklift-providers-list-header__alert">
<Text component={TextVariants.p}>
<Linkify>{message || '-'}</Linkify>
<br />
<br />
<Linkify>{suggestion || '-'}</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

0 comments on commit 6284b5d

Please sign in to comment.