Procházet zdrojové kódy

add stable slice sorting to env var postrenderer and fix cli edge cases

Alexander Belanger před 4 roky
rodič
revize
d71e936c6c

+ 0 - 2
cli/cmd/bluegreen.go

@@ -124,8 +124,6 @@ func bluegreenSwitch(_ *types.GetAuthenticatedUserResponse, client *api.Client,
 				// determine if the deployment has an appropriate number of ready replicas
 				minUnavailable := *(depl.Spec.Replicas) - getMaxUnavailable(depl)
 
-				fmt.Println("min unavabile is", minUnavailable, "curr is", depl.Status.ReadyReplicas)
-
 				// if the number of ready replicas is greater than the number of min unavailable,
 				// the controller is ready for a traffic switch
 				if minUnavailable <= depl.Status.ReadyReplicas {

+ 8 - 4
cli/cmd/deploy/deploy.go

@@ -350,10 +350,14 @@ func (d *DeployAgent) UpdateImageAndValues(overrideValues map[string]interface{}
 					// they're enabled -- read the activeTagValue and construct the new bluegreen object
 					if activeTagInter, ok := bgVal["activeImageTag"]; ok {
 						if activeTagVal, ok := activeTagInter.(string); ok {
-							mergedValues["bluegreen"] = map[string]interface{}{
-								"enabled":        true,
-								"activeImageTag": activeTagVal,
-								"imageTags":      []string{activeTagVal, d.tag},
+							// only overwrite if the active tag value is not the same as the target tag. otherwise
+							// this has been modified already and inserted into overrideValues.
+							if activeTagVal != d.tag {
+								mergedValues["bluegreen"] = map[string]interface{}{
+									"enabled":        true,
+									"activeImageTag": activeTagVal,
+									"imageTags":      []string{activeTagVal, d.tag},
+								}
 							}
 						}
 					}

+ 7 - 0
internal/helm/postrenderer.go

@@ -2,9 +2,11 @@ package helm
 
 import (
 	"bytes"
+	"fmt"
 	"io"
 	"net/url"
 	"regexp"
+	"sort"
 	"strings"
 
 	"github.com/aws/aws-sdk-go/aws/arn"
@@ -749,6 +751,11 @@ func (e *EnvironmentVariablePostrenderer) updatePodSpecs() error {
 				envVarArr = append(envVarArr, envVar)
 			}
 
+			// Sort the slices according to a stable ordering. This is hacky and inefficient.
+			sort.SliceStable(envVarArr, func(i, j int) bool {
+				return fmt.Sprintf("%v", envVarArr[i]) > fmt.Sprintf("%v", envVarArr[j])
+			})
+
 			_container["env"] = envVarArr
 			newContainers = append(newContainers, _container)
 		}