Selaa lähdekoodia

Merge branch 'nico/new-onboarding-flow' of github.com:porter-dev/porter into nico/new-onboarding-flow

jnfrati 4 vuotta sitten
vanhempi
sitoutus
3435742501

+ 3 - 0
api/server/handlers/project/update_onboarding.go

@@ -56,8 +56,11 @@ func (p *OnboardingUpdateHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque
 	onboarding.SkipRegistryConnection = request.SkipRegistryConnection
 	onboarding.SkipResourceProvision = request.SkipResourceProvision
 	onboarding.RegistryConnectionID = request.RegistryConnectionID
+	onboarding.RegistryConnectionCredentialID = request.RegistryConnectionCredentialID
 	onboarding.RegistryInfraID = request.RegistryInfraID
+	onboarding.RegistryInfraCredentialID = request.RegistryInfraCredentialID
 	onboarding.ClusterInfraID = request.ClusterInfraID
+	onboarding.ClusterInfraCredentialID = request.ClusterInfraCredentialID
 
 	if isNotFound {
 		// if not found, create onboarding struct

+ 15 - 0
api/types/infra.go

@@ -37,4 +37,19 @@ type Infra struct {
 
 	// Status is the status of the infra
 	Status InfraStatus `json:"status"`
+
+	// The AWS integration that was used to create the infra
+	AWSIntegrationID uint
+
+	// The GCP integration that was used to create the infra
+	GCPIntegrationID uint
+
+	// The DO integration that was used to create the infra:
+	// this points to an OAuthIntegrationID
+	DOIntegrationID uint
+
+	// The last-applied, non-sensitive input variables to the provisioner. For now,
+	// this is a map[string]string since we marshal into env vars anyway, but
+	// eventually this config will be more complex.
+	LastApplied map[string]string
 }

+ 10 - 7
api/types/project.go

@@ -85,13 +85,16 @@ const (
 )
 
 type OnboardingData struct {
-	CurrentStep            StepEnum            `json:"current_step"`
-	ConnectedSource        ConnectedSourceType `json:"connected_source"`
-	SkipRegistryConnection bool                `json:"skip_registry_connection"`
-	SkipResourceProvision  bool                `json:"skip_resource_provision"`
-	RegistryConnectionID   uint                `json:"registry_connection_id"`
-	RegistryInfraID        uint                `json:"registry_infra_id"`
-	ClusterInfraID         uint                `json:"cluster_infra_id"`
+	CurrentStep                    StepEnum            `json:"current_step"`
+	ConnectedSource                ConnectedSourceType `json:"connected_source"`
+	SkipRegistryConnection         bool                `json:"skip_registry_connection"`
+	SkipResourceProvision          bool                `json:"skip_resource_provision"`
+	RegistryConnectionID           uint                `json:"registry_connection_id"`
+	RegistryConnectionCredentialID uint                `json:"registry_connection_credential_id"`
+	RegistryInfraID                uint                `json:"registry_infra_id"`
+	RegistryInfraCredentialID      uint                `json:"registry_infra_credential_id"`
+	ClusterInfraID                 uint                `json:"cluster_infra_id"`
+	ClusterInfraCredentialID       uint                `json:"cluster_infra_credential_id"`
 }
 
 type UpdateOnboardingRequest OnboardingData

+ 1 - 0
internal/kubernetes/provisioner/input/eks.go

@@ -9,6 +9,7 @@ type EKS struct {
 	AWSAccessKey string `json:"aws_access_key"`
 	AWSSecretKey string `json:"aws_secret_key"`
 	ClusterName  string `json:"cluster_name"`
+	MachineType  string `json:"machine_type"`
 }
 
 func (eks *EKS) GetInput() ([]byte, error) {

+ 1 - 0
internal/kubernetes/provisioner/provisioner.go

@@ -150,6 +150,7 @@ func (conf *Conf) GetProvisionerJobTemplate() (*batchv1.Job, error) {
 				AWSAccessKey: conf.AWS.AWSAccessKeyID,
 				AWSSecretKey: conf.AWS.AWSSecretAccessKey,
 				ClusterName:  conf.EKS.ClusterName,
+				MachineType:  conf.EKS.MachineType,
 			}
 
 			lastApplied, err := inputConf.GetInput()

+ 87 - 4
internal/models/infra.go

@@ -1,6 +1,7 @@
 package models
 
 import (
+	"encoding/json"
 	"fmt"
 	"strconv"
 	"strings"
@@ -8,6 +9,7 @@ import (
 	"gorm.io/gorm"
 
 	"github.com/porter-dev/porter/api/types"
+	"github.com/porter-dev/porter/internal/kubernetes/provisioner/input"
 )
 
 // Infra represents the metadata for an infrastructure type provisioned on
@@ -51,13 +53,94 @@ type Infra struct {
 // ToInfraType generates an external Infra to be shared over REST
 func (i *Infra) ToInfraType() *types.Infra {
 	return &types.Infra{
-		ID:        i.ID,
-		ProjectID: i.ProjectID,
-		Kind:      i.Kind,
-		Status:    i.Status,
+		ID:               i.ID,
+		ProjectID:        i.ProjectID,
+		Kind:             i.Kind,
+		Status:           i.Status,
+		AWSIntegrationID: i.AWSIntegrationID,
+		DOIntegrationID:  i.DOIntegrationID,
+		GCPIntegrationID: i.GCPIntegrationID,
+		LastApplied:      i.SafelyGetLastApplied(),
 	}
 }
 
+// SafeGetLastApplied gets non-sensitive values for the last applied configuration
+func (i *Infra) SafelyGetLastApplied() map[string]string {
+	resp := make(map[string]string)
+
+	switch i.Kind {
+	case types.InfraECR:
+		lastApplied := &input.ECR{}
+
+		if err := json.Unmarshal(i.LastApplied, lastApplied); err != nil {
+			return resp
+		}
+
+		resp["region"] = lastApplied.AWSRegion
+
+		return resp
+	case types.InfraEKS:
+		lastApplied := &input.EKS{}
+
+		if err := json.Unmarshal(i.LastApplied, lastApplied); err != nil {
+			return resp
+		}
+
+		resp["region"] = lastApplied.AWSRegion
+		resp["cluster_name"] = lastApplied.ClusterName
+		resp["machine_type"] = lastApplied.MachineType
+
+		return resp
+	case types.InfraGCR:
+		lastApplied := &input.GCR{}
+
+		if err := json.Unmarshal(i.LastApplied, lastApplied); err != nil {
+			return resp
+		}
+
+		resp["project_id"] = lastApplied.GCPProjectID
+		resp["region"] = lastApplied.GCPRegion
+
+		return resp
+	case types.InfraGKE:
+		lastApplied := &input.GKE{}
+
+		if err := json.Unmarshal(i.LastApplied, lastApplied); err != nil {
+			return resp
+		}
+
+		resp["project_id"] = lastApplied.GCPProjectID
+		resp["region"] = lastApplied.GCPRegion
+		resp["cluster_name"] = lastApplied.ClusterName
+
+		return resp
+	case types.InfraDOCR:
+		lastApplied := &input.DOCR{}
+
+		if err := json.Unmarshal(i.LastApplied, lastApplied); err != nil {
+			return resp
+		}
+
+		resp["name"] = lastApplied.DOCRName
+		resp["subscription_tier"] = lastApplied.DOCRSubscriptionTier
+
+		return resp
+	case types.InfraDOKS:
+		lastApplied := &input.DOKS{}
+
+		if err := json.Unmarshal(i.LastApplied, lastApplied); err != nil {
+			return resp
+		}
+
+		resp["cluster_name"] = lastApplied.ClusterName
+		resp["region"] = lastApplied.DORegion
+
+		return resp
+	}
+
+	return resp
+}
+
 // GetID returns the unique id for this infra
 func (i *Infra) GetUniqueName() string {
 	return fmt.Sprintf("%s-%d-%d-%s", i.Kind, i.ProjectID, i.ID, i.Suffix)

+ 21 - 15
internal/models/onboarding.go

@@ -9,25 +9,31 @@ import (
 type Onboarding struct {
 	gorm.Model
 
-	ProjectID              uint
-	CurrentStep            types.StepEnum
-	ConnectedSource        types.ConnectedSourceType
-	SkipRegistryConnection bool
-	SkipResourceProvision  bool
-	RegistryConnectionID   uint
-	RegistryInfraID        uint
-	ClusterInfraID         uint
+	ProjectID                      uint
+	CurrentStep                    types.StepEnum
+	ConnectedSource                types.ConnectedSourceType
+	SkipRegistryConnection         bool
+	SkipResourceProvision          bool
+	RegistryConnectionID           uint
+	RegistryConnectionCredentialID uint
+	RegistryInfraID                uint
+	RegistryInfraCredentialID      uint
+	ClusterInfraID                 uint
+	ClusterInfraCredentialID       uint
 }
 
 // ToOnboardingType generates an external types.OnboardingData to be shared over REST
 func (o *Onboarding) ToOnboardingType() *types.OnboardingData {
 	return &types.OnboardingData{
-		CurrentStep:            o.CurrentStep,
-		ConnectedSource:        o.ConnectedSource,
-		SkipRegistryConnection: o.SkipRegistryConnection,
-		SkipResourceProvision:  o.SkipResourceProvision,
-		RegistryConnectionID:   o.RegistryConnectionID,
-		RegistryInfraID:        o.RegistryInfraID,
-		ClusterInfraID:         o.ClusterInfraID,
+		CurrentStep:                    o.CurrentStep,
+		ConnectedSource:                o.ConnectedSource,
+		SkipRegistryConnection:         o.SkipRegistryConnection,
+		SkipResourceProvision:          o.SkipResourceProvision,
+		RegistryConnectionID:           o.RegistryConnectionID,
+		RegistryConnectionCredentialID: o.RegistryConnectionCredentialID,
+		RegistryInfraID:                o.RegistryInfraID,
+		RegistryInfraCredentialID:      o.RegistryInfraCredentialID,
+		ClusterInfraID:                 o.ClusterInfraID,
+		ClusterInfraCredentialID:       o.ClusterInfraCredentialID,
 	}
 }