diff --git a/pkg/cloudprovider/providers/openstack/openstack_routes.go b/pkg/cloudprovider/providers/openstack/openstack_routes.go index 8af30d9202b..3f41c7339d9 100644 --- a/pkg/cloudprovider/providers/openstack/openstack_routes.go +++ b/pkg/cloudprovider/providers/openstack/openstack_routes.go @@ -83,9 +83,12 @@ func (r *Routes) ListRoutes(ctx context.Context, clusterName string) ([]*cloudpr var routes []*cloudprovider.Route for _, item := range router.Routes { nodeName, foundNode := nodeNamesByAddr[item.NextHop] + if !foundNode { + nodeName = types.NodeName(item.NextHop) + } route := cloudprovider.Route{ Name: item.DestinationCIDR, - TargetNode: nodeName, //empty if NextHop is unknown + TargetNode: nodeName, //contains the nexthop address if node was not found Blackhole: !foundNode, DestinationCIDR: item.DestinationCIDR, } @@ -225,10 +228,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 counterpart 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 +248,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 && (item.NextHop == addr || route.Blackhole && item.NextHop == string(route.TargetNode)) { index = i break } @@ -255,7 +264,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)