2
0

ProvisionerSettings.tsx 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508
  1. import React, { useContext, useEffect, useState } from "react";
  2. import {
  3. AWSClusterNetwork,
  4. Cluster,
  5. Contract,
  6. EKS,
  7. EKSLogging,
  8. EKSNodeGroup,
  9. EKSPreflightValues,
  10. EnumCloudProvider,
  11. EnumKubernetesKind,
  12. LoadBalancer,
  13. LoadBalancerType,
  14. NodeGroupType,
  15. PreflightCheckRequest,
  16. QuotaIncreaseRequest,
  17. type EnumQuotaIncrease,
  18. } from "@porter-dev/api-contracts";
  19. import { withRouter, type RouteComponentProps } from "react-router";
  20. import styled from "styled-components";
  21. import { Integer } from "type-fest";
  22. import Heading from "components/form-components/Heading";
  23. import SelectRow from "components/form-components/SelectRow";
  24. import { OFState } from "main/home/onboarding/state";
  25. import { useIntercom } from "lib/hooks/useIntercom";
  26. import api from "shared/api";
  27. import { Context } from "shared/Context";
  28. import { pushFiltered } from "shared/routing";
  29. import { type ClusterState, type ClusterType } from "shared/types";
  30. import { PREFLIGHT_TO_ENUM } from "shared/util";
  31. import info from "assets/info-outlined.svg";
  32. import healthy from "assets/status-healthy.png";
  33. import GPUProvisionSettings from "./GPUProvisionSettings";
  34. import Loading from "./Loading";
  35. import Button from "./porter/Button";
  36. import Checkbox from "./porter/Checkbox";
  37. import Icon from "./porter/Icon";
  38. import Input from "./porter/Input";
  39. import InputSlider from "./porter/InputSlider";
  40. import Select from "./porter/Select";
  41. import Spacer from "./porter/Spacer";
  42. import Text from "./porter/Text";
  43. import Tooltip from "./porter/Tooltip";
  44. import VerticalSteps from "./porter/VerticalSteps";
  45. import PreflightChecks from "./PreflightChecks";
  46. const regionOptions = [
  47. { value: "us-east-1", label: "US East (N. Virginia) us-east-1" },
  48. { value: "us-east-2", label: "US East (Ohio) us-east-2" },
  49. { value: "us-west-1", label: "US West (N. California) us-west-1" },
  50. { value: "us-west-2", label: "US West (Oregon) us-west-2" },
  51. { value: "af-south-1", label: "Africa (Cape Town) af-south-1" },
  52. { value: "ap-east-1", label: "Asia Pacific (Hong Kong) ap-east-1" },
  53. { value: "ap-south-1", label: "Asia Pacific (Mumbai) ap-south-1" },
  54. { value: "ap-northeast-2", label: "Asia Pacific (Seoul) ap-northeast-2" },
  55. { value: "ap-southeast-1", label: "Asia Pacific (Singapore) ap-southeast-1" },
  56. { value: "ap-southeast-2", label: "Asia Pacific (Sydney) ap-southeast-2" },
  57. { value: "ap-northeast-1", label: "Asia Pacific (Tokyo) ap-northeast-1" },
  58. { value: "ca-central-1", label: "Canada (Central) ca-central-1" },
  59. { value: "eu-central-1", label: "Europe (Frankfurt) eu-central-1" },
  60. { value: "eu-west-1", label: "Europe (Ireland) eu-west-1" },
  61. { value: "eu-west-2", label: "Europe (London) eu-west-2" },
  62. { value: "eu-south-1", label: "Europe (Milan) eu-south-1" },
  63. { value: "eu-west-3", label: "Europe (Paris) eu-west-3" },
  64. { value: "eu-north-1", label: "Europe (Stockholm) eu-north-1" },
  65. { value: "me-south-1", label: "Middle East (Bahrain) me-south-1" },
  66. { value: "sa-east-1", label: "South America (São Paulo) sa-east-1" },
  67. ];
  68. // IMPORTANT: when adding more machineTypeOptions here, please make sure that you also enter their resources in useClusterResourceLimits.ts
  69. const machineTypeOptions = [
  70. { value: "t3.medium", label: "t3.medium" },
  71. { value: "t3.large", label: "t3.large" },
  72. { value: "t3.xlarge", label: "t3.xlarge" },
  73. { value: "t3.2xlarge", label: "t3.2xlarge" },
  74. { value: "t3a.medium", label: "t3a.medium" },
  75. { value: "t3a.large", label: "t3a.large" },
  76. { value: "t3a.xlarge", label: "t3a.xlarge" },
  77. { value: "t3a.2xlarge", label: "t3a.2xlarge" },
  78. { value: "t4g.medium", label: "t4g.medium" },
  79. { value: "t4g.large", label: "t4g.large" },
  80. { value: "t4g.xlarge", label: "t4g.xlarge" },
  81. { value: "t4g.2xlarge", label: "t4g.2xlarge" },
  82. { value: "c6i.large", label: "c6i.large" },
  83. { value: "c6i.xlarge", label: "c6i.xlarge" },
  84. { value: "c6i.2xlarge", label: "c6i.2xlarge" },
  85. { value: "c6i.4xlarge", label: "c6i.4xlarge" },
  86. { value: "c6i.8xlarge", label: "c6i.8xlarge" },
  87. { value: "c6a.large", label: "c6a.large" },
  88. { value: "c6a.2xlarge", label: "c6a.2xlarge" },
  89. { value: "c6a.4xlarge", label: "c6a.4xlarge" },
  90. { value: "c6a.8xlarge", label: "c6a.8xlarge" },
  91. { value: "r6i.large", label: "r6i.large" },
  92. { value: "r6i.xlarge", label: "r6i.xlarge" },
  93. { value: "r6i.2xlarge", label: "r6i.2xlarge" },
  94. { value: "r6i.4xlarge", label: "r6i.4xlarge" },
  95. { value: "r6i.8xlarge", label: "r6i.8xlarge" },
  96. { value: "r6i.12xlarge", label: "r6i.12xlarge" },
  97. { value: "r6i.16xlarge", label: "r6i.16xlarge" },
  98. { value: "r6i.24xlarge", label: "r6i.24xlarge" },
  99. { value: "r6i.32xlarge", label: "r6i.32xlarge" },
  100. { value: "m5n.large", label: "m5n.large" },
  101. { value: "m5n.xlarge", label: "m5n.xlarge" },
  102. { value: "m5n.2xlarge", label: "m5n.2xlarge" },
  103. { value: "m6a.large", label: "m6a.large" },
  104. { value: "m6a.xlarge", label: "m6a.xlarge" },
  105. { value: "m6a.2xlarge", label: "m6a.2xlarge" },
  106. { value: "m6a.4xlarge", label: "m6a.4xlarge" },
  107. { value: "m6a.8xlarge", label: "m6a.8xlarge" },
  108. { value: "m6a.12xlarge", label: "m6a.12xlarge" },
  109. { value: "m7a.medium", label: "m7a.medium" },
  110. { value: "m7a.large", label: "m7a.large" },
  111. { value: "m7a.xlarge", label: "m7a.xlarge" },
  112. { value: "m7a.2xlarge", label: "m7a.2xlarge" },
  113. { value: "m7a.4xlarge", label: "m7a.4xlarge" },
  114. { value: "m7a.8xlarge", label: "m7a.8xlarge" },
  115. { value: "m7a.12xlarge", label: "m7a.12xlarge" },
  116. { value: "m7a.16xlarge", label: "m7a.16xlarge" },
  117. { value: "m7a.24xlarge", label: "m7a.24xlarge" },
  118. { value: "m7i.large", label: "m7i.large" },
  119. { value: "m7i.xlarge", label: "m7i.xlarge" },
  120. { value: "m7i.2xlarge", label: "m7i.2xlarge" },
  121. { value: "m7i.4xlarge", label: "m7i.4xlarge" },
  122. { value: "m7i.8xlarge", label: "m7i.8xlarge" },
  123. { value: "m7i.12xlarge", label: "m7i.12xlarge" },
  124. { value: "c7a.medium", label: "c7a.medium" },
  125. { value: "c7a.large", label: "c7a.large" },
  126. { value: "c7a.xlarge", label: "c7a.xlarge" },
  127. { value: "c7a.2xlarge", label: "c7a.2xlarge" },
  128. { value: "c7a.4xlarge", label: "c7a.4xlarge" },
  129. { value: "c7a.8xlarge", label: "c7a.8xlarge" },
  130. { value: "c7a.12xlarge", label: "c7a.12xlarge" },
  131. { value: "c7a.16xlarge", label: "c7a.16xlarge" },
  132. { value: "c7a.24xlarge", label: "c7a.24xlarge" },
  133. ];
  134. const defaultCidrVpc = "10.78.0.0/16";
  135. const defaultCidrServices = "172.20.0.0/16";
  136. const defaultClusterVersion = "v1.27.0";
  137. const initialClusterState: ClusterState = {
  138. clusterName: "",
  139. awsRegion: "us-east-1",
  140. machineType: "t3.medium",
  141. ecrScanningEnabled: false,
  142. guardDutyEnabled: false,
  143. kmsEncryptionEnabled: false,
  144. loadBalancerType: false,
  145. wildCardDomain: "",
  146. IPAllowList: "",
  147. wafV2Enabled: false,
  148. awsTags: "",
  149. wafV2ARN: "",
  150. certificateARN: "",
  151. minInstances: 1,
  152. maxInstances: 10,
  153. additionalNodePolicies: [],
  154. cidrRangeVPC: defaultCidrVpc,
  155. cidrRangeServices: defaultCidrServices,
  156. clusterVersion: defaultClusterVersion,
  157. gpuInstanceType: "g4dn.xlarge",
  158. gpuMinInstances: 0,
  159. gpuMaxInstances: 5,
  160. };
  161. type Props = RouteComponentProps & {
  162. selectedClusterVersion?: Contract;
  163. provisionerError?: string;
  164. credentialId: string;
  165. clusterId?: number | null;
  166. closeModal?: () => void;
  167. gpuModal?: boolean;
  168. };
  169. const ProvisionerSettings: React.FC<Props> = (props) => {
  170. const {
  171. user,
  172. currentProject,
  173. currentCluster,
  174. setCurrentCluster,
  175. setShouldRefreshClusters,
  176. } = useContext(Context);
  177. const [step, setStep] = useState(0);
  178. const [isReadOnly, setIsReadOnly] = useState(false);
  179. const [isClicked, setIsClicked] = useState(false);
  180. const [isLoading, setIsLoading] = useState(false);
  181. const [preflightData, setPreflightData] = useState(null);
  182. const [preflightFailed, setPreflightFailed] = useState<boolean>(true);
  183. const [preflightError, setPreflightError] = useState<string>("");
  184. const [showHelpMessage, setShowHelpMessage] = useState(true);
  185. const [quotaIncrease, setQuotaIncrease] = useState<EnumQuotaIncrease[]>([]);
  186. const [showEmailMessage, setShowEmailMessage] = useState(false);
  187. const { showIntercomWithMessage } = useIntercom();
  188. const [clusterState, setClusterState] = useState(initialClusterState);
  189. const [isExpanded, setIsExpanded] = useState(false);
  190. const [controlPlaneLogs, setControlPlaneLogs] = useState<EKSLogging>(
  191. new EKSLogging()
  192. );
  193. const markStepStarted = async (
  194. step: string,
  195. errMessage?: string
  196. ): Promise<void> => {
  197. try {
  198. await api.updateOnboardingStep(
  199. "<token>",
  200. {
  201. step,
  202. error_message: errMessage,
  203. region: clusterState.awsRegion,
  204. provider: "aws",
  205. },
  206. {
  207. project_id: currentProject ? currentProject.id : 0,
  208. }
  209. );
  210. } catch (err) {}
  211. };
  212. const getStatus = (): React.ReactNode => {
  213. if (isLoading) {
  214. return <Loading />;
  215. }
  216. if (isReadOnly && props.provisionerError === "") {
  217. return "Provisioning is still in progress...";
  218. }
  219. return undefined;
  220. };
  221. const validateInput = (wildCardDomainer: string): false | string => {
  222. if (!wildCardDomainer) {
  223. return "Required for ALB Load Balancer";
  224. }
  225. if (wildCardDomainer?.charAt(0) === "*") {
  226. return "Wildcard domain cannot start with *";
  227. }
  228. return false;
  229. };
  230. function validateIPInput(IPAllowList: string): boolean {
  231. // This regular expression checks for an IP address with a subnet mask.
  232. const regex =
  233. /^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/([0-9]|[1-2][0-9]|3[0-2])$/;
  234. if (!IPAllowList) {
  235. return false;
  236. }
  237. // Split the input string by comma and remove any empty elements
  238. const ipAddresses = IPAllowList?.split(",").filter(Boolean);
  239. // Validate each IP address
  240. for (const ip of ipAddresses) {
  241. if (!regex.test(ip.trim())) {
  242. // If any IP is invalid, return true (error)
  243. return true;
  244. }
  245. }
  246. // If all IPs are valid, return false (no error)
  247. return false;
  248. }
  249. function validateTags(awsTags: string): boolean {
  250. // Regular expression t o check for a key-value pair format "key=value"
  251. const regex = /^[a-zA-Z0-9]+=[a-zA-Z0-9]+$/;
  252. // Split the input string by comma and remove any empty elements
  253. const tags = awsTags.split(",").filter(Boolean);
  254. // Validate each tag
  255. for (const tag of tags) {
  256. if (!regex.test(tag.trim())) {
  257. // If any tag is invalid, return true (error)
  258. return true;
  259. }
  260. }
  261. // If all tags are valid, return false (no error)
  262. return false;
  263. }
  264. const clusterNameDoesNotExist = (): boolean => {
  265. return !clusterState.clusterName;
  266. };
  267. const userProvisioning = (): boolean => {
  268. // If the cluster is updating or updating unavailabe but there are no errors do not allow re-provisioning
  269. return isReadOnly && props.provisionerError === "";
  270. };
  271. const isDisabled = (): boolean | undefined => {
  272. return (
  273. clusterNameDoesNotExist() ||
  274. userProvisioning() ||
  275. isClicked ||
  276. (currentCluster && !currentProject?.enable_reprovision)
  277. );
  278. };
  279. function convertStringToTags(tagString: string): Record<string, string> {
  280. if (typeof tagString !== "string" || tagString.trim() === "") {
  281. return {};
  282. }
  283. // Split the input string by comma, then reduce the resulting array to an object
  284. const tags = tagString
  285. .split(",")
  286. .reduce<Record<string, string>>((obj, item) => {
  287. // Split each item by "=", and trim whitespace from both key and value
  288. const [key, value] = item.split("=").map((part) => part.trim());
  289. // Only add the key-value pair to the object if both key and value are present
  290. if (key && value) {
  291. obj[key] = value;
  292. }
  293. return obj;
  294. }, {});
  295. return tags;
  296. }
  297. const handleClusterStateChange = <K extends keyof ClusterState>(
  298. key: K,
  299. value: ClusterState[K]
  300. ): void => {
  301. setClusterState((prevState: ClusterState) => ({
  302. ...prevState,
  303. [key]: value,
  304. }));
  305. };
  306. const createClusterObj = (): Contract => {
  307. const loadBalancerObj = new LoadBalancer({});
  308. loadBalancerObj.loadBalancerType = LoadBalancerType.NLB;
  309. if (clusterState.loadBalancerType) {
  310. loadBalancerObj.loadBalancerType = LoadBalancerType.ALB;
  311. loadBalancerObj.wildcardDomain = clusterState.wildCardDomain;
  312. if (clusterState.awsTags) {
  313. loadBalancerObj.tags = convertStringToTags(clusterState.awsTags);
  314. }
  315. if (clusterState.IPAllowList) {
  316. loadBalancerObj.allowlistIpRanges = clusterState.IPAllowList;
  317. }
  318. if (clusterState.wafV2Enabled) {
  319. loadBalancerObj.enableWafv2 = clusterState.wafV2Enabled;
  320. } else {
  321. loadBalancerObj.enableWafv2 = false;
  322. }
  323. if (clusterState.wafV2ARN) {
  324. loadBalancerObj.wafv2Arn = clusterState.wafV2ARN;
  325. }
  326. if (clusterState.certificateARN) {
  327. loadBalancerObj.additionalCertificateArns =
  328. clusterState.certificateARN.split(",");
  329. }
  330. }
  331. const nodeGroups = [
  332. new EKSNodeGroup({
  333. instanceType: "t3.medium",
  334. minInstances: 1,
  335. maxInstances: 5,
  336. nodeGroupType: NodeGroupType.SYSTEM,
  337. isStateful: false,
  338. additionalPolicies: clusterState.additionalNodePolicies,
  339. }),
  340. new EKSNodeGroup({
  341. instanceType: "t3.large",
  342. minInstances: 1,
  343. maxInstances: 1,
  344. nodeGroupType: NodeGroupType.MONITORING,
  345. isStateful: true,
  346. additionalPolicies: clusterState.additionalNodePolicies,
  347. }),
  348. new EKSNodeGroup({
  349. instanceType: clusterState.machineType,
  350. minInstances: clusterState.minInstances || 1,
  351. maxInstances: clusterState.maxInstances || 10,
  352. nodeGroupType: NodeGroupType.APPLICATION,
  353. isStateful: false,
  354. additionalPolicies: clusterState.additionalNodePolicies,
  355. }),
  356. ];
  357. // Conditionally add the last EKSNodeGroup if gpuModal is enabled
  358. if (props.gpuModal) {
  359. nodeGroups.push(
  360. new EKSNodeGroup({
  361. instanceType: clusterState.gpuInstanceType,
  362. minInstances: clusterState.gpuMinInstances || 0,
  363. maxInstances: clusterState.gpuMaxInstances || 5,
  364. nodeGroupType: NodeGroupType.CUSTOM,
  365. isStateful: false,
  366. additionalPolicies: clusterState.additionalNodePolicies,
  367. })
  368. );
  369. }
  370. const data = new Contract({
  371. cluster: new Cluster({
  372. projectId: currentProject.id,
  373. kind: EnumKubernetesKind.EKS,
  374. cloudProvider: EnumCloudProvider.AWS,
  375. cloudProviderCredentialsId: String(props.credentialId),
  376. kindValues: {
  377. case: "eksKind",
  378. value: new EKS({
  379. clusterName: clusterState.clusterName,
  380. clusterVersion:
  381. clusterState.clusterVersion || defaultClusterVersion,
  382. cidrRange: clusterState.cidrRangeVPC || defaultCidrVpc, // deprecated in favour of network.cidrRangeVPC: can be removed after december 2023
  383. region: clusterState.awsRegion,
  384. loadBalancer: loadBalancerObj,
  385. logging: controlPlaneLogs,
  386. enableGuardDuty: clusterState.guardDutyEnabled,
  387. enableKmsEncryption: clusterState.kmsEncryptionEnabled,
  388. enableEcrScanning: clusterState.ecrScanningEnabled,
  389. network: new AWSClusterNetwork({
  390. vpcCidr: clusterState.cidrRangeVPC || defaultCidrVpc,
  391. serviceCidr:
  392. clusterState.cidrRangeServices || defaultCidrServices,
  393. }),
  394. nodeGroups,
  395. }),
  396. },
  397. }),
  398. });
  399. return data;
  400. };
  401. const createCluster = async (): Promise<void> => {
  402. setIsLoading(true);
  403. setIsClicked(true);
  404. const data = createClusterObj();
  405. if (props.clusterId) {
  406. data.cluster.clusterId = props.clusterId;
  407. }
  408. try {
  409. setIsReadOnly(true);
  410. if (!props.clusterId) {
  411. void markStepStarted("pre-provisioning-check-started");
  412. }
  413. const res = await api.createContract("<token>", data, {
  414. project_id: currentProject.id,
  415. });
  416. if (!props.clusterId) {
  417. void markStepStarted("provisioning-started");
  418. }
  419. // Only refresh and set clusters on initial create
  420. // if (!props.clusterId) {
  421. setShouldRefreshClusters(true);
  422. api
  423. .getClusters("<token>", {}, { id: currentProject.id })
  424. .then(({ data }) => {
  425. data.forEach((cluster: ClusterType) => {
  426. if (cluster.id === res.data.contract_revision?.cluster_id) {
  427. // setHasFinishedOnboarding(true);
  428. setCurrentCluster(cluster);
  429. OFState.actions.goTo("clean_up");
  430. if (!props.gpuModal) {
  431. pushFiltered(props, "/cluster-dashboard", ["project_id"], {
  432. cluster: cluster.name,
  433. });
  434. } else {
  435. if (props.closeModal) {
  436. props.closeModal();
  437. }
  438. }
  439. }
  440. });
  441. })
  442. .catch((err) => {
  443. if (err) {
  444. // setHasFinishedOnboarding(true);
  445. OFState.actions.goTo("clean_up");
  446. pushFiltered(props, "/cluster-dashboard", ["project_id"], {});
  447. }
  448. });
  449. // }
  450. if (props?.closeModal) {
  451. props?.closeModal();
  452. }
  453. } catch (err) {
  454. const errMessage = err.response.data?.error.replace("unknown: ", "");
  455. // hacky, need to standardize error contract with backend
  456. setIsClicked(false);
  457. setIsLoading(false);
  458. void markStepStarted("provisioning-failed", errMessage);
  459. // enable edit again only in the case of an error
  460. setIsClicked(false);
  461. setIsReadOnly(false);
  462. } finally {
  463. setIsLoading(false);
  464. }
  465. };
  466. useEffect(() => {
  467. setIsReadOnly(
  468. props.clusterId &&
  469. (currentCluster.status === "UPDATING" ||
  470. currentCluster.status === "UPDATING_UNAVAILABLE")
  471. );
  472. handleClusterStateChange(
  473. "clusterName",
  474. `${currentProject.name}-cluster-${Math.random()
  475. .toString(36)
  476. .substring(2, 8)}`
  477. );
  478. }, []);
  479. useEffect(() => {
  480. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  481. const contract = props.selectedClusterVersion as any;
  482. // Unmarshall Contract here
  483. if (contract?.cluster) {
  484. const eksValues: EKS = contract.cluster?.eksKind as EKS;
  485. if (eksValues == null) {
  486. return;
  487. }
  488. eksValues.nodeGroups.forEach((nodeGroup: EKSNodeGroup) => {
  489. if (
  490. nodeGroup.nodeGroupType.toString() === "NODE_GROUP_TYPE_APPLICATION"
  491. ) {
  492. handleClusterStateChange("machineType", nodeGroup.instanceType);
  493. handleClusterStateChange("minInstances", nodeGroup.minInstances);
  494. handleClusterStateChange("maxInstances", nodeGroup.maxInstances);
  495. }
  496. if (nodeGroup.additionalPolicies?.length > 0) {
  497. handleClusterStateChange(
  498. "additionalNodePolicies",
  499. nodeGroup.additionalPolicies
  500. );
  501. }
  502. });
  503. handleClusterStateChange("clusterName", eksValues.clusterName);
  504. handleClusterStateChange("awsRegion", eksValues.region);
  505. handleClusterStateChange("clusterVersion", eksValues.clusterVersion);
  506. handleClusterStateChange(
  507. "cidrRangeVPC",
  508. eksValues.cidrRange ?? eksValues.network?.vpcCidr ?? defaultCidrVpc
  509. );
  510. handleClusterStateChange(
  511. "cidrRangeServices",
  512. eksValues.network?.serviceCidr ?? defaultCidrServices
  513. );
  514. if (eksValues.loadBalancer != null) {
  515. handleClusterStateChange(
  516. "IPAllowList",
  517. eksValues.loadBalancer.allowlistIpRanges
  518. );
  519. handleClusterStateChange(
  520. "wildCardDomain",
  521. eksValues.loadBalancer.wildcardDomain
  522. );
  523. const awsTags = eksValues.loadBalancer.tags
  524. ? Object.entries(eksValues.loadBalancer.tags)
  525. .map(([key, value]) => `${key}=${value}`)
  526. .join(",")
  527. : "";
  528. handleClusterStateChange("awsTags", awsTags);
  529. const loadBalancerType =
  530. eksValues.loadBalancer?.loadBalancerType?.toString() ===
  531. "LOAD_BALANCER_TYPE_ALB";
  532. handleClusterStateChange("loadBalancerType", loadBalancerType);
  533. handleClusterStateChange("wafV2ARN", eksValues.loadBalancer?.wafv2Arn);
  534. handleClusterStateChange(
  535. "wafV2Enabled",
  536. eksValues.loadBalancer?.enableWafv2
  537. );
  538. }
  539. if (eksValues.logging != null) {
  540. const logging = new EKSLogging({
  541. enableApiServerLogs: eksValues.logging.enableApiServerLogs,
  542. enableAuditLogs: eksValues.logging.enableAuditLogs,
  543. enableAuthenticatorLogs: eksValues.logging.enableAuthenticatorLogs,
  544. enableControllerManagerLogs:
  545. eksValues.logging.enableControllerManagerLogs,
  546. enableSchedulerLogs: eksValues.logging.enableSchedulerLogs,
  547. });
  548. setControlPlaneLogs(logging);
  549. }
  550. handleClusterStateChange("guardDutyEnabled", eksValues.enableGuardDuty);
  551. handleClusterStateChange(
  552. "kmsEncryptionEnabled",
  553. eksValues.enableKmsEncryption
  554. );
  555. handleClusterStateChange(
  556. "ecrScanningEnabled",
  557. eksValues.enableEcrScanning
  558. );
  559. handleClusterStateChange(
  560. "certificateARN",
  561. eksValues.loadBalancer?.additionalCertificateArns?.join(",")
  562. );
  563. }
  564. }, [isExpanded, props.selectedClusterVersion]);
  565. useEffect(() => {
  566. if (!props.clusterId) {
  567. if (clusterState.clusterName !== "") {
  568. setStep(1);
  569. try {
  570. // eslint-disable-next-line @typescript-eslint/no-floating-promises
  571. preflightChecks();
  572. // Handle the resolved value if necessary
  573. } catch (error) {
  574. if (error) {
  575. setStep(0);
  576. }
  577. }
  578. }
  579. }
  580. }, [clusterState]);
  581. const proceedToProvision = async (): Promise<void> => {
  582. setShowEmailMessage(true);
  583. void markStepStarted("requested-quota-increase");
  584. setStep(2);
  585. };
  586. const requestQuotasAndProvision = async (): Promise<void> => {
  587. await requestQuotaIncrease();
  588. await createCluster();
  589. };
  590. const requestQuotaIncrease = async (): Promise<void> => {
  591. try {
  592. setIsLoading(true);
  593. const data = new QuotaIncreaseRequest({
  594. projectId: BigInt(currentProject.id),
  595. cloudProvider: EnumCloudProvider.AWS,
  596. cloudProviderCredentialsId: props.credentialId,
  597. preflightValues: {
  598. case: "eksPreflightValues",
  599. value: new EKSPreflightValues({
  600. region: clusterState.awsRegion,
  601. }),
  602. },
  603. quotaIncreases: quotaIncrease,
  604. });
  605. await api.requestQuotaIncrease("<token>", data, {
  606. id: currentProject.id,
  607. });
  608. setIsLoading(false);
  609. } catch (err) {
  610. setIsLoading(false);
  611. }
  612. };
  613. const preflightChecks = async (): Promise<void> => {
  614. try {
  615. setIsLoading(true);
  616. setPreflightData(null);
  617. setPreflightFailed(true);
  618. setPreflightError("");
  619. setShowEmailMessage(false);
  620. const contract = createClusterObj();
  621. const data = new PreflightCheckRequest({
  622. contract,
  623. });
  624. const preflightDataResp = await api.preflightCheck("<token>", data, {
  625. id: currentProject.id,
  626. });
  627. // Check if any of the preflight checks has a message
  628. let hasMessage = false;
  629. let errors = "Preflight Checks Failed : ";
  630. const quotas: EnumQuotaIncrease[] = [];
  631. for (const check in preflightDataResp?.data?.Msg.preflight_checks) {
  632. if (preflightDataResp?.data?.Msg.preflight_checks[check]?.message) {
  633. quotas.push(PREFLIGHT_TO_ENUM[check]);
  634. hasMessage = true;
  635. errors = errors + check + ", ";
  636. }
  637. }
  638. setQuotaIncrease(quotas);
  639. // If none of the checks have a message, set setPreflightFailed to false
  640. if (hasMessage) {
  641. showIntercomWithMessage({
  642. message: "I am running into an issue provisioning a cluster.",
  643. });
  644. void markStepStarted("provisioning-failed", errors);
  645. }
  646. if (!hasMessage) {
  647. setPreflightFailed(false);
  648. setStep(2);
  649. }
  650. setPreflightData(preflightDataResp?.data?.Msg);
  651. setIsLoading(false);
  652. } catch (err) {
  653. setPreflightError(err);
  654. setIsLoading(false);
  655. setPreflightFailed(true);
  656. }
  657. };
  658. const renderAdvancedSettings = (): JSX.Element => {
  659. return (
  660. <>
  661. {
  662. <Heading>
  663. <ExpandHeader
  664. onClick={() => {
  665. setIsExpanded(!isExpanded);
  666. }}
  667. isExpanded={isExpanded}
  668. >
  669. <i className="material-icons">arrow_drop_down</i>
  670. Advanced settings
  671. </ExpandHeader>
  672. </Heading>
  673. }
  674. {isExpanded && (
  675. <>
  676. {user?.isPorterUser && (
  677. <Input
  678. width="350px"
  679. type="string"
  680. value={clusterState.clusterVersion}
  681. disabled={true}
  682. setValue={(x: string) => {
  683. handleClusterStateChange("clusterVersion", x);
  684. }}
  685. label="Cluster version (only shown to porter.run emails)"
  686. placeholder={""}
  687. />
  688. )}
  689. <Spacer y={1} />
  690. <Select
  691. options={machineTypeOptions}
  692. width="350px"
  693. disabled={isReadOnly}
  694. value={clusterState.machineType}
  695. setValue={(x: string) => {
  696. handleClusterStateChange("machineType", x);
  697. }}
  698. label="Machine type"
  699. />
  700. <Spacer y={1} />
  701. <Input
  702. width="350px"
  703. type="number"
  704. disabled={isReadOnly || isLoading}
  705. value={clusterState.maxInstances.toString()}
  706. setValue={(x: string) => {
  707. const num = parseInt(x, 10);
  708. if (!isNaN(num)) {
  709. handleClusterStateChange("maxInstances", num);
  710. }
  711. }}
  712. label="Maximum number of application nodes"
  713. placeholder="ex: 1"
  714. />
  715. <Spacer y={1} />
  716. <Input
  717. width="350px"
  718. type="number"
  719. disabled={isReadOnly || isLoading}
  720. value={clusterState.minInstances.toString()}
  721. setValue={(x: string) => {
  722. const num = parseInt(x, 10);
  723. if (num === undefined) {
  724. return;
  725. }
  726. handleClusterStateChange("minInstances", num);
  727. }}
  728. label="Minimum number of application nodes. If set to 0, no applications will be deployed."
  729. placeholder="ex: 1"
  730. />
  731. <Spacer y={1} />
  732. <Input
  733. width="350px"
  734. type="string"
  735. value={clusterState.cidrRangeVPC}
  736. disabled={props.clusterId !== undefined || isLoading}
  737. setValue={(x: string) => {
  738. handleClusterStateChange("cidrRangeVPC", x);
  739. }}
  740. label="CIDR range for AWS VPC"
  741. placeholder="ex: 10.78.0.0/16"
  742. />
  743. <Spacer y={1} />
  744. <Input
  745. width="350px"
  746. type="string"
  747. value={clusterState.cidrRangeServices}
  748. disabled={props.clusterId !== undefined || isLoading}
  749. setValue={(x: string) => {
  750. handleClusterStateChange("cidrRangeServices", x);
  751. }}
  752. label="CIDR range for Kubernetes internal services"
  753. placeholder="ex: 172.20.0.0/16"
  754. />
  755. {currentProject && (
  756. <>
  757. <Spacer y={1} />
  758. <Checkbox
  759. checked={controlPlaneLogs.enableApiServerLogs}
  760. disabled={isReadOnly}
  761. toggleChecked={() => {
  762. setControlPlaneLogs(
  763. new EKSLogging({
  764. ...controlPlaneLogs,
  765. enableApiServerLogs:
  766. !controlPlaneLogs.enableApiServerLogs,
  767. })
  768. );
  769. }}
  770. disabledTooltip={
  771. "Wait for provisioning to complete before editing this field."
  772. }
  773. >
  774. <Text color="helper">
  775. Enable API Server logs in CloudWatch for this cluster
  776. </Text>
  777. </Checkbox>
  778. <Spacer y={1} />
  779. <Checkbox
  780. checked={controlPlaneLogs.enableAuditLogs}
  781. disabled={isReadOnly}
  782. toggleChecked={() => {
  783. setControlPlaneLogs(
  784. new EKSLogging({
  785. ...controlPlaneLogs,
  786. enableAuditLogs: !controlPlaneLogs.enableAuditLogs,
  787. })
  788. );
  789. }}
  790. disabledTooltip={
  791. "Wait for provisioning to complete before editing this field."
  792. }
  793. >
  794. <Text color="helper">
  795. Enable Audit logs in CloudWatch for this cluster
  796. </Text>
  797. </Checkbox>
  798. <Spacer y={1} />
  799. <Checkbox
  800. checked={controlPlaneLogs.enableAuthenticatorLogs}
  801. disabled={isReadOnly}
  802. toggleChecked={() => {
  803. setControlPlaneLogs(
  804. new EKSLogging({
  805. ...controlPlaneLogs,
  806. enableAuthenticatorLogs:
  807. !controlPlaneLogs.enableAuthenticatorLogs,
  808. })
  809. );
  810. }}
  811. disabledTooltip={
  812. "Wait for provisioning to complete before editing this field."
  813. }
  814. >
  815. <Text color="helper">
  816. Enable Authenticator logs in CloudWatch for this cluster
  817. </Text>
  818. </Checkbox>
  819. <Spacer y={1} />
  820. <Checkbox
  821. checked={controlPlaneLogs.enableControllerManagerLogs}
  822. disabled={isReadOnly}
  823. toggleChecked={() => {
  824. setControlPlaneLogs(
  825. new EKSLogging({
  826. ...controlPlaneLogs,
  827. enableControllerManagerLogs:
  828. !controlPlaneLogs.enableControllerManagerLogs,
  829. })
  830. );
  831. }}
  832. disabledTooltip={
  833. "Wait for provisioning to complete before editing this field."
  834. }
  835. >
  836. <Text color="helper">
  837. Enable Controller Manager logs in CloudWatch for this
  838. cluster
  839. </Text>
  840. </Checkbox>
  841. <Spacer y={1} />
  842. <Checkbox
  843. checked={controlPlaneLogs.enableSchedulerLogs}
  844. disabled={isReadOnly}
  845. toggleChecked={() => {
  846. setControlPlaneLogs(
  847. new EKSLogging({
  848. ...controlPlaneLogs,
  849. enableSchedulerLogs:
  850. !controlPlaneLogs.enableSchedulerLogs,
  851. })
  852. );
  853. }}
  854. disabledTooltip={
  855. "Wait for provisioning to complete before editing this field."
  856. }
  857. >
  858. <Text color="helper">
  859. Enable Scheduler logs in CloudWatch for this cluster
  860. </Text>
  861. </Checkbox>
  862. <Spacer y={1} />
  863. <Checkbox
  864. checked={clusterState.loadBalancerType}
  865. disabled={isReadOnly}
  866. toggleChecked={() => {
  867. if (clusterState.loadBalancerType) {
  868. handleClusterStateChange("wildCardDomain", "");
  869. handleClusterStateChange("IPAllowList", "");
  870. handleClusterStateChange("wafV2ARN", "");
  871. handleClusterStateChange("awsTags", "");
  872. handleClusterStateChange("certificateARN", "");
  873. handleClusterStateChange("wafV2Enabled", false);
  874. }
  875. handleClusterStateChange(
  876. "loadBalancerType",
  877. !clusterState.loadBalancerType
  878. );
  879. }}
  880. disabledTooltip={
  881. "Wait for provisioning to complete before editing this field."
  882. }
  883. >
  884. <Text color="helper">Set Load Balancer Type to ALB</Text>
  885. </Checkbox>
  886. <Spacer y={1} />
  887. {clusterState.loadBalancerType && (
  888. <>
  889. <FlexCenter>
  890. <Input
  891. width="350px"
  892. disabled={isReadOnly}
  893. value={clusterState.wildCardDomain}
  894. setValue={(x: string) => {
  895. handleClusterStateChange("wildCardDomain", x);
  896. }}
  897. label="Wildcard domain"
  898. placeholder="user-2.porter.run"
  899. />
  900. <Wrapper>
  901. <Tooltip
  902. content={
  903. "The provided domain should have a wildcard subdomain pointed to the LoadBalancer address. Using testing.porter.run will create a certificate for testing.porter.run with a SAN *.testing.porter.run"
  904. }
  905. position="right"
  906. >
  907. <Icon src={info} />
  908. </Tooltip>
  909. </Wrapper>
  910. </FlexCenter>
  911. {validateInput(clusterState.wildCardDomain) && (
  912. <ErrorInLine>
  913. <i className="material-icons">error</i>
  914. {validateInput(clusterState.wildCardDomain)}
  915. </ErrorInLine>
  916. )}
  917. <Spacer y={1} />
  918. <FlexCenter>
  919. <>
  920. <Input
  921. width="350px"
  922. disabled={isReadOnly}
  923. value={clusterState.IPAllowList}
  924. setValue={(x: string) => {
  925. handleClusterStateChange("IPAllowList", x);
  926. }}
  927. label="IP Allow List"
  928. placeholder="160.72.72.58/32,160.72.72.59/32"
  929. />
  930. <Wrapper>
  931. <Tooltip
  932. content={
  933. "Each range should be a CIDR, including netmask such as 10.1.2.3/21. To use multiple values, they should be comma-separated with no spaces"
  934. }
  935. position="right"
  936. >
  937. <Icon src={info} />
  938. </Tooltip>
  939. </Wrapper>
  940. </>
  941. </FlexCenter>
  942. {validateIPInput(clusterState.IPAllowList) && (
  943. <ErrorInLine>
  944. <i className="material-icons">error</i>
  945. {"Needs to be Comma Separated Valid IP addresses"}
  946. </ErrorInLine>
  947. )}
  948. <Spacer y={1} />
  949. <Input
  950. width="350px"
  951. disabled={isReadOnly}
  952. value={clusterState.certificateARN}
  953. setValue={(x: string) => {
  954. handleClusterStateChange("certificateARN", x);
  955. }}
  956. label="Certificate ARN"
  957. placeholder="arn:aws:acm:REGION:ACCOUNT_ID:certificate/ACM_ID"
  958. />
  959. <Spacer y={1} />
  960. <FlexCenter>
  961. <>
  962. <Input
  963. width="350px"
  964. disabled={isReadOnly}
  965. value={clusterState.awsTags}
  966. setValue={(x: string) => {
  967. handleClusterStateChange("awsTags", x);
  968. }}
  969. label="AWS Tags"
  970. placeholder="costcenter=1,environment=10,project=32"
  971. />
  972. <Wrapper>
  973. <Tooltip
  974. content={
  975. "Each tag should be of the format 'key=value'. To use multiple values, they should be comma-separated with no spaces."
  976. }
  977. position="right"
  978. >
  979. <Icon src={info} />
  980. </Tooltip>
  981. </Wrapper>
  982. </>
  983. </FlexCenter>
  984. {validateTags(clusterState.awsTags) && (
  985. <ErrorInLine>
  986. <i className="material-icons">error</i>
  987. {"Needs to be Comma Separated Valid Tags"}
  988. </ErrorInLine>
  989. )}
  990. <Spacer y={1} />
  991. {/* <Checkbox
  992. checked={accessS3Logs}
  993. disabled={isReadOnly}
  994. toggleChecked={() => {
  995. {
  996. console.log(!accessS3Logs)
  997. }
  998. setAccessS3Logs(!accessS3Logs)
  999. }}
  1000. disabledTooltip={"Wait for provisioning to complete before editing this field."}
  1001. >
  1002. <Text color="helper">Access Logs to S3</Text>
  1003. </Checkbox> */}
  1004. {/* <Spacer y={1} /> */}
  1005. <Checkbox
  1006. checked={clusterState.wafV2Enabled}
  1007. disabled={isReadOnly}
  1008. toggleChecked={() => {
  1009. if (clusterState.wafV2Enabled) {
  1010. handleClusterStateChange("wafV2ARN", "");
  1011. }
  1012. handleClusterStateChange(
  1013. "wafV2Enabled",
  1014. !clusterState.wafV2Enabled
  1015. );
  1016. }}
  1017. disabledTooltip={
  1018. "Wait for provisioning to complete before editing this field."
  1019. }
  1020. >
  1021. <Text color="helper">WAFv2 Enabled</Text>
  1022. </Checkbox>
  1023. {clusterState.wafV2Enabled && (
  1024. <>
  1025. <Spacer y={1} />
  1026. <FlexCenter>
  1027. <>
  1028. <Input
  1029. width="500px"
  1030. type="string"
  1031. label="WAFv2 ARN"
  1032. disabled={isReadOnly}
  1033. value={clusterState.wafV2ARN}
  1034. setValue={(x: string) => {
  1035. handleClusterStateChange("wafV2ARN", x);
  1036. }}
  1037. placeholder="arn:aws:wafv2:REGION:ACCOUNT_ID:regional/webacl/ACL_NAME/RULE_ID"
  1038. />
  1039. <Wrapper>
  1040. <Tooltip
  1041. content={
  1042. 'Only Regional WAFv2 is supported. To find your ARN, navigate to the WAF console, click the Gear icon in the top right, and toggle "ARN" to on'
  1043. }
  1044. position="right"
  1045. >
  1046. <Icon src={info} />
  1047. </Tooltip>
  1048. </Wrapper>
  1049. </>
  1050. </FlexCenter>
  1051. {(clusterState.wafV2ARN === undefined ||
  1052. clusterState.wafV2ARN?.length === 0) && (
  1053. <ErrorInLine>
  1054. <i className="material-icons">error</i>
  1055. {"Required if WafV2 is enabled"}
  1056. </ErrorInLine>
  1057. )}
  1058. </>
  1059. )}
  1060. <Spacer y={1} />
  1061. </>
  1062. )}
  1063. <FlexCenter>
  1064. <Checkbox
  1065. checked={clusterState.ecrScanningEnabled}
  1066. disabled={isReadOnly}
  1067. toggleChecked={() => {
  1068. handleClusterStateChange(
  1069. "ecrScanningEnabled",
  1070. !clusterState.ecrScanningEnabled
  1071. );
  1072. }}
  1073. disabledTooltip={
  1074. "Wait for provisioning to complete before editing this field."
  1075. }
  1076. >
  1077. <Text color="helper">
  1078. Enable ECR scanning for this cluster
  1079. </Text>
  1080. </Checkbox>
  1081. </FlexCenter>
  1082. <Spacer y={1} />
  1083. <FlexCenter>
  1084. <Checkbox
  1085. checked={clusterState.guardDutyEnabled}
  1086. disabled={isReadOnly}
  1087. toggleChecked={() => {
  1088. handleClusterStateChange(
  1089. "guardDutyEnabled",
  1090. !clusterState.guardDutyEnabled
  1091. );
  1092. }}
  1093. disabledTooltip={
  1094. "Wait for provisioning to complete before editing this field."
  1095. }
  1096. >
  1097. <Text color="helper">
  1098. Install AWS GuardDuty agent on this cluster (see details
  1099. to fully enable)
  1100. </Text>
  1101. <Spacer x={0.5} inline />
  1102. <Tooltip
  1103. content={
  1104. "In addition to installing the agent, you must enable GuardDuty through your AWS Console and enable EKS Protection in the EKS Protection tab of the GuardDuty console."
  1105. }
  1106. position="right"
  1107. >
  1108. <Icon src={info} />
  1109. </Tooltip>
  1110. </Checkbox>
  1111. </FlexCenter>
  1112. <Spacer y={1} />
  1113. <FlexCenter>
  1114. <Checkbox
  1115. checked={clusterState.kmsEncryptionEnabled}
  1116. disabled={isReadOnly}
  1117. toggleChecked={() => {
  1118. handleClusterStateChange(
  1119. "kmsEncryptionEnabled",
  1120. !clusterState.kmsEncryptionEnabled
  1121. );
  1122. }}
  1123. disabledTooltip={
  1124. clusterState.kmsEncryptionEnabled
  1125. ? "KMS encryption can never be disabled."
  1126. : "Wait for provisioning to complete before editing this field."
  1127. }
  1128. >
  1129. <Text color="helper">
  1130. Enable KMS encryption for this cluster
  1131. </Text>
  1132. <Spacer x={0.5} inline />
  1133. <Tooltip
  1134. content={
  1135. "KMS encryption can never be disabled. Deletion of the KMS key will permanently place this cluster in a degraded state."
  1136. }
  1137. position="right"
  1138. >
  1139. <Icon src={info} />
  1140. </Tooltip>
  1141. </Checkbox>
  1142. </FlexCenter>
  1143. {clusterState.kmsEncryptionEnabled && (
  1144. <ErrorInLine>
  1145. <i className="material-icons">error</i>
  1146. {
  1147. "KMS encryption can never be disabled. Deletion of the KMS key will permanently place this cluster in a degraded state."
  1148. }
  1149. </ErrorInLine>
  1150. )}
  1151. <Spacer y={1} />
  1152. </>
  1153. )}
  1154. </>
  1155. )}
  1156. </>
  1157. );
  1158. };
  1159. const dismissPreflight = async (): Promise<void> => {
  1160. setShowHelpMessage(false);
  1161. try {
  1162. await preflightChecks();
  1163. } catch (err) {}
  1164. };
  1165. const renderForm = (): JSX.Element => {
  1166. // Render simplified form if initial create
  1167. if (!props.clusterId) {
  1168. return (
  1169. <>
  1170. <VerticalSteps
  1171. currentStep={step}
  1172. steps={[
  1173. <>
  1174. <Text size={16}>Select an AWS region</Text>
  1175. <Spacer y={0.5} />
  1176. <Text color="helper">
  1177. Porter will automatically provision your infrastructure in the
  1178. specified region.
  1179. </Text>
  1180. <Spacer height="10px" />
  1181. <SelectRow
  1182. options={regionOptions}
  1183. width="350px"
  1184. disabled={isReadOnly || isLoading}
  1185. value={clusterState.awsRegion}
  1186. scrollBuffer={true}
  1187. dropdownMaxHeight="240px"
  1188. setActiveValue={(x: string) => {
  1189. handleClusterStateChange("awsRegion", x);
  1190. }}
  1191. label="📍 AWS region"
  1192. />
  1193. <>
  1194. {(user?.isPorterUser || currentProject?.multi_cluster) &&
  1195. renderAdvancedSettings()}
  1196. </>
  1197. </>,
  1198. <>
  1199. {showEmailMessage ? (
  1200. <>
  1201. <CheckItemContainer>
  1202. <CheckItemTop>
  1203. <StatusIcon src={healthy} />
  1204. <Spacer inline x={1} />
  1205. <Text style={{ marginLeft: "10px", flex: 1 }}>
  1206. {
  1207. "Porter will request to increase quotas when you provision"
  1208. }
  1209. </Text>
  1210. </CheckItemTop>
  1211. </CheckItemContainer>
  1212. </>
  1213. ) : (
  1214. <>
  1215. <PreflightChecks
  1216. provider="AWS"
  1217. preflightData={preflightData}
  1218. error={preflightError}
  1219. />
  1220. <Spacer y={0.5} />
  1221. {preflightFailed && preflightData && (
  1222. <>
  1223. {showHelpMessage && currentProject?.quota_increase ? (
  1224. <>
  1225. <Text color="helper">
  1226. Your account currently is blocked from
  1227. provisioning in {clusterState.awsRegion} due to a
  1228. quota limit imposed by AWS. Either change the
  1229. region or request to increase quotas.
  1230. </Text>
  1231. <Spacer y={0.5} />
  1232. <Text color="helper">
  1233. Porter can automatically request quota increases
  1234. on your behalf and email you once the cluster is
  1235. provisioned.
  1236. </Text>
  1237. <Spacer y={0.5} />
  1238. <div
  1239. style={{
  1240. display: "flex",
  1241. justifyContent: "flex-start",
  1242. alignItems: "center",
  1243. gap: "15px",
  1244. }}
  1245. >
  1246. <Button
  1247. disabled={isLoading}
  1248. onClick={proceedToProvision}
  1249. >
  1250. Auto request increase
  1251. </Button>
  1252. <Button
  1253. disabled={isLoading}
  1254. onClick={dismissPreflight}
  1255. color="#313539"
  1256. >
  1257. I'll do it myself
  1258. </Button>
  1259. </div>
  1260. </>
  1261. ) : (
  1262. <>
  1263. <Text color="helper">
  1264. Your account currently is blocked from
  1265. provisioning in {clusterState.awsRegion} due to a
  1266. quota limit imposed by AWS. Either change the
  1267. region or request to increase quotas.
  1268. </Text>
  1269. <Spacer y={0.5} />
  1270. <Button
  1271. disabled={isLoading}
  1272. onClick={preflightChecks}
  1273. >
  1274. Retry checks
  1275. </Button>
  1276. </>
  1277. )}
  1278. </>
  1279. )}
  1280. </>
  1281. )}
  1282. </>,
  1283. <>
  1284. <Text size={16}>Provision your cluster</Text>
  1285. <Spacer y={1} />
  1286. {showEmailMessage && (
  1287. <>
  1288. <Text color="helper">
  1289. After your quota requests have been approved by AWS,
  1290. Porter will email you when your cluster has been
  1291. provisioned.
  1292. </Text>
  1293. <Spacer y={1} />
  1294. </>
  1295. )}
  1296. <Button
  1297. disabled={(preflightFailed && !showEmailMessage) || isLoading}
  1298. onClick={
  1299. showEmailMessage ? requestQuotasAndProvision : createCluster
  1300. }
  1301. status={getStatus()}
  1302. >
  1303. Provision
  1304. </Button>
  1305. <Spacer y={1} />
  1306. </>,
  1307. ].filter((x) => x)}
  1308. />
  1309. </>
  1310. );
  1311. }
  1312. // If settings, update full form
  1313. if (props.clusterId && props.gpuModal) {
  1314. return (
  1315. <GPUProvisionSettings
  1316. handleClusterStateChange={handleClusterStateChange}
  1317. clusterState={clusterState}
  1318. preflightChecks={preflightChecks}
  1319. isReadOnly={isReadOnly}
  1320. isLoading={isLoading}
  1321. createCluster={createCluster}
  1322. preflightData={preflightData}
  1323. preflightFailed={preflightFailed}
  1324. preflightError={preflightError}
  1325. proceedToProvision={proceedToProvision}
  1326. getStatus={getStatus}
  1327. dismissPreflight={dismissPreflight}
  1328. showHelpMessage={showHelpMessage}
  1329. showEmailMessage={showEmailMessage}
  1330. requestQuotasAndProvision={requestQuotaIncrease}
  1331. />
  1332. );
  1333. }
  1334. return (
  1335. <>
  1336. <StyledForm>
  1337. <Heading isAtTop>EKS configuration</Heading>
  1338. <SelectRow
  1339. options={regionOptions}
  1340. width="350px"
  1341. disabled={isReadOnly || true}
  1342. value={clusterState.awsRegion}
  1343. scrollBuffer={true}
  1344. dropdownMaxHeight="240px"
  1345. setActiveValue={(x: string) => {
  1346. handleClusterStateChange("awsRegion", x);
  1347. }}
  1348. label="📍 AWS region"
  1349. />
  1350. {renderAdvancedSettings()}
  1351. </StyledForm>
  1352. <Button
  1353. // disabled={isDisabled()}
  1354. disabled={isDisabled() ?? isLoading}
  1355. onClick={createCluster}
  1356. status={getStatus()}
  1357. >
  1358. Provision
  1359. </Button>
  1360. </>
  1361. );
  1362. };
  1363. return (
  1364. <>
  1365. {renderForm()}
  1366. {user.isPorterUser && (
  1367. <>
  1368. <Spacer y={1} />
  1369. <Text color="yellow">Visible to Admin Only</Text>
  1370. <Button color="red" onClick={createCluster} status={getStatus()}>
  1371. Override Provision
  1372. </Button>
  1373. </>
  1374. )}
  1375. </>
  1376. );
  1377. };
  1378. export default withRouter(ProvisionerSettings);
  1379. const ExpandHeader = styled.div<{ isExpanded: boolean }>`
  1380. display: flex;
  1381. align-items: center;
  1382. cursor: pointer;
  1383. > i {
  1384. margin - right: 7px;
  1385. margin-left: -7px;
  1386. transform: ${(props) =>
  1387. props.isExpanded ? "rotate(0deg)" : "rotate(-90deg)"};
  1388. transition: transform 0.1s ease;
  1389. }
  1390. `;
  1391. const StyledForm = styled.div`
  1392. position: relative;
  1393. padding: 30px 30px 25px;
  1394. border-radius: 5px;
  1395. background: ${({ theme }) => theme.fg};
  1396. border: 1px solid #494b4f;
  1397. font-size: 13px;
  1398. margin-bottom: 30px;
  1399. `;
  1400. const FlexCenter = styled.div`
  1401. display: flex;
  1402. align-items: center;
  1403. gap: 3px;
  1404. `;
  1405. const Wrapper = styled.div`
  1406. transform: translateY(+13px);
  1407. `;
  1408. const ErrorInLine = styled.div`
  1409. display: flex;
  1410. align-items: center;
  1411. font-size: 13px;
  1412. color: #ff3b62;
  1413. margin-top: 10px;
  1414. > i {
  1415. font - size: 18px;
  1416. margin-right: 5px;
  1417. }
  1418. `;
  1419. const CheckItemContainer = styled.div`
  1420. display: flex;
  1421. flex-direction: column;
  1422. border: 1px solid ${(props) => props.theme.border};
  1423. border-radius: 5px;
  1424. font-size: 13px;
  1425. width: 100%;
  1426. margin-bottom: 10px;
  1427. padding-left: 10px;
  1428. cursor: ${(props) => (props.hasMessage ? "pointer" : "default")};
  1429. background: ${(props) => props.theme.clickable.bg};
  1430. `;
  1431. const CheckItemTop = styled.div`
  1432. display: flex;
  1433. align-items: center;
  1434. padding: 10px;
  1435. background: ${(props) => props.theme.clickable.bg};
  1436. `;
  1437. const StatusIcon = styled.img`
  1438. height: 14px;
  1439. `;