Skip to content

Commit

Permalink
take into account draining node when scaling down
Browse files Browse the repository at this point in the history
  • Loading branch information
wardviaene committed Feb 13, 2018
1 parent 6e7cf17 commit 283e8c9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions api/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,9 +865,12 @@ func (c *Controller) processEcsMessage(message ecs.SNSPayloadEcs) error {
totalFreeMemory := make(map[string]int64)
hasFreeResources := make(map[string]bool)
hasFreeResourcesGlobal := true
hasFreeResourcesGlobalAZ := ""
for _, dcci := range dc.ContainerInstances {
totalFreeCpu[dcci.AvailabilityZone] += dcci.FreeCpu
totalFreeMemory[dcci.AvailabilityZone] += dcci.FreeMemory
if dcci.Status != "DRAINING" {
totalFreeCpu[dcci.AvailabilityZone] += dcci.FreeCpu
totalFreeMemory[dcci.AvailabilityZone] += dcci.FreeMemory
}
}
for k, _ := range totalFreeCpu {
controllerLogger.Debugf("%v: Have %d cpu available, need %d", k, totalFreeCpu[k], clusterCpuNeeded)
Expand All @@ -881,8 +884,9 @@ func (c *Controller) processEcsMessage(message ecs.SNSPayloadEcs) error {
}
}
}
for _, v := range hasFreeResources {
for k, v := range hasFreeResources {
if !v {
hasFreeResourcesGlobalAZ = k
hasFreeResourcesGlobal = false
}
}
Expand All @@ -893,7 +897,7 @@ func (c *Controller) processEcsMessage(message ecs.SNSPayloadEcs) error {
return err
}
if lastScalingOp == "no" {
controllerLogger.Infof("Starting scaling down operation (cpu: %d >= %d, mem: %d >= %d", totalFreeCpu, clusterCpuNeeded, totalFreeMemory, clusterMemoryNeeded)
controllerLogger.Infof("Starting scaling down operation (cpu: %d >= %d, mem: %d >= %d", totalFreeCpu[hasFreeResourcesGlobalAZ], clusterCpuNeeded, totalFreeMemory[hasFreeResourcesGlobalAZ], clusterMemoryNeeded)
scalingOp = "down"
autoScalingGroupName, err := autoscaling.GetAutoScalingGroupByTag(clusterName)
if err != nil {
Expand Down

0 comments on commit 283e8c9

Please sign in to comment.