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

Made timeouts exponential #640

Merged
merged 7 commits into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 13 additions & 28 deletions pkg/networkutils/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"syscall"
"time"

"github.com/aws/amazon-vpc-cni-k8s/pkg/utils/retry"

"github.com/pkg/errors"
"golang.org/x/sys/unix"

Expand Down Expand Up @@ -759,35 +761,18 @@ func setupENINetwork(eniIP string, eniMAC string, eniTable int, eniSubnetCIDR st
return errors.Wrap(err, "setupENINetwork: failed to clean up old routes")
}

// In case of route dependency, retry few times
retry := 0
for {
if err := netLink.RouteAdd(&r); err != nil {
if netlinkwrapper.IsNetworkUnreachableError(err) {
retry++
if retry > maxRetryRouteAdd {
log.Errorf("Failed to add route %s/0 via %s table %d",
r.Dst.IP.String(), gw.String(), eniTable)
return errors.Wrapf(err, "setupENINetwork: failed to add route %s/0 via %s table %d",
r.Dst.IP.String(), gw.String(), eniTable)
}
log.Debugf("Not able to add route route %s/0 via %s table %d (attempt %d/%d)",
r.Dst.IP.String(), gw.String(), eniTable, retry, maxRetryRouteAdd)
time.Sleep(retryRouteAddInterval)
} else if netlinkwrapper.IsRouteExistsError(err) {
if err := netLink.RouteReplace(&r); err != nil {
return errors.Wrapf(err, "setupENINetwork: unable to replace route entry %s", r.Dst.IP.String())
}
log.Debugf("Successfully replaced route to be %s/0", r.Dst.IP.String())
break
} else {
return errors.Wrapf(err, "setupENINetwork: unable to add route %s/0 via %s table %d",
r.Dst.IP.String(), gw.String(), eniTable)
}
} else {
log.Debugf("Successfully added route route %s/0 via %s table %d", r.Dst.IP.String(), gw.String(), eniTable)
break
err = retry.RetryNWithBackoff(retry.NewSimpleBackoff(500*time.Millisecond, retryRouteAddInterval, 0.15, 2.0), maxRetryRouteAdd, func() error {
if err := netLink.RouteReplace(&r); err != nil {
log.Debugf("Not able to set route %s/0 via %s table %d",
r.Dst.IP.String(), gw.String(), eniTable)
return errors.Wrapf(err, "setupENINetwork: unable to replace route entry %s", r.Dst.IP.String())
}

log.Debugf("Successfully added/replaced route to be %s/0", r.Dst.IP.String())
return nil
})
if err != nil {
return err
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/networkutils/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ func TestSetupENINetwork(t *testing.T) {
mockNetLink.EXPECT().AddrAdd(gomock.Any(), &netlink.Addr{IPNet: testeniAddr}).Return(nil)

mockNetLink.EXPECT().RouteDel(gomock.Any())
mockNetLink.EXPECT().RouteAdd(gomock.Any()).Return(nil)
mockNetLink.EXPECT().RouteReplace(gomock.Any()).Return(nil)

mockNetLink.EXPECT().RouteDel(gomock.Any())
mockNetLink.EXPECT().RouteAdd(gomock.Any()).Return(nil)
mockNetLink.EXPECT().RouteReplace(gomock.Any()).Return(nil)

mockNetLink.EXPECT().RouteDel(gomock.Any()).Return(nil)

Expand Down