Skip to content

Commit

Permalink
fix: cancel delete staticroute when it's used by NatRule (#1733)
Browse files Browse the repository at this point in the history
Signed-off-by: xujunjie-cover <xujunjielxx@163.com>

(cherry picked from commit f582a11)
  • Loading branch information
xujunjie-cover authored and oilbeater committed Jul 22, 2022
1 parent 513a30b commit ef275cc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/controller/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,10 @@ func (c *Controller) gcStaticRoute() error {
for _, route := range routes {
if route.Policy == ovs.PolicyDstIP || route.Policy == "" {
if !c.ipam.ContainAddress(route.NextHop) {
exist, err := c.ovnClient.NatRuleExists(route.CIDR)
if exist || err != nil {
continue
}
klog.Infof("gc static route %s %s %s", route.Policy, route.CIDR, route.NextHop)
if err := c.ovnClient.DeleteStaticRouteByNextHop(route.NextHop); err != nil {
klog.Errorf("failed to delete stale nexthop route %s, %v", route.NextHop, err)
Expand Down
12 changes: 12 additions & 0 deletions pkg/ovs/ovn-nbctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,18 @@ func (c Client) DeleteNatRule(logicalIP, router string) error {
return err
}

func (c *Client) NatRuleExists(logicalIP string) (bool, error) {
results, err := c.CustomFindEntity("NAT", []string{"external_ip"}, fmt.Sprintf("logical_ip=%s", logicalIP))
if err != nil {
klog.Errorf("customFindEntity failed, %v", err)
return false, err
}
if len(results) == 0 {
return false, nil
}
return true, nil
}

func (c Client) DeleteMatchedStaticRoute(cidr, nexthop, router string) error {
if cidr == "" || nexthop == "" {
return nil
Expand Down

0 comments on commit ef275cc

Please sign in to comment.