Преглед изворни кода

Merge branch 'master' of github.com:porter-dev/porter into stacks-improved-debug-flow-pre-deploy

Feroze Mohideen пре 2 година
родитељ
комит
7e445e4bd5

+ 20 - 17
api/server/handlers/porter_app/parse.go

@@ -118,7 +118,7 @@ func buildUmbrellaChartValues(
 			}
 		}
 
-		validateErr := validateHelmValues(helm_values, shouldCreate)
+		validateErr := validateHelmValues(helm_values, shouldCreate, appType)
 		if validateErr != "" {
 			return nil, fmt.Errorf("error validating service \"%s\": %s", name, validateErr)
 		}
@@ -175,26 +175,29 @@ func buildUmbrellaChartValues(
 }
 
 // we can add to this function up later or use an alternative
-func validateHelmValues(values map[string]interface{}, shouldCreate bool) string {
+func validateHelmValues(values map[string]interface{}, shouldCreate bool, appType string) string {
 	// currently, we only validate port on initial app create, because this will break any updates to existing apps with lower port numbers
 	if shouldCreate {
-		containerMap, err := getNestedMap(values, "container")
-		if err != nil {
-			return "error checking port: misformatted values"
-		} else {
-			portVal, portExists := containerMap["port"]
-			if portExists {
-				portStr, pOK := portVal.(string)
-				if !pOK {
-					return "error checking port: no port in container"
-				}
+		// validate port for web services
+		if appType == "web" {
+			containerMap, err := getNestedMap(values, "container")
+			if err != nil {
+				return "error checking port: misformatted values"
+			} else {
+				portVal, portExists := containerMap["port"]
+				if portExists {
+					portStr, pOK := portVal.(string)
+					if !pOK {
+						return "error checking port: no port in container"
+					}
 
-				port, err := strconv.Atoi(portStr)
-				if err != nil || port < 1024 || port > 65535 {
-					return "port must be a number between 1024 and 65535"
+					port, err := strconv.Atoi(portStr)
+					if err != nil || port < 1024 || port > 65535 {
+						return "port must be a number between 1024 and 65535"
+					}
+				} else {
+					return "port must be specified for web services"
 				}
-			} else {
-				return "must specify port if choosing to expose service externally"
 			}
 		}
 	}

+ 17 - 56
cli/cmd/app.go

@@ -2,7 +2,6 @@ package cmd
 
 import (
 	"context"
-	"encoding/json"
 	"errors"
 	"fmt"
 	"io"
@@ -24,7 +23,6 @@ import (
 	"k8s.io/apimachinery/pkg/watch"
 	"k8s.io/kubectl/pkg/util/term"
 
-	templaterUtils "github.com/porter-dev/porter/internal/templater/utils"
 	"k8s.io/apimachinery/pkg/runtime"
 	"k8s.io/apimachinery/pkg/runtime/schema"
 	"k8s.io/client-go/kubernetes"
@@ -1049,71 +1047,34 @@ func appUpdateTag(_ *types.GetAuthenticatedUserResponse, client *api.Client, arg
 	if err != nil {
 		return fmt.Errorf("Unable to find application %s", args[0])
 	}
-
-	// check for the post-deploy job associated with the release
-	postDeployReleaseName := fmt.Sprintf("%s-r", args[0])
-	postDeployRelease, postDeployReleaseErr := client.GetRelease(context.TODO(), cliConf.Project, cliConf.Cluster, namespace, postDeployReleaseName)
-
-	color.New(color.FgGreen).Printf("Updating application %s to build using tag \"%s\"\n", args[0], appTag)
-	overrideValues := map[string]interface{}{
-		"global": map[string]interface{}{
-			"image": map[string]interface{}{
-				"tag": appTag,
-			},
-		},
+	repository, ok := release.Config["global"].(map[string]interface{})["image"].(map[string]interface{})["repository"].(string)
+	if !ok || repository == "" {
+		return fmt.Errorf("Application %s does not have an associated image repository. Unable to update tag", args[0])
 	}
-	mergedValues := templaterUtils.CoalesceValues(release.Config, overrideValues)
-
-	bytes, err := json.Marshal(mergedValues)
-	if err != nil {
-		return fmt.Errorf("Unable to update application %s: %w", args[0], err)
+	imageInfo := types.ImageInfo{
+		Repository: repository,
+		Tag:        appTag,
 	}
-	err = client.UpgradeRelease(
-		context.Background(),
-		cliConf.Project,
-		cliConf.Cluster,
-		namespace,
-		args[0],
-		&types.UpgradeReleaseRequest{
-			Values:             string(bytes),
-			IgnoreDependencies: true,
-		},
-	)
-	if err != nil {
-		return fmt.Errorf("Unable to update application %s: %w", args[0], err)
+	createUpdatePorterAppRequest := &types.CreatePorterAppRequest{
+		ClusterID:       cliConf.Cluster,
+		ProjectID:       cliConf.Project,
+		ImageInfo:       imageInfo,
+		OverrideRelease: false,
 	}
 
-	color.New(color.FgGreen).Printf("Successfully updated application %s\n", args[0])
-
-	if postDeployReleaseErr != nil {
-		// didn't find a post-deploy job, so we're done
-		return nil
-	}
-	color.New(color.FgGreen).Printf("Post-deploy job for application %s found. Updating job to build using tag \"%s\" as well\n", args[0], appTag)
-	overrideValues = map[string]interface{}{
-		"image": map[string]interface{}{
-			"tag": appTag,
-		},
-	}
-	mergedValues = templaterUtils.CoalesceValues(postDeployRelease.Config, overrideValues)
+	color.New(color.FgGreen).Printf("Updating application %s to build using tag \"%s\"\n", args[0], appTag)
 
-	bytes, err = json.Marshal(mergedValues)
-	if err != nil {
-		return fmt.Errorf("Unable to update post-deploy job for application %s: %w", args[0], err)
-	}
-	err = client.UpgradeRelease(
+	_, err = client.CreatePorterApp(
 		context.Background(),
 		cliConf.Project,
 		cliConf.Cluster,
-		namespace,
-		postDeployReleaseName,
-		&types.UpgradeReleaseRequest{
-			Values: string(bytes),
-		},
+		args[0],
+		createUpdatePorterAppRequest,
 	)
 	if err != nil {
-		return fmt.Errorf("Unable to update post-deploy job for application %s: %w", args[0], err)
+		return fmt.Errorf("Unable to update application %s: %w", args[0], err)
 	}
 
+	color.New(color.FgGreen).Printf("Successfully updated application %s to use tag \"%s\"\n", args[0], appTag)
 	return nil
 }

+ 9 - 0
dashboard/src/components/ProvisionerSettings.tsx

@@ -67,6 +67,15 @@ const machineTypeOptions = [
   { value: "t3.large", label: "t3.large" },
   { value: "t3.xlarge", label: "t3.xlarge" },
   { value: "t3.2xlarge", label: "t3.2xlarge" },
+  { value: "t3a.medium", label: "t3a.medium" },
+  { value: "t3a.large", label: "t3a.large" },
+  { value: "t3a.xlarge", label: "t3a.xlarge" },
+  { value: "t3a.2xlarge", label: "t3a.2xlarge" },
+  { value: "c6i.large", label: "c6i.large" },
+  { value: "c6i.xlarge", label: "c6i.xlarge" },
+  { value: "c6i.2xlarge", label: "c6i.2xlarge" },
+  { value: "c6i.4xlarge", label: "c6i.4xlarge" },
+  { value: "c6i.8xlarge", label: "c6i.8xlarge" },
   { value: "g4dn.xlarge", label: "g4dn.xlarge" },
 ];
 

+ 1 - 1
internal/kubernetes/prometheus/metrics.go

@@ -139,7 +139,7 @@ func QueryPrometheus(
 	} else if opts.Metric == "memory" {
 		query = fmt.Sprintf("container_memory_usage_bytes{%s}", podSelector)
 	} else if opts.Metric == "network" {
-		netPodSelector := fmt.Sprintf(`namespace="%s",pod=~"%s",container="POD"`, opts.Namespace, selectionRegex)
+		netPodSelector := fmt.Sprintf(`namespace="%s",pod=~"%s"`, opts.Namespace, selectionRegex)
 		query = fmt.Sprintf("rate(container_network_receive_bytes_total{%s}[5m])", netPodSelector)
 	} else if opts.Metric == "nginx:errors" {
 		num := fmt.Sprintf(`sum(rate(nginx_ingress_controller_requests{status=~"5.*",exported_namespace="%s",ingress=~"%s"}[5m]) OR on() vector(0))`, opts.Namespace, selectionRegex)