Skip to content

Commit a968b2b

Browse files
aaurenmurali-reddy
authored andcommitted
cleanup local routes if nexthop moves outside host subnet (#629)
1 parent 11ae253 commit a968b2b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pkg/controllers/routing/network_routes_controller.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/osrg/gobgp/table"
2727
"github.com/prometheus/client_golang/prometheus"
2828
"github.com/vishvananda/netlink"
29+
"github.com/vishvananda/netlink/nl"
2930

3031
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3132
"k8s.io/client-go/kubernetes"
@@ -427,6 +428,22 @@ func (nrc *NetworkRoutingController) injectRoute(path *table.Path) error {
427428
if !nrc.enableOverlays {
428429
glog.Infof("Found node: " + nexthop.String() + " to be in different subnet but overlays are " +
429430
"disabled so not creating any tunnel and injecting route for the node's pod CIDR.")
431+
432+
glog.Infof("Cleaning up old routes if there are any")
433+
routes, err := netlink.RouteListFiltered(nl.FAMILY_ALL, &netlink.Route{
434+
Dst: dst, Protocol: 0x11,
435+
}, netlink.RT_FILTER_DST|netlink.RT_FILTER_PROTOCOL)
436+
if err != nil {
437+
glog.Errorf("Failed to get routes from netlink")
438+
}
439+
for i, r := range routes {
440+
glog.V(2).Infof("Found route to remove: %s", r.String())
441+
err := netlink.RouteDel(&routes[i])
442+
if err != nil {
443+
glog.Errorf("Failed to remove route due to " + err.Error())
444+
}
445+
}
446+
430447
glog.Infof("Cleaning up if there is any existing tunnel interface for the node")
431448
link, err := netlink.LinkByName(tunnelName)
432449
if err != nil {

0 commit comments

Comments
 (0)