From 60d4e618815fddd9e41c32bfea3a83a563ef960f Mon Sep 17 00:00:00 2001 From: ahctim Date: Wed, 28 Jul 2021 08:03:45 -0600 Subject: [PATCH 1/2] hold initial blue desired count in global var --- cmd/plugin/blue_green.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/plugin/blue_green.go b/cmd/plugin/blue_green.go index f941590..6d958a2 100644 --- a/cmd/plugin/blue_green.go +++ b/cmd/plugin/blue_green.go @@ -12,6 +12,10 @@ import ( "github.com/assemblyai/drone-deploy-ecs/pkg/types" ) +var ( + initialDesiredCount int +) + // Returns blue service, green service, error func determineBlueGreen(e types.ECSClient, blueService string, greenService string, cluster string) (string, string, error) { @@ -124,6 +128,7 @@ func blueGreen(dc deploy.DeployConfig, maxDeployChecks int) error { dc.ScaleUp(currBlueDesiredCount, serviceMinCount, serviceMaxCount, determinedGreenService) log.Println("Pausing for 45 seconds while ECS schedules", currBlueDesiredCount, "containers") + initialDesiredCount = int(currBlueDesiredCount) time.Sleep(45 * time.Second) // Start polling deployment @@ -242,7 +247,7 @@ func scaleDownInPercentages(dc deploy.DeployConfig, service string, serviceUsesA var newDesiredCount int32 var lastScaleDownEvent bool - scaleDownNumber := float64(desiredCount) * percent + scaleDownNumber := float64(initialDesiredCount) * percent if scaleDownNumber < 0 { scaleDownBy = 1 From 3a06d16c6f13e4ad251ec745094d8386143a3ba9 Mon Sep 17 00:00:00 2001 From: ahctim Date: Wed, 28 Jul 2021 08:03:58 -0600 Subject: [PATCH 2/2] remove comment --- cmd/plugin/blue_green.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/cmd/plugin/blue_green.go b/cmd/plugin/blue_green.go index 6d958a2..bd2a7c6 100644 --- a/cmd/plugin/blue_green.go +++ b/cmd/plugin/blue_green.go @@ -212,15 +212,6 @@ func blueGreen(dc deploy.DeployConfig, maxDeployChecks int) error { return err } -/* -There is a bug in this function. It effectively performs an exponential backoff. -This is because it multiplies desiredCount * scalePercent, but it also calls itself recursively, -so desiredCount gets smaller and smaller - -We should hold the initial desiredCount passed from blueGreen(), maybe in a global variable, then perform our logic on that number - -This bug doesn't really hurt anything, it just makes the scale down go slower than expected -*/ func scaleDownInPercentages(dc deploy.DeployConfig, service string, serviceUsesAppAutoscaling bool, scalePercent string, scaleDownInterval string, desiredCount int) error { scalePercentString, err := strconv.Atoi(scalePercent)