소스 검색

feat: helm chart overrides

Soham Parekh 3 년 전
부모
커밋
370c50377e
3개의 변경된 파일29개의 추가작업 그리고 15개의 파일을 삭제
  1. 9 9
      cli/cmd/deploy/deploy.go
  2. 3 1
      cli/cmd/deploy/shared.go
  3. 17 5
      internal/helm/postrenderer.go

+ 9 - 9
cli/cmd/deploy/deploy.go

@@ -437,26 +437,26 @@ func GetEnvForRelease(
 ) (map[string]string, error) {
 	res := make(map[string]string)
 
-	// first, get the env vars from "container.env.normal"
-	normalEnv, err := GetNormalEnv(client, config, projID, clusterID, namespace, true)
+	// first, get the env vars specified by "container.env.synced"
+	// look for container.env.synced
+	syncedEnv, err := GetSyncedEnv(client, config, projID, clusterID, namespace, true)
 
 	if err != nil {
-		return nil, fmt.Errorf("error while fetching container.env.normal variables: %w", err)
+		return nil, fmt.Errorf("error while fetching container.env.synced variables: %w", err)
 	}
 
-	for k, v := range normalEnv {
+	for k, v := range syncedEnv {
 		res[k] = v
 	}
 
-	// next, get the env vars specified by "container.env.synced"
-	// look for container.env.synced
-	syncedEnv, err := GetSyncedEnv(client, config, projID, clusterID, namespace, true)
+	// next, get the env vars from "container.env.normal"
+	normalEnv, err := GetNormalEnv(client, config, projID, clusterID, namespace, true)
 
 	if err != nil {
-		return nil, fmt.Errorf("error while fetching container.env.synced variables: %w", err)
+		return nil, fmt.Errorf("error while fetching container.env.normal variables: %w", err)
 	}
 
-	for k, v := range syncedEnv {
+	for k, v := range normalEnv {
 		res[k] = v
 	}
 

+ 3 - 1
cli/cmd/deploy/shared.go

@@ -56,7 +56,9 @@ func coalesceEnvGroups(
 		}
 
 		for k, v := range envGroup.Variables {
-			envConfig[k] = v
+			if _, ok := envConfig[k]; !ok {
+				envConfig[k] = v
+			}
 		}
 
 		containerMap, _ := config["container"].(map[string]interface{})

+ 17 - 5
internal/helm/postrenderer.go

@@ -10,6 +10,7 @@ import (
 	"strings"
 
 	"github.com/aws/aws-sdk-go/aws/arn"
+	"github.com/heroku/color"
 	"github.com/porter-dev/porter/internal/kubernetes"
 	"github.com/porter-dev/porter/internal/models"
 	"github.com/porter-dev/porter/internal/repository"
@@ -671,12 +672,15 @@ func (e *EnvironmentVariablePostrenderer) updatePodSpecs() error {
 	for _, podSpec := range e.podSpecs {
 		containersVal, hasContainers := podSpec["containers"]
 
+		// If the pod spec does not contain `containers` field, continue
 		if !hasContainers {
 			continue
 		}
 
 		containers, ok := containersVal.([]interface{})
 
+		color.Magenta("containers: %v", containers)
+
 		if !ok {
 			continue
 		}
@@ -693,14 +697,14 @@ func (e *EnvironmentVariablePostrenderer) updatePodSpecs() error {
 			}
 
 			// read container env variables
-			envInter, ok := _container["env"]
+			containerEnv, ok := _container["env"]
 
 			if !ok {
 				newContainers = append(newContainers, _container)
 				continue
 			}
 
-			env, ok := envInter.([]interface{})
+			env, ok := containerEnv.([]interface{})
 
 			if !ok {
 				newContainers = append(newContainers, _container)
@@ -727,15 +731,21 @@ func (e *EnvironmentVariablePostrenderer) updatePodSpecs() error {
 				}
 
 				// check if the env var already exists, if it does perform reconciliation
-				if currVal, exists := envVars[envVarNameStr]; exists {
-					currValMap, ok := currVal.(resource)
+				if existingVal, exists := envVars[envVarNameStr]; exists {
+					existingValMap, ok := existingVal.(resource)
 
 					if !ok {
 						continue
 					}
 
 					// if the current value has a valueFrom field, this should override the existing env var
-					if _, currValFromFieldExists := currValMap["valueFrom"]; currValFromFieldExists {
+					_, existingValHasValueField := existingValMap["value"]
+					_, existingValHasValueFromField := existingValMap["valueFrom"]
+					_, currValHasValueFromField := envVarMap["valueFrom"]
+
+					if existingValHasValueField && currValHasValueFromField {
+						continue
+					} else if existingValHasValueFromField && currValHasValueFromField {
 						continue
 					} else {
 						envVars[envVarNameStr] = envVarMap
@@ -761,6 +771,8 @@ func (e *EnvironmentVariablePostrenderer) updatePodSpecs() error {
 			newContainers = append(newContainers, _container)
 		}
 
+		color.Red("newContainers: %v", containers)
+
 		podSpec["containers"] = newContainers
 	}