From 471db0a1a94519a5eb7abb92c87688e51246d105 Mon Sep 17 00:00:00 2001 From: Hana Xu Date: Fri, 3 Jan 2025 11:33:09 -0500 Subject: [PATCH 1/2] fix region validation when switching to enterprise tier --- .../CreateCluster/CreateCluster.tsx | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/packages/manager/src/features/Kubernetes/CreateCluster/CreateCluster.tsx b/packages/manager/src/features/Kubernetes/CreateCluster/CreateCluster.tsx index 18a01362452..369a7432ff9 100644 --- a/packages/manager/src/features/Kubernetes/CreateCluster/CreateCluster.tsx +++ b/packages/manager/src/features/Kubernetes/CreateCluster/CreateCluster.tsx @@ -61,13 +61,14 @@ import type { KubeNodePoolResponse, KubernetesTier, } from '@linode/api-v4/lib/kubernetes'; +import type { Region } from '@linode/api-v4/lib/regions'; import type { APIError } from '@linode/api-v4/lib/types'; import type { ExtendedIP } from 'src/utilities/ipUtils'; export const CreateCluster = () => { const { classes } = useStyles(); - const [selectedRegionId, setSelectedRegionId] = React.useState< - string | undefined + const [selectedRegion, setSelectedRegion] = React.useState< + Region | undefined >(); const [nodePools, setNodePools] = React.useState([]); const [label, setLabel] = React.useState(); @@ -162,6 +163,17 @@ export const CreateCluster = () => { } }, [versionData]); + // When changing the tier to Enterprise, we want to check if the pre-selected region has the capability + React.useEffect(() => { + if ( + isLkeEnterpriseLAFeatureEnabled && + selectedTier === 'enterprise' && + !selectedRegion?.capabilities.includes('Kubernetes Enterprise') + ) { + setSelectedRegion(undefined); + } + }, [isLkeEnterpriseLAFeatureEnabled, selectedRegion, selectedTier]); + const createCluster = () => { if (ipV4Addr.some((ip) => ip.error) || ipV6Addr.some((ip) => ip.error)) { scrollErrorIntoViewV2(formContainerRef); @@ -214,7 +226,7 @@ export const CreateCluster = () => { k8s_version: version, label, node_pools, - region: selectedRegionId, + region: selectedRegion?.id, }; if (showAPL) { @@ -271,7 +283,7 @@ export const CreateCluster = () => { }; const highAvailabilityPrice = getDCSpecificPriceByType({ - regionId: selectedRegionId, + regionId: selectedRegion?.id, type: lkeHAType, }); @@ -295,7 +307,7 @@ export const CreateCluster = () => { isSelectedRegionEligibleForPlan, } = plansNoticesUtils({ regionsData, - selectedRegionID: selectedRegionId, + selectedRegionID: selectedRegion?.id, }); if (typesError || regionsError || versionsError) { @@ -362,9 +374,9 @@ export const CreateCluster = () => { } disableClearable errorText={errorMap.region} - onChange={(e, region) => setSelectedRegionId(region.id)} + onChange={(e, region) => setSelectedRegion(region)} regions={regionsData} - value={selectedRegionId} + value={selectedRegion?.id} /> { isAPLEnabled={apl_enabled} isErrorKubernetesTypes={isErrorKubernetesTypes} isLoadingKubernetesTypes={isLoadingKubernetesTypes} - selectedRegionId={selectedRegionId} + selectedRegionId={selectedRegion?.id} setHighAvailability={setHighAvailability} /> @@ -454,7 +466,7 @@ export const CreateCluster = () => { isPlanPanelDisabled={isPlanPanelDisabled} isSelectedRegionEligibleForPlan={isSelectedRegionEligibleForPlan} regionsData={regionsData} - selectedRegionId={selectedRegionId} + selectedRegionId={selectedRegion?.id} types={typesData || []} typesLoading={typesLoading} /> @@ -473,7 +485,7 @@ export const CreateCluster = () => { updateFor={[ hasAgreed, highAvailability, - selectedRegionId, + selectedRegion?.id, nodePools, submitting, typesData, @@ -487,7 +499,7 @@ export const CreateCluster = () => { hasAgreed={hasAgreed} highAvailability={highAvailability} pools={nodePools} - region={selectedRegionId} + region={selectedRegion?.id} regionsData={regionsData} removePool={removePool} showHighAvailability={showHighAvailability} From 0ed6e4c13388026b198c101efce7021596e6c320 Mon Sep 17 00:00:00 2001 From: Hana Xu Date: Mon, 6 Jan 2025 13:16:40 -0500 Subject: [PATCH 2/2] feedback --- .../Kubernetes/CreateCluster/CreateCluster.tsx | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/packages/manager/src/features/Kubernetes/CreateCluster/CreateCluster.tsx b/packages/manager/src/features/Kubernetes/CreateCluster/CreateCluster.tsx index 369a7432ff9..365a8758551 100644 --- a/packages/manager/src/features/Kubernetes/CreateCluster/CreateCluster.tsx +++ b/packages/manager/src/features/Kubernetes/CreateCluster/CreateCluster.tsx @@ -111,6 +111,11 @@ export const CreateCluster = () => { // HA is enabled by default for enterprise clusters if (tier === 'enterprise') { setHighAvailability(true); + + // When changing the tier to enterprise, we want to check if the pre-selected region has the capability + if (!selectedRegion?.capabilities.includes('Kubernetes Enterprise')) { + setSelectedRegion(undefined); + } } else { setHighAvailability(undefined); } @@ -163,17 +168,6 @@ export const CreateCluster = () => { } }, [versionData]); - // When changing the tier to Enterprise, we want to check if the pre-selected region has the capability - React.useEffect(() => { - if ( - isLkeEnterpriseLAFeatureEnabled && - selectedTier === 'enterprise' && - !selectedRegion?.capabilities.includes('Kubernetes Enterprise') - ) { - setSelectedRegion(undefined); - } - }, [isLkeEnterpriseLAFeatureEnabled, selectedRegion, selectedTier]); - const createCluster = () => { if (ipV4Addr.some((ip) => ip.error) || ipV6Addr.some((ip) => ip.error)) { scrollErrorIntoViewV2(formContainerRef);