Skip to content

Commit

Permalink
Check ASG min OD rules before launching new spot instance (#291)
Browse files Browse the repository at this point in the history
In the event an ASG has just enough OD instances to meet the minimum
number of OD instances, the code should not launch a new spot instance.
  • Loading branch information
jjones-smug authored and cristim committed Aug 20, 2018
1 parent 4981979 commit fff582b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/autoscaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ func (a *autoScalingGroup) process() {
"No running on-demand instances were found, nothing to do here...")
return
}

if !a.needReplaceOnDemandInstances() {
logger.Println("Not allowed to replace any of the running OD instances in ", a.name)
return
}

a.loadLaunchConfiguration()
err := onDemandInstance.launchSpotReplacement()
if err != nil {
Expand Down
23 changes: 23 additions & 0 deletions core/autoscaling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,29 @@ func TestNeedReplaceOnDemandInstances(t *testing.T) {
desiredCapacity: aws.Int64(4),
expectedRun: true,
},
{name: "ASG has on-demand instances equal to the min on-demand number",
asgInstances: makeInstancesWithCatalog(
map[string]*instance{
"id-1": {
Instance: &ec2.Instance{
State: &ec2.InstanceState{Name: aws.String(ec2.InstanceStateNameRunning)},
Placement: &ec2.Placement{AvailabilityZone: aws.String("eu-west-1a")},
InstanceLifecycle: aws.String("on-demand"),
},
},
"id-2": {
Instance: &ec2.Instance{
State: &ec2.InstanceState{Name: aws.String(ec2.InstanceStateNameRunning)},
Placement: &ec2.Placement{AvailabilityZone: aws.String("eu-west-1b")},
InstanceLifecycle: aws.String("spot"),
},
},
},
),
minOnDemand: 1,
desiredCapacity: aws.Int64(2),
expectedRun: false,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit fff582b

Please sign in to comment.