Skip to content

Commit 1b9b222

Browse files
committed
fix(ipAddrDel): check for routes before trying to delete
Instead of deleting and just hoping for the best, this change makes it so that we check first whether or not a route exists. This helps to reduce needless warnings that the user receives and is just all around more accurate.
1 parent f997e4a commit 1b9b222

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

pkg/controllers/proxy/linux_networking.go

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,38 @@ func (ln *linuxNetworking) ipAddrDel(iface netlink.Link, ip string, nodeIP strin
105105
Scope: syscall.RT_SCOPE_HOST,
106106
Src: parsedNodeIP,
107107
}
108-
err = netlink.RouteDel(nRoute)
108+
routes, err := netlink.RouteListFiltered(netlink.FAMILY_ALL, nRoute,
109+
netlink.RT_FILTER_TYPE|netlink.RT_FILTER_DST|netlink.RT_FILTER_OIF|netlink.RT_FILTER_TABLE|netlink.RT_FILTER_SRC)
109110
if err != nil {
110-
if !strings.Contains(err.Error(), "no such process") {
111-
klog.Errorf("Failed to delete route to service VIP %s configured on %s. Error: %v",
112-
ip, iface.Attrs().Name, err)
113-
} else {
114-
klog.Warningf("got a No such process error while trying to remove route: %v (this is not normally bad "+
115-
"enough to stop processing)", err)
116-
return nil
111+
return fmt.Errorf("failed to list filtered routes for route %s: %v", nRoute, err)
112+
}
113+
114+
// Let the user know if we found more than 1 route that matched a single route filter
115+
if len(routes) > 1 {
116+
klog.Warning("Found more than 1 route that matched a single route filter, this is not expected, please " +
117+
"report this upstream as a bug if you see this message along with the information below:")
118+
for _, route := range routes {
119+
klog.Infof("Found route: %s", route)
117120
}
121+
klog.Warningf("Continuing with deletion of the route we know about: %s", nRoute)
118122
}
119123

120-
return err
124+
// If we found one or no routes, this is expected, so we can proceed with the action
125+
if len(routes) > 0 {
126+
klog.V(1).Infof("Found %d routes for interface %s, deleting them...", len(routes), iface.Attrs().Name)
127+
err = netlink.RouteDel(nRoute)
128+
if err != nil {
129+
if !strings.Contains(err.Error(), "no such process") {
130+
return fmt.Errorf("failed to delete route %s: %v", nRoute, err)
131+
}
132+
klog.Warningf("got a No such process error while trying to remove route %s: %v (this is not normally bad "+
133+
"enough to stop processing)", nRoute, err)
134+
}
135+
} else {
136+
klog.V(1).Infof("No routes found for %s, skipping deletion", nRoute)
137+
}
138+
139+
return nil
121140
}
122141

123142
// utility method to assign an IP to an interface. Mainly used to assign service VIP's

0 commit comments

Comments
 (0)