Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MGMT-15151: Refactoring external platform integrations control #2255

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
22a4c9a
Refactoring external partner integrations control
ammont82 Jul 10, 2023
dbb8f19
Disabling Oci option in dropdown
ammont82 Jul 11, 2023
89665fe
Merge branch 'master' into MGMT-15151-refactoring-external-partners-i…
jkilzi Jul 11, 2023
662766d
Merge branch 'master' into MGMT-15151-refactoring-external-partners-i…
jkilzi Jul 11, 2023
4450e26
Removing ExternalPartnerIntegrationsCheckbox and adjusting code
ammont82 Jul 12, 2023
8b26eb0
Change handleClusterUpdate to take into account changes in platform
ammont82 Jul 13, 2023
e289666
Renaming props in ExternalPlatformDropdown
ammont82 Jul 13, 2023
d3133f2
Cleaning code
ammont82 Jul 13, 2023
5e7d0c9
Adding tests form external platform integration dropdown
ammont82 Jul 13, 2023
aa9243f
Merge branch 'master' into MGMT-15151-refactoring-external-partners-i…
ammont82 Jul 13, 2023
e748467
Removing unnecessary tests
ammont82 Jul 13, 2023
a60bf3e
Removing ASSISTED_INSTALLER_PLATFORM_INTEGRATION_FEATURE feature
ammont82 Jul 14, 2023
30e731d
Disable dropdown when oci is selected as platform
ammont82 Jul 14, 2023
680555f
Adjusting texts for new component
ammont82 Jul 14, 2023
f212934
Change in texts and in ExternalPlatformDropdown
ammont82 Jul 14, 2023
9c567c1
Removing console.logs
ammont82 Jul 18, 2023
923ea27
Remove ClusterPlatformIntegrationHint from footer
ammont82 Jul 18, 2023
acfbaf1
Removing setPlatform method from HostDiscoveryService
ammont82 Jul 18, 2023
3b8b61e
Disabling custom manifests checkbox when oci option is selected
ammont82 Jul 18, 2023
69bfa93
Change platform accordly with userManagedNetworking activated or not
ammont82 Jul 18, 2023
1761150
Solving lint problems
ammont82 Jul 18, 2023
c4f3c4f
Cleaning code and changing 'None' for 'No platform integration'
ammont82 Jul 19, 2023
ce09300
Disabling UMN for vSphere option
ammont82 Jul 19, 2023
4f1c439
Merge branch 'master' into MGMT-15151-refactoring-external-partners-i…
ammont82 Jul 19, 2023
a0a68bf
Adapting tests for external partner integration
ammont82 Jul 19, 2023
544a111
Solving problems with translation files
ammont82 Jul 19, 2023
e99581c
Merge branch 'master' into MGMT-15151-refactoring-external-partners-i…
ammont82 Jul 20, 2023
f60023b
Adapting changes from master
ammont82 Jul 20, 2023
b4d107b
Replacing link for button in external partner integration dropdown
ammont82 Jul 20, 2023
e4f263e
Set clusterPlatform as value of dropdown if exists
ammont82 Jul 21, 2023
cfa011c
Change resetPlatform to correct values
ammont82 Jul 21, 2023
fc9091b
Merge master into branch
ammont82 Jul 21, 2023
48c8189
Adapting tests for external partner integrations
ammont82 Jul 21, 2023
977dc9a
Patch correct platform type
ammont82 Jul 24, 2023
67b3e02
Cleaning code
ammont82 Jul 25, 2023
3b4a746
Disable Oracle option when is not supported by some cpu architecture
ammont82 Jul 25, 2023
e87552b
Merge branch 'master' into MGMT-15151-refactoring-external-partners-i…
jkilzi Jul 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const getClusterDetailsInitialValues = ({
diskEncryptionTangServers: parseTangServers(cluster?.diskEncryption?.tangServers),
diskEncryption: cluster?.diskEncryption ?? {},
cpuArchitecture: cluster?.cpuArchitecture || getDefaultCpuArchitecture(),
platform: cluster?.platform?.type || 'none',
};
};

Expand Down
3 changes: 2 additions & 1 deletion libs/ui-lib/lib/common/components/clusterWizard/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DiskEncryption, Host, Cluster } from '../../api';
import { DiskEncryption, Host, Cluster, PlatformType } from '../../api';

import {
ValidationGroup as ClusterValidationGroup,
Expand All @@ -25,6 +25,7 @@ export type ClusterDetailsValues = {
diskEncryptionTangServers: TangServer[];
diskEncryption: DiskEncryption;
cpuArchitecture: string;
platform: PlatformType;
};

export type HostsValidationsProps<S extends string, V extends string[]> = {
Expand Down
ammont82 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
import React from 'react';
import { Dropdown, DropdownItem, DropdownToggle, FormGroup } from '@patternfly/react-core';
import { CaretDownIcon } from '@patternfly/react-icons';
import { useField } from 'formik';
import {
NUTANIX_CONFIG_LINK,
PlatformType,
VSPHERE_CONFIG_LINK,
getFieldId,
} from '../../../common';
import {
NewFeatureSupportLevelMap,
useNewFeatureSupportLevel,
} from '../../../common/components/newFeatureSupportLevels';
import { clusterExistsReason as CLUSTER_EXISTS_REASON } from '../featureSupportLevels/featureStateUtils';

const INPUT_NAME = 'platform';
const fieldId = getFieldId(INPUT_NAME, 'input');

type ExternalPlatformDropdownProps = {
isOracleCloudPlatformIntegrationEnabled: boolean;
selectedPlatform?: PlatformType;
ammont82 marked this conversation as resolved.
Show resolved Hide resolved
disabledOciTooltipContent: React.ReactNode;
isOciDisabled: boolean;
};

export const externalPlatformTypes: Record<PlatformType, string> = {
none: 'None',
baremetal: 'Baremetal',
nutanix: 'Nutanix',
oci: 'Oracle',
vsphere: 'vSphere',
};

export const ExternalPlatformDropdown = ({
ammont82 marked this conversation as resolved.
Show resolved Hide resolved
isOracleCloudPlatformIntegrationEnabled,
selectedPlatform,
disabledOciTooltipContent,
isOciDisabled,
}: ExternalPlatformDropdownProps) => {
const [field, { value }, { setValue }] = useField<string>(INPUT_NAME);
const [current, setCurrent] = React.useState(
ammont82 marked this conversation as resolved.
Show resolved Hide resolved
selectedPlatform ? externalPlatformTypes[selectedPlatform] : 'None',
);
const [isOpen, setOpen] = React.useState(false);
ammont82 marked this conversation as resolved.
Show resolved Hide resolved

const enabledItems = [
ammont82 marked this conversation as resolved.
Show resolved Hide resolved
<DropdownItem key="none" id="none">
{externalPlatformTypes['none']}
<a
href={'www.google.es'}
ammont82 marked this conversation as resolved.
Show resolved Hide resolved
target="_blank"
rel="noopener noreferrer"
style={{ float: 'right' }}
>
Learn more <i className="fas fa-external-link-alt" />
</a>
</DropdownItem>,
<DropdownItem key="nutanix-platform" id="nutanix">
{externalPlatformTypes['nutanix']}
<a
href={NUTANIX_CONFIG_LINK}
target="_blank"
rel="noopener noreferrer"
style={{ float: 'right' }}
>
{'Learn more'} <i className="fas fa-external-link-alt" />
</a>
</DropdownItem>,
<DropdownItem key="vsphere-platform" id="vsphere">
{externalPlatformTypes['vsphere']}
<a
href={VSPHERE_CONFIG_LINK}
target="_blank"
rel="noopener noreferrer"
style={{ float: 'right' }}
>
{'Learn more'} <i className="fas fa-external-link-alt" />
</a>
</DropdownItem>,
];

if (isOracleCloudPlatformIntegrationEnabled) {
enabledItems.push(
<DropdownItem
key="oracle-platform"
id="oci"
tooltip={isOciDisabled ? disabledOciTooltipContent : undefined}
isAriaDisabled={!!isOciDisabled}
>
{externalPlatformTypes['oci']}
<a
href={VSPHERE_CONFIG_LINK}
ammont82 marked this conversation as resolved.
Show resolved Hide resolved
target="_blank"
rel="noopener noreferrer"
style={{ float: 'right' }}
>
{'Learn more'} <i className="fas fa-external-link-alt" />
</a>
</DropdownItem>,
);
}

const onSelect = React.useCallback(
(event?: React.SyntheticEvent<HTMLDivElement>) => {
const selectedPlatform = event?.currentTarget.id as PlatformType;
setValue(selectedPlatform);
setOpen(false);
setCurrent(externalPlatformTypes[selectedPlatform]);
},
[setOpen, setValue],
);

const toggle = React.useMemo(
() => (
<DropdownToggle
onToggle={(val) => setOpen(val)}
toggleIndicator={CaretDownIcon}
isText
className="pf-u-w-100"
>
{current || value}
</DropdownToggle>
),
[setOpen, current, value],
);

return (
<FormGroup id={`form-control__${fieldId}`} fieldId={fieldId} label={'Integrate with platform'}>
<Dropdown
{...field}
id={fieldId}
dropdownItems={enabledItems}
toggle={toggle}
isOpen={isOpen}
className="pf-u-w-100"
onSelect={onSelect}
/>
</FormGroup>
);
};

export const FEATURE_ID = 'EXTERNAL_PLATFORM_OCI';

export interface OracleDropdownItemState {
readonly featureId: string;
readonly isSupported: boolean;
readonly isDisabled: boolean;
readonly disabledReason?: string;
}

export const useOracleDropdownItemState = (
ammont82 marked this conversation as resolved.
Show resolved Hide resolved
hasExistentCluster: boolean,
featureSupportLevelData: NewFeatureSupportLevelMap | null,
): OracleDropdownItemState | null => {
const featureSupportLevelContext = useNewFeatureSupportLevel();
if (!featureSupportLevelData) {
return null;
}

const isSupported = featureSupportLevelData
? featureSupportLevelContext.isFeatureSupported(FEATURE_ID, featureSupportLevelData)
: false;
const isDisabled = hasExistentCluster || !isSupported;
let disabledReason: string | undefined;
if (isDisabled) {
if (hasExistentCluster) {
disabledReason = CLUSTER_EXISTS_REASON;
} else {
disabledReason = featureSupportLevelContext.getFeatureDisabledReason(FEATURE_ID);
}
}

return {
featureId: FEATURE_ID,
isSupported,
isDisabled,
disabledReason,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@ import { DiscoveryImageModalButton } from './DiscoveryImageModal';
import InformationAndAlerts from './InformationAndAlerts';
import { OcmSwitchField } from '../ui/OcmFormFields';
import { selectCurrentClusterPermissionsState } from '../../selectors';
ammont82 marked this conversation as resolved.
Show resolved Hide resolved
import PlatformIntegration from './platformIntegration/PlatformIntegration';

const schedulableMastersTooltip =
'Workloads must be run on control plane nodes when less than 5 hosts are discovered';

const HostInventory = ({ cluster }: { cluster: Cluster }) => {
const isPlatformIntegrationFeatureEnabled = useFeature(
'ASSISTED_INSTALLER_PLATFORM_INTEGRATION_FEATURE',
ammont82 marked this conversation as resolved.
Show resolved Hide resolved
);
const isSingleClusterFeatureEnabled = useFeature('ASSISTED_INSTALLER_SINGLE_CLUSTER_FEATURE');

const mastersMustRunWorkloads = selectMastersMustRunWorkloads(cluster);
Expand Down Expand Up @@ -61,13 +57,6 @@ const HostInventory = ({ cluster }: { cluster: Cluster }) => {
</TextContent>
)}
</StackItem>
{isPlatformIntegrationFeatureEnabled && (
<StackItem>
<Split>
<PlatformIntegration clusterId={cluster.id} />
ammont82 marked this conversation as resolved.
Show resolved Hide resolved
</Split>
</StackItem>
)}
<StackItem>
<Split>
<SplitItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import {
useFeature,
ClusterCreateParams,
getSupportedCpuArchitectures,
PlatformType,
ammont82 marked this conversation as resolved.
Show resolved Hide resolved
} from '../../../common';
import DiskEncryptionControlGroup from '../../../common/components/clusterConfiguration/DiskEncryptionFields/DiskEncryptionControlGroup';
import { useTranslation } from '../../../common/hooks/use-translation-wrapper';
import {
OcmCheckboxField,
OcmCheckboxFieldProps,
OcmInputField,
OcmRichInputField,
OcmSelectField,
Expand All @@ -36,11 +36,7 @@ import CpuArchitectureDropdown, {
import OcmSNOControlGroup from './OcmSNOControlGroup';
import useSupportLevelsAPI from '../../hooks/useSupportLevelsAPI';
import { useOpenshiftVersions } from '../../hooks';
import { useClusterWizardContext } from '../clusterWizard/ClusterWizardContext';
import {
ExternalPartnerIntegrationsCheckbox,
useExternalPartnerIntegrationsCheckboxState,
} from './ExternalPartnerIntegrationsCheckbox';
import { ExternalPlatformDropdown, useOracleDropdownItemState } from './ExternalPlatformDropdown';

export type OcmClusterDetailsFormFieldsProps = {
forceOpenshiftVersion?: string;
Expand All @@ -54,6 +50,7 @@ export type OcmClusterDetailsFormFieldsProps = {
clusterExists: boolean;
clusterCpuArchitecture?: string;
clusterId?: string;
clusterPlatform?: PlatformType;
ammont82 marked this conversation as resolved.
Show resolved Hide resolved
};

const BaseDnsHelperText = ({ name, baseDnsDomain }: { name?: string; baseDnsDomain?: string }) => (
Expand All @@ -78,8 +75,9 @@ export const OcmClusterDetailsFormFields = ({
clusterExists,
clusterCpuArchitecture,
clusterId,
clusterPlatform,
}: OcmClusterDetailsFormFieldsProps) => {
const { values, setFieldValue } = useFormikContext<ClusterDetailsValues>();
const { values } = useFormikContext<ClusterDetailsValues>();
const { name, baseDnsDomain, highAvailabilityMode, useRedHatDnsService } = values;
const nameInputRef = React.useRef<HTMLInputElement>();

Expand All @@ -92,7 +90,7 @@ export const OcmClusterDetailsFormFields = ({
} = useFormikContext<ClusterCreateParams>();
const { getCpuArchitectures } = useOpenshiftVersions();
const cpuArchitecturesByVersionImage = getCpuArchitectures(openshiftVersion);
const clusterWizardContext = useClusterWizardContext();

const featureSupportLevelData = useSupportLevelsAPI(
'features',
values.openshiftVersion,
Expand All @@ -105,7 +103,7 @@ export const OcmClusterDetailsFormFields = ({
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const cpuArchitecture = (architectureData[values.cpuArchitecture] as CpuArchitectureItem).label;
const externalPartnerIntegrationsCheckboxState = useExternalPartnerIntegrationsCheckboxState(
const oracleDropdownItemState = useOracleDropdownItemState(
clusterExists,
featureSupportLevelData,
);
Expand All @@ -114,17 +112,6 @@ export const OcmClusterDetailsFormFields = ({
nameInputRef.current?.focus();
}, []);

const handleExternalPartnerIntegrationsChange = React.useCallback<
NonNullable<OcmCheckboxFieldProps['onChange']>
>(
(value: boolean, _event: React.FormEvent<HTMLInputElement>) => {
const checked = Boolean(value);
setFieldValue('addCustomManifest', checked, false);
clusterWizardContext.setAddCustomManifests(checked);
},
[clusterWizardContext, setFieldValue],
);

return (
<Form id="wizard-cluster-details__form">
<OcmRichInputField
Expand Down Expand Up @@ -198,21 +185,12 @@ export const OcmClusterDetailsFormFields = ({

{!isPullSecretSet && <PullSecret isOcm={isOcm} defaultPullSecret={defaultPullSecret} />}

{isOracleCloudPlatformIntegrationEnabled && externalPartnerIntegrationsCheckboxState && (
<ExternalPartnerIntegrationsCheckbox
disabledStateTooltipContent={externalPartnerIntegrationsCheckboxState.disabledReason}
popoverContent={
<p>
To integrate with an external partner (for example, Oracle Cloud), you'll need to
ammont82 marked this conversation as resolved.
Show resolved Hide resolved
provide a custom manifest.
</p>
}
label={'External partner integrations'}
helperText={'Integrate with other platforms using custom manifests.'}
onChange={handleExternalPartnerIntegrationsChange}
isDisabled={externalPartnerIntegrationsCheckboxState.isDisabled}
/>
)}
<ExternalPlatformDropdown
isOracleCloudPlatformIntegrationEnabled={isOracleCloudPlatformIntegrationEnabled}
selectedPlatform={clusterPlatform}
disabledOciTooltipContent={oracleDropdownItemState?.disabledReason}
isOciDisabled={oracleDropdownItemState?.isDisabled || false}
/>

<CustomManifestCheckbox clusterId={clusterId || ''} />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ const ClusterDetailsForm = (props: ClusterDetailsFormProps) => {
clusterExists={!!cluster}
clusterCpuArchitecture={cluster?.cpuArchitecture as CpuArchitecture}
clusterId={cluster?.id}
clusterPlatform={cluster?.platform?.type}
ammont82 marked this conversation as resolved.
Show resolved Hide resolved
/>
</GridItem>
</Grid>
Expand Down
3 changes: 3 additions & 0 deletions libs/ui-lib/lib/ocm/services/ClusterDetailsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ const ClusterDetailsService = {
baseDnsDomain: values.baseDnsDomain,
cpuArchitecture: values.cpuArchitecture as ClusterCpuArchitecture,
diskEncryption: DiskEncryptionService.getDiskEncryptionParams(values),
platform: {
type: values.platform,
},
};

if (values.externalPartnerIntegrations) {
ammont82 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down