Skip to content

Commit

Permalink
reserve pod eip static route when update vpc (#2185)
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhen-ma committed Dec 23, 2022
1 parent 9bcb203 commit 33da205
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pkg/controller/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,40 @@ func (c *Controller) handleAddOrUpdateVpc(key string) error {
NextHopIP: gatewayV6,
})
}

if c.config.EnableEipSnat {
cm, err := c.configMapsLister.ConfigMaps(c.config.ExternalGatewayConfigNS).Get(util.ExternalGatewayConfig)
if err == nil {
nextHop := cm.Data["external-gw-addr"]
if nextHop == "" {
klog.Errorf("no available gateway nic address")
return fmt.Errorf("no available gateway nic address")
}
if strings.Contains(nextHop, "/") {
nextHop = strings.Split(nextHop, "/")[0]
}

nats, err := c.ovnLegacyClient.GetRouterNat(vpc.Name)
if err != nil {
klog.Errorf("failed to get nat for vpc %s, %v", vpc.Name, err)
return err
}
for _, nat := range nats {
logical_ip, err := c.ovnLegacyClient.GetNatIPInfo(nat)
if err != nil {
klog.Errorf("failed to get nat ip info for vpc %s, %v", vpc.Name, err)
return err
}
if logical_ip != "" {
targetRoutes = append(targetRoutes, &kubeovnv1.StaticRoute{
Policy: kubeovnv1.PolicySrc,
CIDR: logical_ip,
NextHopIP: nextHop,
})
}
}
}
}
}

routeNeedDel, routeNeedAdd, err := diffStaticRoute(existRoute, targetRoutes)
Expand Down
30 changes: 30 additions & 0 deletions pkg/ovs/ovn-nbctl-legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2737,3 +2737,33 @@ func (c LegacyClient) SetAclLog(pgName string, logEnable, isIngress bool) error

return nil
}

func (c *LegacyClient) GetRouterNat(routerName string) ([]string, error) {
var nat []string
results, err := c.CustomFindEntity("logical-router", []string{"nat"}, fmt.Sprintf("name=%s", routerName))
if err != nil {
klog.Errorf("customFindEntity failed, %v", err)
return nat, err
}
if len(results) == 0 {
return nat, nil
}

return results[0]["nat"], nil
}

func (c *LegacyClient) GetNatIPInfo(uuid string) (string, error) {
var logical_ip string

output, err := c.ovnNbCommand("--data=bare", "--format=csv", "--no-heading", "--columns=logical_ip", "list", "nat", uuid)
if err != nil {
klog.Errorf("failed to list nat, %v", err)
return logical_ip, err
}
lines := strings.Split(output, "\n")

if len(lines) > 0 {
logical_ip = strings.TrimSpace(lines[0])
}
return logical_ip, nil
}

0 comments on commit 33da205

Please sign in to comment.