Skip to content

Commit

Permalink
only send spot termination if there are any
Browse files Browse the repository at this point in the history
  • Loading branch information
keyki committed Jun 26, 2020
1 parent 65b5339 commit e5f0a6c
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,19 @@ func (p awsProvider) StopInstances(instances *types.InstanceContainer) []error {
errChan <- err
}

spotInstanceNames := ""
for _, inst := range spotInstanceIDs {
name := instIDNames[*inst]
spotInstanceNames += fmt.Sprintf("\n%s:%s", *inst, name)
}
log.Infof("[AWS] Sending request to terminate spot instances in region %s (%d): %v", region, len(spotInstanceIDs), spotInstanceNames)
if _, err := p.ec2Clients[region].TerminateInstances(&ec2.TerminateInstancesInput{InstanceIds: spotInstanceIDs}); err != nil {
errChan <- err
if len(spotInstanceIDs) > 0 {
spotInstanceNames := ""
for _, inst := range spotInstanceIDs {
name := instIDNames[*inst]
spotInstanceNames += fmt.Sprintf("\n%s:%s", *inst, name)
}

log.Infof("[AWS] Sending request to terminate spot instances in region %s (%d): %v", region, len(spotInstanceIDs), spotInstanceNames)
if _, err := p.ec2Clients[region].TerminateInstances(&ec2.TerminateInstancesInput{InstanceIds: spotInstanceIDs}); err != nil {
errChan <- err
}
} else {
log.Info("[AWS] There are not spot instances to terminate")
}
}
}
Expand Down

0 comments on commit e5f0a6c

Please sign in to comment.