Skip to content

Commit

Permalink
fix: replace replace with add to override existing route (#2052)
Browse files Browse the repository at this point in the history
  • Loading branch information
lut777 committed Nov 18, 2022
1 parent fa3c8c9 commit 8b06f3f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/daemon/controller_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func (c *Controller) reconcileRouters(event subnetEvent) error {
}
// add new routes first
for _, r := range routesToAdd {
if err = netlink.RouteAdd(&r); err != nil && !errors.Is(err, syscall.EEXIST) {
klog.Errorf("failed to add route for subnet %s: %v", newSubnet.Name, err)
if err = netlink.RouteReplace(&r); err != nil && !errors.Is(err, syscall.EEXIST) {
klog.Errorf("failed to replace route for subnet %s: %v", newSubnet.Name, err)
return err
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/daemon/gateway_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ func (c *Controller) addPolicyRouting(family int, gateway string, priority, tabl
Gw: net.ParseIP(gateway),
Table: int(tableID),
}
if err := netlink.RouteAdd(route); err != nil && !errors.Is(err, syscall.EEXIST) {
err = fmt.Errorf("failed to add route in table %d: %+v", tableID, err)
if err := netlink.RouteReplace(route); err != nil && !errors.Is(err, syscall.EEXIST) {
err = fmt.Errorf("failed to replace route in table %d: %+v", tableID, err)
klog.Error(err)
return err
}
Expand Down

0 comments on commit 8b06f3f

Please sign in to comment.