Skip to content

Commit

Permalink
cronEventAction - fix to logic
Browse files Browse the repository at this point in the history
need to invert test for needReplaceOnDemandInstances and
onDemandInstance == nil

currently if onDemandInstance == nil methods return and execution stop.
This way the check to terminate a spotInstace if their number is more
than required is never done.

Assume that ASG scale down and terminate the onDemand instances that
autospotting is not terminating [autospotting_min_on_demand_number].
On the next runs onDemandInstance will be nil and spot instances in
excess will not be terminated.
  • Loading branch information
mello7tre committed Jul 28, 2020
1 parent 742e011 commit af6ccfc
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions core/autoscaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,18 @@ func (a *autoScalingGroup) cronEventAction() runer {

onDemandInstance := a.getAnyUnprotectedOnDemandInstance()

if need, total := a.needReplaceOnDemandInstances(); !need {
logger.Printf("Not allowed to replace any more of the running OD instances in %s", a.name)
return terminateSpotInstance{target{asg: a, totalInstances: total}}
}

if onDemandInstance == nil {
logger.Println(a.region.name, a.name,
"No running unprotected on-demand instances were found, nothing to do here...")

return enableEventHandling{target{asg: a}}
}

if need, total := a.needReplaceOnDemandInstances(); !need {
logger.Printf("Not allowed to replace any more of the running OD instances in %s", a.name)
return terminateSpotInstance{target{asg: a, totalInstances: total}}
}

a.loadLaunchConfiguration()
return launchSpotReplacement{target{
onDemandInstance: onDemandInstance}}
Expand Down

0 comments on commit af6ccfc

Please sign in to comment.