|
|
@@ -13,6 +13,7 @@ import (
|
|
|
"github.com/porter-dev/porter/internal/kubernetes"
|
|
|
"github.com/porter-dev/porter/internal/kubernetes/domain"
|
|
|
"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/templater/utils"
|
|
|
"github.com/stefanmcshane/helm/pkg/chart"
|
|
|
@@ -175,28 +176,7 @@ func parse(ctx context.Context, conf ParseConf) (*chart.Chart, map[string]interf
|
|
|
}
|
|
|
|
|
|
for serviceName := range services {
|
|
|
- if len(conf.EnvironmentGroups) != 0 {
|
|
|
- if _, ok := services[serviceName].Config["labels"]; !ok {
|
|
|
- services[serviceName].Config["labels"] = make(map[string]string)
|
|
|
- }
|
|
|
- if _, ok := services[serviceName].Config["labels"].(map[string]any); ok {
|
|
|
- delete(services[serviceName].Config["labels"].(map[string]any), environment_groups.LabelKey_LinkedEnvironmentGroup)
|
|
|
- }
|
|
|
- switch services[serviceName].Config["labels"].(type) {
|
|
|
- case map[string]any:
|
|
|
- services[serviceName].Config["labels"].(map[string]any)[environment_groups.LabelKey_LinkedEnvironmentGroup] = strings.Join(conf.EnvironmentGroups, ".")
|
|
|
- case map[string]string:
|
|
|
- services[serviceName].Config["labels"].(map[string]string)[environment_groups.LabelKey_LinkedEnvironmentGroup] = strings.Join(conf.EnvironmentGroups, ".")
|
|
|
- case any:
|
|
|
- if val, ok := services[serviceName].Config["labels"].(string); ok {
|
|
|
- if val == "" {
|
|
|
- services[serviceName].Config["labels"] = map[string]string{
|
|
|
- environment_groups.LabelKey_LinkedEnvironmentGroup: strings.Join(conf.EnvironmentGroups, "."),
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ services[serviceName] = addLabelsToService(services[serviceName], conf.EnvironmentGroups, porter_app.LabelKey_PorterApplication)
|
|
|
}
|
|
|
|
|
|
application := &Application{
|
|
|
@@ -206,8 +186,7 @@ func parse(ctx context.Context, conf ParseConf) (*chart.Chart, map[string]interf
|
|
|
Release: parsed.Release,
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- values, err := buildUmbrellaChartValues(ctx, application, synced_env, conf.ImageInfo, conf.ExistingHelmValues, conf.SubdomainCreateOpts, conf.InjectLauncherToStartCommand, conf.ShouldValidateHelmValues, conf.UserUpdate, conf.Namespace, conf.AddCustomNodeSelector)
|
|
|
+ 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)
|
|
|
}
|
|
|
@@ -221,6 +200,7 @@ func parse(ctx context.Context, conf ParseConf) (*chart.Chart, map[string]interf
|
|
|
// return the parsed release values for the release job chart, if they exist
|
|
|
var preDeployJobValues map[string]interface{}
|
|
|
if application.Release != nil && application.Release.Run != nil {
|
|
|
+ application.Release = addLabelsToService(application.Release, conf.EnvironmentGroups, porter_app.LabelKey_PorterApplicationPreDeploy)
|
|
|
preDeployJobValues = buildPreDeployJobChartValues(application.Release, application.Env, synced_env, conf.ImageInfo, conf.InjectLauncherToStartCommand, conf.ExistingHelmValues, strings.TrimSuffix(strings.TrimPrefix(conf.Namespace, "porter-stack-"), "")+"-r", conf.UserUpdate, conf.AddCustomNodeSelector)
|
|
|
}
|
|
|
|
|
|
@@ -900,3 +880,42 @@ func convertHelmValuesToPorterYaml(helmValues string) (*PorterStackYAML, error)
|
|
|
Services: services,
|
|
|
}, nil
|
|
|
}
|
|
|
+
|
|
|
+// addLabelsToService always adds the default label to the service, and if envGroups is not empty, it adds the corresponding environment group label as well.
|
|
|
+func addLabelsToService(service *Service, envGroups []string, defaultLabelKey string) *Service {
|
|
|
+ if _, ok := service.Config["labels"]; !ok {
|
|
|
+ service.Config["labels"] = make(map[string]string)
|
|
|
+ }
|
|
|
+ if len(envGroups) != 0 {
|
|
|
+ // delete the env group label so we can replace it
|
|
|
+ if _, ok := service.Config["labels"].(map[string]any); ok {
|
|
|
+ delete(service.Config["labels"].(map[string]any), environment_groups.LabelKey_LinkedEnvironmentGroup)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 any:
|
|
|
+ if val, ok := service.Config["labels"].(string); ok {
|
|
|
+ if val == "" {
|
|
|
+ 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, ".")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return service
|
|
|
+}
|