Unverified Commit f582a11b authored by xujunjie-cover's avatar xujunjie-cover Committed by GitHub
Browse files

fix: cancel delete staticroute when it's used by NatRule (#1733)

Signed-off-by: default avatarxujunjie-cover <xujunjielxx@163.com>
Showing with 16 additions and 0 deletions
+16 -0
......@@ -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)
}
......
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment