Ver código fonte

fix database status edge case

Alexander Belanger 4 anos atrás
pai
commit
fb6ca22af8

+ 8 - 8
api/server/handlers/infra/create.go

@@ -92,14 +92,6 @@ func (c *InfraCreateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	// handle write to the database
-	infra, err = c.Repo().Infra().CreateInfra(infra)
-
-	if err != nil {
-		c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
-		return
-	}
-
 	// call apply on the provisioner service
 	vals := req.Values
 
@@ -119,6 +111,14 @@ func (c *InfraCreateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 		}
 	}
 
+	// handle write to the database
+	infra, err = c.Repo().Infra().CreateInfra(infra)
+
+	if err != nil {
+		c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
+		return
+	}
+
 	resp, err := c.Config().ProvisionerClient.Apply(context.Background(), proj.ID, infra.ID, &ptypes.ApplyBaseRequest{
 		Kind:          req.Kind,
 		Values:        vals,

+ 5 - 0
api/server/handlers/infra/get.go

@@ -1,6 +1,7 @@
 package infra
 
 import (
+	"fmt"
 	"net/http"
 
 	"github.com/porter-dev/porter/api/server/handlers"
@@ -41,6 +42,10 @@ func (c *InfraGetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 		} else {
 			res.LatestOperation = op
 		}
+	} else {
+		// if the operation does not exist, throw an error as this infra is in an invalid state
+		c.HandleAPIError(w, r, apierrors.NewErrInternal(fmt.Errorf("latest operation not found")))
+		return
 	}
 
 	c.WriteResult(w, r, res)

+ 1 - 1
api/types/database.go

@@ -23,5 +23,5 @@ type Database struct {
 type ListDatabaseResponse []*Database
 
 type UpdateDatabaseStatusRequest struct {
-	Status string `json:"status" form:"required,oneof=deleting creating"`
+	Status string `json:"status" form:"required,oneof=destroying updating"`
 }

+ 1 - 1
dashboard/src/main/home/cluster-dashboard/databases/DatabasesList.tsx

@@ -79,7 +79,7 @@ const DatabasesList = () => {
       await api.updateDatabaseStatus(
         "<token>",
         {
-          status: "deleting",
+          status: "destroying",
         },
         {
           project_id,

+ 10 - 0
dashboard/src/shared/common.tsx

@@ -68,6 +68,16 @@ export const integrationList: any = {
       "https://avatars2.githubusercontent.com/u/52505464?s=400&u=da920f994c67665c7ad6c606a5286557d4f8555f&v=4",
     label: "Elastic Container Registry (ECR)",
   },
+  doks: {
+    icon:
+      "https://cdn4.iconfinder.com/data/icons/logos-and-brands/512/97_Docker_logo_logos-512.png",
+    label: "Digital Ocean Kubernetes Service (DOKS)",
+  },
+  docr: {
+    icon:
+      "https://cdn4.iconfinder.com/data/icons/logos-and-brands/512/97_Docker_logo_logos-512.png",
+    label: "Digital Ocean Container Registry (DOCR)",
+  },
   aws: {
     icon: aws,
     label: "AWS",

+ 1 - 1
provisioner/client/get_raw_state.go

@@ -16,7 +16,7 @@ func (c *Client) GetRawState(
 
 	err := c.getRequest(
 		fmt.Sprintf(
-			"/%s/tfstate",
+			"/%s/tfstate/raw",
 			workspaceID,
 		),
 		nil,

+ 1 - 0
provisioner/server/handlers/state/create_resource.go

@@ -136,6 +136,7 @@ func createRDSDatabase(config *config.Config, infra *models.Infra, operation *mo
 		InstanceID:       output["rds_instance_id"].(string),
 		InstanceEndpoint: output["rds_connection_endpoint"].(string),
 		InstanceName:     output["rds_instance_name"].(string),
+		Status:           "Running",
 	}
 
 	database, err := config.Repo.Database().CreateDatabase(database)

+ 4 - 0
provisioner/server/router/router.go

@@ -50,6 +50,10 @@ func NewAPIRouter(config *config.Config) *chi.Mux {
 				r.Use(staticTokenAuth.NewAuthenticated)
 				r.Use(workspaceAuth.Middleware)
 
+				// Note that this handler is also used in the above group. The /tfstate/raw endpoint is meant to
+				// be used from the API server, while the /tfstate endpoint is meant to be called as a Terraform
+				// HTTP backend.
+				r.Method("GET", "/{workspace_id}/tfstate/raw", state.NewRawStateGetHandler(config))
 				r.Method("GET", "/{workspace_id}/logs", state.NewLogsGetHandler(config))
 			})
 		})