Skip to content

Commit 199a997

Browse files
authored
Merge pull request #524 from gnought/feat/retry_insufficient_spot_capacity
feat: add retry logic for insufficient spot capacity errors
2 parents d742e1f + dadc0de commit 199a997

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

builder/common/step_run_source_instance.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,7 @@ func (s *StepRunSourceInstance) Run(ctx context.Context, state multistep.StateBa
285285
err = retry.Config{
286286
Tries: 11,
287287
ShouldRetry: func(err error) bool {
288-
if awserrors.Matches(err, "InvalidParameterValue", "iamInstanceProfile") {
289-
return true
290-
}
291-
return false
288+
return awserrors.Matches(err, "InvalidParameterValue", "iamInstanceProfile")
292289
},
293290
RetryDelay: (&retry.Backoff{InitialBackoff: 200 * time.Millisecond, MaxBackoff: 30 * time.Second, Multiplier: 2}).Linear,
294291
}.Run(ctx, func(ctx context.Context) error {
@@ -326,10 +323,7 @@ func (s *StepRunSourceInstance) Run(ctx context.Context, state multistep.StateBa
326323

327324
var r *ec2.DescribeInstancesOutput
328325
err = retry.Config{Tries: 11, ShouldRetry: func(err error) bool {
329-
if awserrors.Matches(err, "InvalidInstanceID.NotFound", "") {
330-
return true
331-
}
332-
return false
326+
return awserrors.Matches(err, "InvalidInstanceID.NotFound", "")
333327
},
334328
RetryDelay: (&retry.Backoff{InitialBackoff: 200 * time.Millisecond, MaxBackoff: 30 * time.Second, Multiplier: 2}).Linear,
335329
}.Run(ctx, func(ctx context.Context) error {

builder/common/step_run_spot_instance.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,9 @@ func (s *StepRunSpotInstance) Run(ctx context.Context, state multistep.StateBag)
413413
// we can wait on those operations, this can be removed.
414414
return true
415415
}
416+
if err.Error() == "InsufficientInstanceCapacity" {
417+
return true
418+
}
416419
return false
417420
},
418421
RetryDelay: (&retry.Backoff{InitialBackoff: 500 * time.Millisecond, MaxBackoff: 30 * time.Second, Multiplier: 2}).Linear,
@@ -433,6 +436,12 @@ func (s *StepRunSpotInstance) Run(ctx context.Context, state multistep.StateBag)
433436
if err != nil {
434437
log.Printf("create request failed %v", err)
435438
}
439+
// We can end up unavailable Spot capacity, we keep retrying
440+
for _, err := range createOutput.Errors {
441+
if err.ErrorCode != nil && *err.ErrorCode == "InsufficientInstanceCapacity" {
442+
return fmt.Errorf(*err.ErrorCode)
443+
}
444+
}
436445
return err
437446
})
438447

@@ -513,10 +522,7 @@ func (s *StepRunSpotInstance) Run(ctx context.Context, state multistep.StateBag)
513522

514523
// Retry creating tags for about 2.5 minutes
515524
err = retry.Config{Tries: 11, ShouldRetry: func(err error) bool {
516-
if awserrors.Matches(err, "InvalidInstanceID.NotFound", "") {
517-
return true
518-
}
519-
return false
525+
return awserrors.Matches(err, "InvalidInstanceID.NotFound", "")
520526
},
521527
RetryDelay: (&retry.Backoff{InitialBackoff: 200 * time.Millisecond, MaxBackoff: 30 * time.Second, Multiplier: 2}).Linear,
522528
}.Run(ctx, func(ctx context.Context) error {

0 commit comments

Comments
 (0)