Skip to content

Commit

Permalink
make node autoscaling cluster aware
Browse files Browse the repository at this point in the history
  • Loading branch information
wardviaene committed Feb 20, 2018
1 parent 5a26140 commit 4854c29
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions api/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,21 +815,23 @@ func (c *Controller) processEcsMessage(message ecs.SNSPayloadEcs) error {
var scalingOp = "no"
if desiredCapacity < maxSize {
for _, dcci := range dc.ContainerInstances {
if dcci.Status != "DRAINING" && dcci.FreeCpu > cpuNeeded[clusterName] && dcci.FreeMemory > memoryNeeded[clusterName] {
resourcesFit[dcci.AvailabilityZone] = true
controllerLogger.Debugf("Cluster %v needs at least %v cpu and %v memory. Found instance %v (%v) with %v cpu and %v memory",
clusterName,
cpuNeeded[clusterName],
memoryNeeded[clusterName],
dcci.ContainerInstanceId,
dcci.AvailabilityZone,
dcci.FreeCpu,
dcci.FreeMemory,
)
} else {
// set resourcesFit[az] in case it's not set to true
if _, ok := resourcesFit[dcci.AvailabilityZone]; !ok {
resourcesFit[dcci.AvailabilityZone] = false
if clusterName == dcci.ClusterName {
if dcci.Status != "DRAINING" && dcci.FreeCpu > cpuNeeded[clusterName] && dcci.FreeMemory > memoryNeeded[clusterName] {
resourcesFit[dcci.AvailabilityZone] = true
controllerLogger.Debugf("Cluster %v needs at least %v cpu and %v memory. Found instance %v (%v) with %v cpu and %v memory",
clusterName,
cpuNeeded[clusterName],
memoryNeeded[clusterName],
dcci.ContainerInstanceId,
dcci.AvailabilityZone,
dcci.FreeCpu,
dcci.FreeMemory,
)
} else {
// set resourcesFit[az] in case it's not set to true
if _, ok := resourcesFit[dcci.AvailabilityZone]; !ok {
resourcesFit[dcci.AvailabilityZone] = false
}
}
}
}
Expand Down Expand Up @@ -875,9 +877,11 @@ func (c *Controller) processEcsMessage(message ecs.SNSPayloadEcs) error {
hasFreeResourcesGlobal := true
hasFreeResourcesGlobalAZ := ""
for _, dcci := range dc.ContainerInstances {
if dcci.Status != "DRAINING" {
totalFreeCpu[dcci.AvailabilityZone] += dcci.FreeCpu
totalFreeMemory[dcci.AvailabilityZone] += dcci.FreeMemory
if clusterName == dcci.ClusterName {
if dcci.Status != "DRAINING" {
totalFreeCpu[dcci.AvailabilityZone] += dcci.FreeCpu
totalFreeMemory[dcci.AvailabilityZone] += dcci.FreeMemory
}
}
}
for k, _ := range totalFreeCpu {
Expand Down

0 comments on commit 4854c29

Please sign in to comment.