Skip to content

Commit

Permalink
cni: return first error if setup retry fails
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Ethier <[email protected]>
  • Loading branch information
nickethier committed Mar 31, 2020
1 parent b899020 commit bf974de
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions client/allocrunner/networking_cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,18 @@ func (c *cniNetworkConfigurator) Setup(ctx context.Context, alloc *structs.Alloc
// where two alloc attempt to create the nomad bridge at the same time, resulting
// in one of them to fail. This rety attempts to overcome any
const retry = 3
var firstError error
for attempt := 1; ; attempt++ {
//TODO eventually returning the IP from the result would be nice to have in the alloc
if _, err := c.cni.Setup(ctx, alloc.ID, spec.Path, cni.WithCapabilityPortMap(getPortMapping(alloc))); err != nil {
c.logger.Warn("failed to configure network", "err", err, "attempt", attempt)
if attempt == retry {
return fmt.Errorf("failed to configure network: %v", err)
switch attempt {
case 1:
firstError = err
case retry:
return fmt.Errorf("failed to configure network: %v", firstError)
}

// Sleep for 1 second + jitter
time.Sleep(time.Second + (time.Duration(c.rand.Int63n(1000)) * time.Millisecond))
continue
Expand Down

0 comments on commit bf974de

Please sign in to comment.