|
|
@@ -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 == "" {
|