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 <[email protected]>
(cherry picked from commit f582a11)
  • Loading branch information
xujunjie-cover authored and oilbeater committed Jul 22, 2022
1 parent f9a8458 commit 994885c
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 @@ -608,6 +608,10 @@ func (c *Controller) gcStaticRoute() error {
for _, route := range routes {
if route.CIDR != "0.0.0.0/0" && route.CIDR != "::/0" && c.ipam.ContainAddress(route.CIDR) {
klog.Infof("gc static route %s %s %s", route.Policy, route.CIDR, route.NextHop)
exist, err := c.ovnLegacyClient.NatRuleExists(route.CIDR)
if exist || err != nil {
continue
}
if err := c.ovnLegacyClient.DeleteStaticRoute(route.CIDR, c.config.ClusterRouter); err != nil {
klog.Errorf("failed to delete stale route %s, %v", route.NextHop, err)
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/ovs/ovn-nbctl-legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,18 @@ func (c LegacyClient) DeleteNatRule(logicalIP, router string) error {
return err
}

func (c *LegacyClient) 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 LegacyClient) DeleteMatchedStaticRoute(cidr, nexthop, router string) error {
if cidr == "" || nexthop == "" {
return nil
Expand Down

0 comments on commit 994885c

Please sign in to comment.