Sfoglia il codice sorgente

Merge pull request #475 from porter-dev/eks-machine-type

Support different EKS machine types
abelanger5 5 anni fa
parent
commit
7868d3b4ec

+ 22 - 2
dashboard/src/main/home/provisioner/AWSFormSection.tsx

@@ -25,6 +25,7 @@ type PropsType = RouteComponentProps & {
 
 type StateType = {
   awsRegion: string;
+  awsMachineType: string;
   awsAccessId: string;
   awsSecretKey: string;
   selectedInfras: { value: string; label: string }[];
@@ -60,10 +61,20 @@ const regionOptions = [
   { value: "sa-east-1", label: "South America (São Paulo) sa-east-1" },
 ];
 
+const machineTypeOptions = [
+  { value: "t2.medium", label: "t2.medium"},
+  { value: "t2.xlarge", label: "t2.xlarge"},
+  { value: "t2.2xlarge", label: "t2.2xlarge"},
+  { value: "t3.medium", label: "t3.medium"},
+  { value: "t3.xlarge", label: "t3.xlarge"},
+  { value: "t3.2xlarge", label: "t3.2xlarge"},
+]
+
 // TODO: Consolidate across forms w/ HOC
 class AWSFormSection extends Component<PropsType, StateType> {
   state = {
     awsRegion: "us-east-1",
+    awsMachineType: "t2.medium",
     awsAccessId: "",
     awsSecretKey: "",
     selectedInfras: [...provisionOptions],
@@ -178,7 +189,7 @@ class AWSFormSection extends Component<PropsType, StateType> {
 
   provisionEKS = () => {
     console.log("Provisioning EKS");
-    let { awsAccessId, awsSecretKey, awsRegion } = this.state;
+    let { awsAccessId, awsSecretKey, awsRegion, awsMachineType } = this.state;
     let { currentProject } = this.context;
 
     let clusterName = `${currentProject.name}-cluster`;
@@ -199,6 +210,7 @@ class AWSFormSection extends Component<PropsType, StateType> {
           {
             aws_integration_id: res.data.id,
             eks_name: clusterName,
+            machine_type: awsMachineType,
           },
           { id: currentProject.id }
         )
@@ -263,7 +275,7 @@ class AWSFormSection extends Component<PropsType, StateType> {
 
   render() {
     let { setSelectedProvisioner } = this.props;
-    let { awsRegion, awsAccessId, awsSecretKey, selectedInfras } = this.state;
+    let { awsRegion, awsMachineType, awsAccessId, awsSecretKey, selectedInfras } = this.state;
 
     return (
       <StyledAWSFormSection>
@@ -289,6 +301,14 @@ class AWSFormSection extends Component<PropsType, StateType> {
             setActiveValue={(x: string) => this.setState({ awsRegion: x })}
             label="📍 AWS Region"
           />
+          <SelectRow
+            options={machineTypeOptions}
+            width="100%"
+            value={awsMachineType}
+            dropdownMaxHeight="240px"
+            setActiveValue={(x: string) => this.setState({ awsMachineType: x })}
+            label="⚙️ AWS Machine Type"
+          />
           <InputRow
             type="text"
             value={awsAccessId}

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

@@ -642,6 +642,7 @@ const provisionEKS = baseApi<
   {
     eks_name: string;
     aws_integration_id: string;
+    machine_type: string;
   },
   { id: number }
 >("POST", (pathParams) => {

+ 1 - 0
internal/forms/infra.go

@@ -48,6 +48,7 @@ func (ce *CreateECRInfra) ToInfra() (*models.Infra, error) {
 // EKS infra via the provisioning container
 type CreateEKSInfra struct {
 	EKSName          string `json:"eks_name" form:"required"`
+	MachineType      string `json:"machine_type"`
 	ProjectID        uint   `json:"project_id" form:"required"`
 	AWSIntegrationID uint   `json:"aws_integration_id" form:"required"`
 }

+ 2 - 1
internal/kubernetes/agent.go

@@ -383,7 +383,7 @@ func (a *Agent) ProvisionECR(
 func (a *Agent) ProvisionEKS(
 	projectID uint,
 	awsConf *integrations.AWSIntegration,
-	eksName string,
+	eksName, machineType string,
 	repo repository.Repository,
 	infra *models.Infra,
 	operation provisioner.ProvisionerOperation,
@@ -408,6 +408,7 @@ func (a *Agent) ProvisionEKS(
 		},
 		EKS: &eks.Conf{
 			ClusterName: eksName,
+			MachineType: machineType,
 		},
 	}
 

+ 6 - 0
internal/kubernetes/provisioner/aws/eks/eks.go

@@ -5,6 +5,7 @@ import v1 "k8s.io/api/core/v1"
 // Conf is the EKS cluster config required for the provisioner
 type Conf struct {
 	ClusterName string
+	MachineType string
 }
 
 // AttachEKSEnv adds the relevant EKS env for the provisioner
@@ -14,5 +15,10 @@ func (conf *Conf) AttachEKSEnv(env []v1.EnvVar) []v1.EnvVar {
 		Value: conf.ClusterName,
 	})
 
+	env = append(env, v1.EnvVar{
+		Name:  "EKS_MACHINE_TYPE",
+		Value: conf.MachineType,
+	})
+
 	return env
 }

+ 2 - 0
server/api/provision_handler.go

@@ -389,6 +389,7 @@ func (app *App) HandleProvisionAWSEKSInfra(w http.ResponseWriter, r *http.Reques
 		uint(projID),
 		awsInt,
 		form.EKSName,
+		form.MachineType,
 		*app.Repo,
 		infra,
 		provisioner.Apply,
@@ -481,6 +482,7 @@ func (app *App) HandleDestroyAWSEKSInfra(w http.ResponseWriter, r *http.Request)
 		infra.ProjectID,
 		awsInt,
 		form.EKSName,
+		"",
 		*app.Repo,
 		infra,
 		provisioner.Destroy,