@@ -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