From aa2af91ebe8fa648112062436964ad5c6bfc4356 Mon Sep 17 00:00:00 2001 From: Montse Ortega Date: Tue, 19 Sep 2023 13:47:47 +0200 Subject: [PATCH] Use platform type to call support-levels API in Networking page (#2372) Co-authored-by: Jonathan Kilzi --- .../NetworkConfiguration.tsx | 57 ++++++++++++++----- .../featureSupportLevels/featureStateUtils.ts | 11 +++- 2 files changed, 50 insertions(+), 18 deletions(-) diff --git a/libs/ui-lib/lib/ocm/components/clusterConfiguration/networkConfiguration/NetworkConfiguration.tsx b/libs/ui-lib/lib/ocm/components/clusterConfiguration/networkConfiguration/NetworkConfiguration.tsx index 67ee6509a5..db6b36a776 100644 --- a/libs/ui-lib/lib/ocm/components/clusterConfiguration/networkConfiguration/NetworkConfiguration.tsx +++ b/libs/ui-lib/lib/ocm/components/clusterConfiguration/networkConfiguration/NetworkConfiguration.tsx @@ -9,6 +9,7 @@ import { Cluster, ClusterDefaultConfig, clusterNetworksEqual, + CpuArchitecture, DUAL_STACK, HostSubnets, isSNO, @@ -30,8 +31,10 @@ import { OcmCheckbox } from '../../ui/OcmFormFields'; import { NetworkTypeControlGroup } from '../../../../common/components/clusterWizard/networkingSteps/NetworkTypeControlGroup'; import { NewFeatureSupportLevelData, + NewFeatureSupportLevelMap, useNewFeatureSupportLevel, } from '../../../../common/components/newFeatureSupportLevels'; +import useSupportLevelsAPI from '../../../hooks/useSupportLevelsAPI'; export type NetworkConfigurationProps = VirtualIPControlGroupProps & { hostSubnets: HostSubnets; @@ -74,20 +77,29 @@ const getManagedNetworkingDisabledReason = ( }; const getUserManagedDisabledReason = ( - featureSupportLevelData: NewFeatureSupportLevelData, + featureSupportLevelContext: NewFeatureSupportLevelData, platformType?: PlatformType, + featureSupportLevelMap?: NewFeatureSupportLevelMap | null, ) => { - if (platformType === 'nutanix' || platformType === 'vsphere') { - return 'User-Managed Networking is not supported when using Nutanix or vSphere'; - } - if (!featureSupportLevelData.isFeatureSupported('USER_MANAGED_NETWORKING')) { - return featureSupportLevelData.getFeatureDisabledReason('USER_MANAGED_NETWORKING'); + if (!featureSupportLevelContext.isFeatureSupported('USER_MANAGED_NETWORKING')) { + return featureSupportLevelContext.getFeatureDisabledReason( + 'USER_MANAGED_NETWORKING', + featureSupportLevelMap ?? undefined, + undefined, + platformType, + ); } }; -const getClusterManagedDisabledReason = (featureSupportLevelData: NewFeatureSupportLevelData) => { - if (!featureSupportLevelData.isFeatureSupported('CLUSTER_MANAGED_NETWORKING')) { - return featureSupportLevelData.getFeatureDisabledReason('CLUSTER_MANAGED_NETWORKING'); +const getClusterManagedDisabledReason = ( + featureSupportLevelContext: NewFeatureSupportLevelData, + featureSupportLevelMap?: NewFeatureSupportLevelMap | null, +) => { + if (!featureSupportLevelContext.isFeatureSupported('CLUSTER_MANAGED_NETWORKING')) { + return featureSupportLevelContext.getFeatureDisabledReason( + 'CLUSTER_MANAGED_NETWORKING', + featureSupportLevelMap ?? undefined, + ); } }; @@ -96,6 +108,7 @@ const getManagedNetworkingState = ( isOracleCloudInfrastructure: boolean, featureSupportLevelData: NewFeatureSupportLevelData, platformType?: PlatformType, + featureSupportLevelMap?: NewFeatureSupportLevelMap | null, ): { isDisabled: boolean; clusterManagedDisabledReason?: string; @@ -106,8 +119,15 @@ const getManagedNetworkingState = ( isOracleCloudInfrastructure, featureSupportLevelData, ); - const cmnReason = getClusterManagedDisabledReason(featureSupportLevelData); - const umnReason = getUserManagedDisabledReason(featureSupportLevelData, platformType); + const cmnReason = getClusterManagedDisabledReason( + featureSupportLevelData, + featureSupportLevelMap, + ); + const umnReason = getUserManagedDisabledReason( + featureSupportLevelData, + platformType, + featureSupportLevelMap, + ); return { isDisabled: !!(cmnReason || umnReason || networkingReason), @@ -122,7 +142,13 @@ const NetworkConfiguration = ({ isVipDhcpAllocationDisabled, defaultNetworkSettings, }: NetworkConfigurationProps) => { - const featureSupportLevelData = useNewFeatureSupportLevel(); + const featureSupportLevelContext = useNewFeatureSupportLevel(); + const featureSupportLevelData = useSupportLevelsAPI( + 'features', + cluster.openshiftVersion, + cluster.cpuArchitecture as CpuArchitecture, + cluster.platform?.type, + ); const { isViewerMode } = useSelector(selectCurrentClusterPermissionsState); const { setFieldValue, values, validateField } = useFormikContext(); @@ -200,10 +226,11 @@ const NetworkConfiguration = ({ getManagedNetworkingState( isDualStack, cluster.platform?.type === 'oci', - featureSupportLevelData, + featureSupportLevelContext, cluster.platform?.type, + featureSupportLevelData, ), - [isDualStack, cluster.platform?.type, featureSupportLevelData], + [isDualStack, cluster.platform?.type, featureSupportLevelContext, featureSupportLevelData], ); return ( @@ -249,7 +276,7 @@ const NetworkConfiguration = ({ )} diff --git a/libs/ui-lib/lib/ocm/components/featureSupportLevels/featureStateUtils.ts b/libs/ui-lib/lib/ocm/components/featureSupportLevels/featureStateUtils.ts index 4c04bd5c95..dfaa34d4ff 100644 --- a/libs/ui-lib/lib/ocm/components/featureSupportLevels/featureStateUtils.ts +++ b/libs/ui-lib/lib/ocm/components/featureSupportLevels/featureStateUtils.ts @@ -10,6 +10,7 @@ import { PlatformType, } from '../../../common'; import { architectureData } from '../clusterConfiguration/CpuArchitectureDropdown'; +import { ExternalPlatformLabels } from '../clusterConfiguration/platformIntegration/constants'; const CNV_OPERATOR_LABEL = 'Openshift Virtualization'; const LVMS_OPERATOR_LABEL = 'Logical Volume Manager Storage'; @@ -174,7 +175,9 @@ export const getNewFeatureDisabledReason = ( return getNetworkTypeSelectionDisabledReason(cluster); } case 'CLUSTER_MANAGED_NETWORKING': { - return 'Cluster-managed networking is not supported for ARM architecture with this version of OpenShift.'; + return `Cluster-managed networking is not supported when using ${ + platformType ? ExternalPlatformLabels[platformType] : '' + }`; } case 'EXTERNAL_PLATFORM_OCI': { return getOciDisabledReason(cpuArchitecture, isSupported); @@ -194,9 +197,11 @@ export const getNewFeatureDisabledReason = ( return `Integration with vSphere is not available with the selected CPU architecture.`; } } - case 'PLATFORM_MANAGED_NETWORKING': { + case 'USER_MANAGED_NETWORKING': { if (!isSupported) { - return `User-Managed Networking is not supported when using ${platformType || ''}`; + return `User-Managed Networking is not supported when using ${ + platformType ? ExternalPlatformLabels[platformType] : '' + }`; } } default: {