Skip to content

Commit

Permalink
Merge pull request #1138 from sgratch/add-preserveStaticIPs-flag-to-plan
Browse files Browse the repository at this point in the history
🐾 Add the preserveStaticIPs flag to vSphere's plan details section
  • Loading branch information
yaacov authored May 5, 2024
2 parents a10047e + e35e657 commit cc02eac
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ci/yaml/crds/forklift/forklift.konveyor.io_plans.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ spec:
description: Preserve the CPU model and flags the VM runs with in
its oVirt cluster.
type: boolean
preserveStaticIPs:
description: Preserve static IPs of VMs in vSphere (Windows only)
type: boolean
provider:
description: Providers.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@
"Pre migration hook": "Pre migration hook",
"Precopy interval (minutes)": "Precopy interval (minutes)",
"Preserve CPU model": "Preserve CPU model",
"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 that the VM runs with in vSphere provider's environment.": "Preserve the static IPs that the VM runs with in vSphere provider's environment.",
"Product": "Product",
"Project": "Project",
"Project ID": "Project ID",
Expand Down Expand Up @@ -381,6 +383,7 @@
"Set cutover": "Set cutover",
"Set default transfer network": "Set default transfer network",
"Set to preserve the CPU model": "Set to preserve the CPU model",
"Set to preserve the static IPs": "Set to preserve the static IPs",
"Set warm migration": "Set warm migration",
"Sets the maximum number of VMs that can be migrated simultaneously. The default value is 20 virtual machines.": "Sets the maximum number of VMs that can be migrated simultaneously. The default value is 20 virtual machines.",
"Sets the memory limits allocated to the main container in the controller pod. The default value is 800Mi.": "Sets the memory limits allocated to the main container in the controller pod. The default value is 800Mi.",
Expand Down Expand Up @@ -507,6 +510,7 @@
"Whether this is a warm migration": "Whether this is a warm migration",
"Whether this is a warm migration.": "Whether this is a warm migration.",
"Whether to preserve the CPU model": "Whether to preserve the CPU model",
"Whether to preserve the static IPs": "Whether to preserve the static IPs",
"YAML": "YAML",
"You can always bring this welcome card back into view by clicking 'Show the welcome card' in the page heading.": "You can always bring this welcome card back into view by clicking 'Show the welcome card' in the page heading.",
"You can cancel virtual machines from a running migration plan.": "You can cancel virtual machines from a running migration plan.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Suspend } from '../Suspend';

import {
PreserveClusterCpuModelDetailsItem,
PreserveStaticIPsDetailsItem,
TargetNamespaceDetailsItem,
TransferNetworkDetailsItem,
WarmDetailsItem,
Expand Down Expand Up @@ -82,6 +83,11 @@ export const SettingsSectionInternal: React.FC<SettingsSectionProps> = ({ obj, p
<PreserveClusterCpuModelDetailsItem resource={obj} canPatch={permissions.canPatch} />
</Suspend>
)}
{['vsphere'].includes(sourceProvider?.spec?.type) && (
<Suspend obj={sourceProvider} loaded={loaded} loadError={loadError}>
<PreserveStaticIPsDetailsItem resource={obj} canPatch={permissions.canPatch} />
</Suspend>
)}
</DescriptionList>
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';
import { useModal } from 'src/modules/Providers/modals';
import { DetailsItem } from 'src/modules/Providers/utils';
import { useForkliftTranslation } from 'src/utils/i18n';

import { Label } from '@patternfly/react-core';

import { PlanDetailsItemProps } from '../../DetailsSection';
import { EditPlanPreserveStaticIPs } from '../modals/EditPlanPreserveStaticIPs';

export const PreserveStaticIPsDetailsItem: React.FC<PlanDetailsItemProps> = ({
resource,
canPatch,
helpContent,
destinationProvider,
}) => {
const { t } = useForkliftTranslation();
const { showModal } = useModal();

const defaultHelpContent = t(
`Preserve the static IPs that the VM runs with in vSphere provider's environment.`,
);

const trueLabel = (
<Label isCompact color={'green'}>
Preserve static IPs
</Label>
);
const falseLabel = (
<Label isCompact color={'blue'}>
Use system default
</Label>
);

return (
<DetailsItem
title={t('Preserve static IPs')}
content={resource?.spec?.preserveStaticIPs ? trueLabel : falseLabel}
helpContent={helpContent ?? defaultHelpContent}
crumbs={['spec', 'preserveStaticIPs']}
onEdit={
canPatch &&
(() =>
showModal(
<EditPlanPreserveStaticIPs
resource={resource}
destinationProvider={destinationProvider}
/>,
))
}
/>
);
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @index(['./*', /style/g], f => `export * from '${f.path}';`)
export * from './PreserveClusterCpuModelDetailsItem';
export * from './PreserveStaticIPsDetailsItem';
export * from './TargetNamespaceDetailsItem';
export * from './TransferNetworkDetailsItem';
export * from './WarmDetailsItem';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import React from 'react';
import {
EditModal,
EditModalProps,
ModalInputComponentType,
OnConfirmHookType,
} from 'src/modules/Providers/modals';
import { useForkliftTranslation } from 'src/utils/i18n';

import { Modify, PlanModel, V1beta1Plan, V1beta1Provider } from '@kubev2v/types';
import { K8sModel, k8sPatch } from '@openshift-console/dynamic-plugin-sdk';
import { Switch } from '@patternfly/react-core';

const onConfirm: OnConfirmHookType = async ({ resource, model, newValue }) => {
const plan = resource as V1beta1Plan;

const resourceValue = plan?.spec?.preserveStaticIPs;
const op = resourceValue ? 'replace' : 'add';

const obj = await k8sPatch({
model: model,
resource: resource,
data: [
{
op,
path: '/spec/preserveStaticIPs',
value: newValue === 'true' || undefined,
},
],
});

return obj;
};

interface SwitchRendererProps {
value: string | number;
onChange: (string) => void;
}

const PreserveStaticIPsInputFactory: () => ModalInputComponentType = () => {
const SwitchRenderer: React.FC<SwitchRendererProps> = ({ value, onChange }) => {
const onChangeInternal = (v) => {
onChange(v ? 'true' : 'false');
};

return (
<Switch
id="simple-switch"
label="Preserve the static IPs that the VM runs with in vSphere provider's environment."
labelOff="Do not try to preserve the static IPs that the VM runs with in vSphere provider's environment."
isChecked={value === 'true'}
onChange={onChangeInternal}
/>
);
};

return SwitchRenderer;
};

const EditPlanPreserveStaticIPs_: React.FC<EditPlanPreserveStaticIPsProps> = (props) => {
const { t } = useForkliftTranslation();

return (
<EditModal
{...props}
jsonPath={(obj: V1beta1Plan) => (obj.spec.preserveStaticIPs ? 'true' : 'false')}
title={props?.title || t('Set to preserve the static IPs')}
label={props?.label || t('Whether to preserve the static IPs')}
model={PlanModel}
onConfirmHook={onConfirm}
body={t(`Preserve the static IPs that the VM runs with in vSphere provider's environment.`)}
InputComponent={PreserveStaticIPsInputFactory()}
/>
);
};

export type EditPlanPreserveStaticIPsProps = Modify<
EditModalProps,
{
resource: V1beta1Plan;
title?: string;
label?: string;
model?: K8sModel;
jsonPath?: string | string[];
destinationProvider: V1beta1Provider;
}
>;

export const EditPlanPreserveStaticIPs: React.FC<EditPlanPreserveStaticIPsProps> = (props) => {
return <EditPlanPreserveStaticIPs_ {...props} />;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// @index(['./*', /style/g], f => `export * from '${f.path}';`)
export * from './EditPlanPreserveStaticIPs';
// @endindex
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @index(['./*', /style/g], f => `export * from '${f.path}';`)
export * from './EditPlanPreserveClusterCpuModel';
export * from './EditPlanPreserveStaticIPs';
export * from './EditPlanTargetNamespace';
export * from './EditPlanTransferNetwork';
export * from './EditPlanWarm';
Expand Down

0 comments on commit cc02eac

Please sign in to comment.