Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CNI Implementation #7518

Merged
merged 8 commits into from
May 15, 2020
Prev Previous commit
Next Next commit
cni: return first error if setup retry fails
Signed-off-by: Nick Ethier <[email protected]>
  • Loading branch information
nickethier committed May 15, 2020
commit 39e247aa9e213b577da4ea6ba10d6e617c08f4e9
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