From 37e87b9450a92505a72e0edde2ad7888fc3fa16b Mon Sep 17 00:00:00 2001 From: Soham Dessai Date: Tue, 19 Sep 2023 13:58:02 -0400 Subject: [PATCH] Fix Provision failing when region is not available --- dashboard/src/components/PreflightChecks.tsx | 15 +++- .../src/components/ProvisionerSettings.tsx | 81 ++++++++++--------- 2 files changed, 56 insertions(+), 40 deletions(-) diff --git a/dashboard/src/components/PreflightChecks.tsx b/dashboard/src/components/PreflightChecks.tsx index 668c8457ad..c1a6d40b91 100644 --- a/dashboard/src/components/PreflightChecks.tsx +++ b/dashboard/src/components/PreflightChecks.tsx @@ -13,6 +13,7 @@ import Loading from "./Loading"; type Props = RouteComponentProps & { preflightData: any provider: 'AWS' | 'GCP' | 'DEFAULT'; + error?: string; }; @@ -97,10 +98,16 @@ const PreflightChecks: React.FC = (props) => { Porter checks that the account has the right permissions and resources to provision a cluster. - {Object.keys(currentMessageConst).map((checkKey) => ( - - ))} - + { + props.error ? + + : + Object.keys(currentMessageConst).map((checkKey) => ( + + )) + + } + ); }; diff --git a/dashboard/src/components/ProvisionerSettings.tsx b/dashboard/src/components/ProvisionerSettings.tsx index 367581df25..61bddbbbf6 100644 --- a/dashboard/src/components/ProvisionerSettings.tsx +++ b/dashboard/src/components/ProvisionerSettings.tsx @@ -133,6 +133,7 @@ const ProvisionerSettings: React.FC = (props) => { const [isLoading, setIsLoading] = useState(false); const [preflightData, setPreflightData] = useState(null) const [preflightFailed, setPreflightFailed] = useState(true) + const [preflightError, setPreflightError] = useState("") const markStepStarted = async (step: string, errMessage?: string) => { try { @@ -480,52 +481,60 @@ const ProvisionerSettings: React.FC = (props) => { useEffect(() => { if (!props.clusterId) { setStep(1) - setPreflightData(null) preflightChecks() } }, [props.selectedClusterVersion, awsRegion]); const preflightChecks = async () => { - setIsLoading(true); - setPreflightData(null); - var data = new PreflightCheckRequest({ - projectId: BigInt(currentProject.id), - cloudProvider: EnumCloudProvider.AWS, - cloudProviderCredentialsId: props.credentialId, - preflightValues: { - case: "eksPreflightValues", - value: new EKSPreflightValues({ - region: awsRegion, - }) + try { + setIsLoading(true); + setPreflightData(null); + setPreflightFailed(true) + setPreflightError(""); + + var data = new PreflightCheckRequest({ + projectId: BigInt(currentProject.id), + cloudProvider: EnumCloudProvider.AWS, + cloudProviderCredentialsId: props.credentialId, + preflightValues: { + case: "eksPreflightValues", + value: new EKSPreflightValues({ + region: awsRegion, + }) + } + }); + const preflightDataResp = await api.preflightCheck( + "", data, + { + id: currentProject.id, + } + ) + // Check if any of the preflight checks has a message + let hasMessage = false; + let errors = "Preflight Checks Failed : "; + for (let check in preflightDataResp?.data?.Msg.preflight_checks) { + if (preflightDataResp?.data?.Msg.preflight_checks[check]?.message) { + hasMessage = true; + errors = errors + check + ", " + } } - }); - const preflightDataResp = await api.preflightCheck( - "", data, - { - id: currentProject.id, + // If none of the checks have a message, set setPreflightFailed to false + if (hasMessage) { + markStepStarted("provisioning-failed", errors); } - ) - // Check if any of the preflight checks has a message - let hasMessage = false; - let errors = "Preflight Checks Failed : "; - for (let check in preflightDataResp?.data?.Msg.preflight_checks) { - if (preflightDataResp?.data?.Msg.preflight_checks[check]?.message) { - hasMessage = true; - errors = errors + check + ", " + if (!hasMessage) { + setPreflightFailed(false); + setStep(2); } + setPreflightData(preflightDataResp?.data?.Msg); + setIsLoading(false) + } catch (err) { + setPreflightError(err) + setIsLoading(false) + setPreflightFailed(true); } - // If none of the checks have a message, set setPreflightFailed to false - if (hasMessage) { - markStepStarted("provisioning-failed", errors); - } - if (!hasMessage) { - setPreflightFailed(false); - setStep(2); - } - setPreflightData(preflightDataResp?.data?.Msg); - setIsLoading(false) } const renderAdvancedSettings = () => { @@ -997,7 +1006,7 @@ const ProvisionerSettings: React.FC = (props) => { , <> - + {(preflightFailed && preflightData) && <>