Skip to content

Commit

Permalink
Merge pull request docker#4312 from nolith/3539-retry-on-spot-instances
Browse files Browse the repository at this point in the history
Wait for eventual consistency on AWS spot instances
  • Loading branch information
dgageot authored Nov 23, 2017
2 parents 9b98950 + 28433ea commit 49dfaa7
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions drivers/amazonec2/amazonec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const (
)

const (
keypairNotFoundCode = "InvalidKeyPair.NotFound"
keypairNotFoundCode = "InvalidKeyPair.NotFound"
spotInstanceRequestNotFoundCode = "InvalidSpotInstanceRequestID.NotFound"
)

var (
Expand Down Expand Up @@ -640,11 +641,21 @@ func (d *Driver) Create() error {
}

log.Info("Waiting for spot instance...")
err = d.getClient().WaitUntilSpotInstanceRequestFulfilled(&ec2.DescribeSpotInstanceRequestsInput{
SpotInstanceRequestIds: []*string{spotInstanceRequest.SpotInstanceRequests[0].SpotInstanceRequestId},
})
if err != nil {
return fmt.Errorf("Error fulfilling spot request: %v", err)
for i := 0; i < 3; i++ {
// AWS eventual consistency means we could not have SpotInstanceRequest ready yet
err = d.getClient().WaitUntilSpotInstanceRequestFulfilled(&ec2.DescribeSpotInstanceRequestsInput{
SpotInstanceRequestIds: []*string{spotInstanceRequest.SpotInstanceRequests[0].SpotInstanceRequestId},
})
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
if awsErr.Code() == spotInstanceRequestNotFoundCode {
time.Sleep(5 * time.Second)
continue
}
}
return fmt.Errorf("Error fulfilling spot request: %v", err)
}
break
}
log.Info("Created spot instance request %v", *spotInstanceRequest.SpotInstanceRequests[0].SpotInstanceRequestId)
// resolve instance id
Expand Down

0 comments on commit 49dfaa7

Please sign in to comment.