mirror of https://github.com/k3s-io/k3s
fix route deletion
This is a follow-up to #56258 which only half of the work done. The DeleteRoute method failed to delete routes when it can’t find the corresponding node in OpenStack.pull/8/head
parent
33f7d8618b
commit
de15b859ba
|
@ -225,10 +225,16 @@ func (r *Routes) DeleteRoute(ctx context.Context, clusterName string, route *clo
|
|||
|
||||
ip, _, _ := net.ParseCIDR(route.DestinationCIDR)
|
||||
isCIDRv6 := ip.To4() == nil
|
||||
addr, err := getAddressByName(r.compute, route.TargetNode, isCIDRv6)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
var addr string
|
||||
|
||||
// Blackhole routes are orphaned and have no target in OpenStack
|
||||
if !route.Blackhole {
|
||||
var err error
|
||||
addr, err = getAddressByName(r.compute, route.TargetNode, isCIDRv6)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
router, err := routers.Get(r.network, r.opts.RouterID).Extract()
|
||||
|
@ -239,7 +245,7 @@ func (r *Routes) DeleteRoute(ctx context.Context, clusterName string, route *clo
|
|||
routes := router.Routes
|
||||
index := -1
|
||||
for i, item := range routes {
|
||||
if item.DestinationCIDR == route.DestinationCIDR && item.NextHop == addr {
|
||||
if item.DestinationCIDR == route.DestinationCIDR && (route.Blackhole || item.NextHop == addr) {
|
||||
index = i
|
||||
break
|
||||
}
|
||||
|
@ -255,7 +261,8 @@ func (r *Routes) DeleteRoute(ctx context.Context, clusterName string, route *clo
|
|||
routes = routes[:len(routes)-1]
|
||||
|
||||
unwind, err := updateRoutes(r.network, router, routes)
|
||||
if err != nil {
|
||||
// If this was a blackhole route we are done, there are no ports to update
|
||||
if err != nil || route.Blackhole {
|
||||
return err
|
||||
}
|
||||
defer onFailure.call(unwind)
|
||||
|
|
Loading…
Reference in New Issue