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>
  • Loading branch information
xujunjie-cover committed Jul 22, 2022
1 parent 3c7588b commit f582a11
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
Expand Up @@ -647,6 +647,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
Expand Up @@ -1181,6 +1181,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 f582a11

Please sign in to comment.