ソースを参照

provisioner with contract

Justin Rhee 3 年 前
コミット
53f4593a8b

+ 1 - 1
dashboard/package-lock.json

@@ -1440,7 +1440,7 @@
     },
     "@porter-dev/api-contracts": {
       "version": "https://gitpkg.now.sh/porter-dev/api-contracts/generated/js?main",
-      "integrity": "sha512-6xoMMbr0AJWpppaUC3Rk5AyJIoScIoNlJ6Bpy15eFcJFjE1aWEmEytl1tJQfi2mzd5f4PMSBIudq3jOUZAcy0w=="
+      "integrity": "sha512-RkY5K0EPjrxvhJghfbuhoVarImbnU2Sg/VjKh3xM/bgaMAtQxjPZHp3WxJwZqyK3CRKz0uM+5301y78WzZcAeQ=="
     },
     "@sentry/browser": {
       "version": "6.15.0",

+ 44 - 31
dashboard/src/components/ProvisionerSettings.tsx

@@ -2,7 +2,6 @@ import React, { useEffect, useState, useContext } from "react";
 import styled from "styled-components";
 
 import api from "shared/api";
-import aws from "assets/aws.png";
 
 import { Context } from "shared/Context";
 
@@ -10,6 +9,7 @@ import SelectRow from "components/form-components/SelectRow";
 import Heading from "components/form-components/Heading";
 import InputRow from "./form-components/InputRow";
 import SaveButton from "./SaveButton";
+import { Contract, EnumKubernetesKind, EnumCloudProvider, NodeGroupType } from "@porter-dev/api-contracts";
 
 const regionOptions = [
   { value: "us-east-1", label: "US East (N. Virginia) us-east-1" },
@@ -61,44 +61,57 @@ const ProvisionerForm: React.FC<Props> = ({
   const [isReadOnly, setIsReadOnly] = useState(false);
 
   const createCluster = async () => {
-    var data: any = {
-      project_id: currentProject.id,
-      cloud_provider: "aws",
-      cloud_provider_credentials_id: String(credentialId),
-      cluster_settings: {
-        cluster_name: clusterName,
-        cluster_version: "v1.24.0",
-        cidr_range: cidrRange || "172.0.0.0/16",
-        region: awsRegion,
-        node_groups: [
-          {
-            instance_type: "t3.medium",
-            min_instances: 1,
-            max_instances: 5,
-            node_group_type: "SYSTEM"
-          },
-          {
-            instance_type: "t3.large",
-            min_instances: 1,
-            max_instances: 5,
-            node_group_type: "MONITORING"
-          },
-          {
-            instance_type: machineType,
-            min_instances: minInstances || 1,
-            max_instances: maxInstances || 10,
-            node_group_type: "APPLICATION"
+    var data: Contract = {
+      cluster: {
+        projectId: currentProject.id,
+        clusterId: null,
+        kind: EnumKubernetesKind.EKS,
+        cloudProvider: EnumCloudProvider.AWS,
+        cloudProviderCredentialsId: String(credentialId),
+        kindValues: {
+          case: "eksKind",
+          value: {
+            clusterName,
+            clusterVersion: "v1.24.0",
+            cidrRange: cidrRange || "172.0.0.0/16",
+            region: awsRegion,
+            nodeGroups: [
+              {
+                instanceType: "t3.medium",
+                minInstances: 1,
+                maxInstances: 5,
+                nodeGroupType: NodeGroupType.SYSTEM,
+                isStateful: false,
+                nameSuffix: "",
+              },
+              {
+                instanceType: "t3.large",
+                minInstances: 1,
+                maxInstances: 5,
+                nodeGroupType: NodeGroupType.MONITORING,
+                isStateful: false,
+                nameSuffix: "",
+              },
+              {
+                instanceType: machineType,
+                minInstances: minInstances || 1,
+                maxInstances: maxInstances || 10,
+                nodeGroupType: NodeGroupType.APPLICATION,
+                isStateful: false,
+                nameSuffix: "",
+              }
+            ]
           }
-        ]
+        },
       }
     };
 
     if (clusterId) {
-      data["cluster_id"] = clusterId;
+      data["cluster"]["clusterId"] = clusterId;
     }
 
     try {
-      await api.provisionCluster(
+      await api.createContract(
         "<token>",
         data,
         { project_id: currentProject.id }

+ 17 - 0
dashboard/src/shared/api.tsx

@@ -7,6 +7,7 @@ import {
   CreateStackBody,
   SourceConfig,
 } from "main/home/cluster-dashboard/stacks/types";
+import { Contract } from "@porter-dev/api-contracts";
 
 /**
  * Generic api call format
@@ -888,6 +889,20 @@ const provisionCluster = baseApi<
   return `/api/projects/${project_id}/provision/cluster`;
 });
 
+const createContract = baseApi<
+  Contract,
+  { project_id: number }
+>("POST", ({ project_id }) => {
+  return `/api/projects/${project_id}/contract`;
+});
+
+const getContracts = baseApi<
+  {},
+  { project_id: number }
+>("GET", ({ project_id }) => {
+  return `/api/projects/${project_id}/contracts`;
+});
+
 const provisionInfra = baseApi<
   {
     kind: string;
@@ -2545,6 +2560,8 @@ export default {
   listIncidents,
   getIncident,
   getIncidentEvents,
+  createContract,
+  getContracts,
   // STACKS
   listStacks,
   getStack,