Ver código fonte

add helm release revision number in create/update porter app response (#3333)

Feroze Mohideen 2 anos atrás
pai
commit
acdd4234fb

+ 4 - 4
api/server/handlers/porter_app/create.go

@@ -244,7 +244,7 @@ func (c *CreatePorterAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
 		}
 
 		// create the app chart
-		_, err = helmAgent.InstallChart(ctx, conf, c.Config().DOConf, c.Config().ServerConf.DisablePullSecretsInjection)
+		release, err := helmAgent.InstallChart(ctx, conf, c.Config().DOConf, c.Config().ServerConf.DisablePullSecretsInjection)
 		if err != nil {
 			err = telemetry.Error(ctx, span, err, "error installing app chart")
 			c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest))
@@ -305,7 +305,7 @@ func (c *CreatePorterAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
 			return
 		}
 
-		c.WriteResult(w, r, porterApp.ToPorterAppType())
+		c.WriteResult(w, r, porterApp.ToPorterAppTypeWithRevision(release.Version))
 	} else {
 		telemetry.WithAttributes(span, telemetry.AttributeKV{Key: "upgrading-application", Value: true})
 
@@ -400,7 +400,7 @@ func (c *CreatePorterAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
 		}
 
 		// update the chart
-		_, err = helmAgent.UpgradeInstallChart(ctx, conf, c.Config().DOConf, c.Config().ServerConf.DisablePullSecretsInjection)
+		release, err := helmAgent.UpgradeInstallChart(ctx, conf, c.Config().DOConf, c.Config().ServerConf.DisablePullSecretsInjection)
 		if err != nil {
 			err = telemetry.Error(ctx, span, err, "error upgrading application")
 			telemetry.WithAttributes(span, telemetry.AttributeKV{Key: "porter-yaml-base64", Value: porterYamlBase64})
@@ -489,7 +489,7 @@ func (c *CreatePorterAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
 			return
 		}
 
-		c.WriteResult(w, r, updatedPorterApp.ToPorterAppType())
+		c.WriteResult(w, r, updatedPorterApp.ToPorterAppTypeWithRevision(release.Version))
 	}
 }
 

+ 36 - 14
api/server/handlers/porter_app/parse.go

@@ -15,6 +15,7 @@ import (
 	"github.com/porter-dev/porter/internal/kubernetes/environment_groups"
 	"github.com/porter-dev/porter/internal/kubernetes/porter_app"
 	"github.com/porter-dev/porter/internal/repository"
+	"github.com/porter-dev/porter/internal/telemetry"
 	"github.com/porter-dev/porter/internal/templater/utils"
 	"github.com/stefanmcshane/helm/pkg/chart"
 
@@ -110,18 +111,23 @@ type ParseConf struct {
 }
 
 func parse(ctx context.Context, conf ParseConf) (*chart.Chart, map[string]interface{}, map[string]interface{}, error) {
+	ctx, span := telemetry.NewSpan(ctx, "parse-porter-yaml")
+	defer span.End()
+
 	parsed := &PorterStackYAML{}
 
 	if conf.FullHelmValues != "" {
 		parsedHelmValues, err := convertHelmValuesToPorterYaml(conf.FullHelmValues)
 		if err != nil {
-			return nil, nil, nil, fmt.Errorf("%s: %w", "error parsing raw helm values", err)
+			err = telemetry.Error(ctx, span, err, "error parsing raw helm values")
+			return nil, nil, nil, err
 		}
 		parsed = parsedHelmValues
 	} else {
 		err := yaml.Unmarshal(conf.PorterYaml, parsed)
 		if err != nil {
-			return nil, nil, nil, fmt.Errorf("%s: %w", "error parsing porter.yaml", err)
+			err = telemetry.Error(ctx, span, err, "error parsing porter.yaml")
+			return nil, nil, nil, err
 		}
 	}
 
@@ -130,16 +136,19 @@ func parse(ctx context.Context, conf ParseConf) (*chart.Chart, map[string]interf
 	for i := range conf.EnvGroups {
 		cm, _, err := conf.SubdomainCreateOpts.k8sAgent.GetLatestVersionedConfigMap(conf.EnvGroups[i], conf.Namespace)
 		if err != nil {
-			return nil, nil, nil, fmt.Errorf("%s: %w", "error building values from porter.yaml", err)
+			err = telemetry.Error(ctx, span, err, "error getting latest versioned config map")
+			return nil, nil, nil, err
 		}
 
 		versionStr, ok := cm.ObjectMeta.Labels["version"]
 		if !ok {
-			return nil, nil, nil, fmt.Errorf("error extracting version from config map")
+			err = telemetry.Error(ctx, span, nil, "error extracting version from config map")
+			return nil, nil, nil, err
 		}
 		versionInt, err := strconv.Atoi(versionStr)
 		if err != nil {
-			return nil, nil, nil, fmt.Errorf("error converting version to int: %w", err)
+			err = telemetry.Error(ctx, span, err, "error converting version to int")
+			return nil, nil, nil, err
 		}
 
 		version := uint(versionInt)
@@ -163,7 +172,8 @@ func parse(ctx context.Context, conf ParseConf) (*chart.Chart, map[string]interf
 	}
 
 	if parsed.Apps != nil && parsed.Services != nil {
-		return nil, nil, nil, fmt.Errorf("'apps' and 'services' are synonymous but both were defined")
+		err := telemetry.Error(ctx, span, nil, "'apps' and 'services' are synonymous but both were defined")
+		return nil, nil, nil, err
 	}
 
 	var services map[string]*Service
@@ -188,13 +198,19 @@ func parse(ctx context.Context, conf ParseConf) (*chart.Chart, map[string]interf
 
 	values, err := buildUmbrellaChartValues(ctx, application, synced_env, conf.ImageInfo, conf.ExistingHelmValues, conf.SubdomainCreateOpts, conf.InjectLauncherToStartCommand, conf.ShouldValidateHelmValues, conf.UserUpdate, conf.Namespace, conf.AddCustomNodeSelector)
 	if err != nil {
-		return nil, nil, nil, fmt.Errorf("%s: %w", "error building values", err)
+		err = telemetry.Error(ctx, span, err, "error building values")
+		return nil, nil, nil, err
+	}
+	convertedValues, ok := convertMap(values).(map[string]interface{})
+	if !ok {
+		err = telemetry.Error(ctx, span, nil, "error converting values")
+		return nil, nil, nil, err
 	}
-	convertedValues := convertMap(values).(map[string]interface{})
 
 	umbrellaChart, err := buildUmbrellaChart(application, conf.ServerConfig, conf.ProjectID, conf.ExistingChartDependencies)
 	if err != nil {
-		return nil, nil, nil, fmt.Errorf("%s: %w", "error building chart", err)
+		err = telemetry.Error(ctx, span, err, "error building umbrella chart")
+		return nil, nil, nil, err
 	}
 
 	// return the parsed release values for the release job chart, if they exist
@@ -605,6 +621,12 @@ func convertMap(m interface{}) interface{} {
 		for k, v := range m {
 			m[k] = convertMap(v)
 		}
+	case map[string]string:
+		result := map[string]interface{}{}
+		for k, v := range m {
+			result[k] = v
+		}
+		return result
 	case map[interface{}]interface{}:
 		result := map[string]interface{}{}
 		for k, v := range m {
@@ -894,16 +916,16 @@ func addLabelsToService(service *Service, envGroups []string, defaultLabelKey st
 	}
 
 	switch service.Config["labels"].(type) {
-	case map[string]any:
-		service.Config["labels"].(map[string]any)[defaultLabelKey] = porter_app.LabelValue_PorterApplication
-		if len(envGroups) != 0 {
-			service.Config["labels"].(map[string]any)[environment_groups.LabelKey_LinkedEnvironmentGroup] = strings.Join(envGroups, ".")
-		}
 	case map[string]string:
 		service.Config["labels"].(map[string]string)[defaultLabelKey] = porter_app.LabelValue_PorterApplication
 		if len(envGroups) != 0 {
 			service.Config["labels"].(map[string]string)[environment_groups.LabelKey_LinkedEnvironmentGroup] = strings.Join(envGroups, ".")
 		}
+	case map[string]any:
+		service.Config["labels"].(map[string]any)[defaultLabelKey] = porter_app.LabelValue_PorterApplication
+		if len(envGroups) != 0 {
+			service.Config["labels"].(map[string]any)[environment_groups.LabelKey_LinkedEnvironmentGroup] = strings.Join(envGroups, ".")
+		}
 	case any:
 		if val, ok := service.Config["labels"].(string); ok {
 			if val == "" {

+ 3 - 0
api/types/porter_app.go

@@ -28,6 +28,9 @@ type PorterApp struct {
 	// Porter YAML
 	PorterYAMLBase64 string `json:"porter_yaml,omitempty"`
 	PorterYamlPath   string `json:"porter_yaml_path,omitempty"`
+
+	// Helm
+	HelmRevisionNumber int `json:"helm_revision_number,omitempty"`
 }
 
 // swagger:model

+ 2 - 2
dashboard/src/main/auth/Register.tsx

@@ -48,11 +48,11 @@ const Register: React.FC<Props> = ({
   const [windowDimensions, setWindowDimensions] = useState(getWindowDimensions());
   const [buttonDisabled, setButtonDisabled] = useState(false);
 
-  const [chosenReferralOption, setChosenReferralOption] = useState<string>("");
+  const [chosenReferralOption, setChosenReferralOption] = useState<string>("(None provided)");
   const [referralOtherText, setReferralOtherText] = useState<string>("");
 
   const referralOptions = [
-    { value: "", label: "Please select an option:" },
+    { value: "(None provided)", label: "Please select an option:" },
     { value: "Email", label: "Email" },
     { value: "Word of mouth", label: "Word of mouth (friend, colleague, etc.)" },
     { value: "YC", label: "YC" },

+ 23 - 0
internal/models/porter_app.go

@@ -51,3 +51,26 @@ func (a *PorterApp) ToPorterAppType() *types.PorterApp {
 		PorterYamlPath: a.PorterYamlPath,
 	}
 }
+
+// ToPorterAppTypeWithRevision generates an external types.PorterApp with the latest helm revision number to be shared over REST
+// this is a bit hacky since it mixes db information with non-db information in the response
+// TODO: rethink this when we switch to versioned porter.yamls
+func (a *PorterApp) ToPorterAppTypeWithRevision(revision int) *types.PorterApp {
+	return &types.PorterApp{
+		ID:                 a.ID,
+		ProjectID:          a.ProjectID,
+		ClusterID:          a.ClusterID,
+		Name:               a.Name,
+		ImageRepoURI:       a.ImageRepoURI,
+		GitRepoID:          a.GitRepoID,
+		RepoName:           a.RepoName,
+		GitBranch:          a.GitBranch,
+		BuildContext:       a.BuildContext,
+		Builder:            a.Builder,
+		Buildpacks:         a.Buildpacks,
+		Dockerfile:         a.Dockerfile,
+		PullRequestURL:     a.PullRequestURL,
+		PorterYamlPath:     a.PorterYamlPath,
+		HelmRevisionNumber: revision,
+	}
+}