Skip to content

Commit

Permalink
kindnetd remove wrong routes
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Sep 26, 2022
1 parent 333bc7f commit 5f0e3c3
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions images/kindnetd/cmd/kindnetd/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,31 @@ func syncRoute(nodeIP string, podCIDRs []string) error {
return err
}

// Check if the route exists to the other node's PodCIDR
// Declare the wanted route.
routeToDst := netlink.Route{Dst: dst, Gw: ip}
route, err := netlink.RouteListFiltered(nl.GetIPFamily(ip), &routeToDst, netlink.RT_FILTER_DST)
// List all routes which have the same dst set.
// RouteListFiltered ignores the gw for filtering because of the passed filterMask.
routes, err := netlink.RouteListFiltered(nl.GetIPFamily(ip), &routeToDst, netlink.RT_FILTER_DST)
if err != nil {
return err
}

// Check if the wanted route exists and delete wrong routes
found := false
for _, route := range routes {
if routeToDst.Gw.Equal(ip) {
found = true
continue
}
// Delete wrong route because of invalid gateway.
klog.Infof("Removing invalid route %v\n", route)
if err := netlink.RouteDel(&route); err != nil {
return err
}
}

// Add route if not present
if len(route) == 0 {
if !found {
klog.Infof("Adding route %v \n", routeToDst)
if err := netlink.RouteAdd(&routeToDst); err != nil {
return err
Expand Down

0 comments on commit 5f0e3c3

Please sign in to comment.