Skip to content

Commit

Permalink
fix: now route with connected/static will all be sync (#2231)
Browse files Browse the repository at this point in the history
  • Loading branch information
lut777 authored Jan 9, 2023
1 parent c2467d2 commit 25f8973
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 40 deletions.
80 changes: 42 additions & 38 deletions pkg/controller/ovn-ic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/kubeovn/kube-ovn/pkg/ovsdb/ovnnb"
"os"
"os/exec"
"reflect"
Expand All @@ -16,7 +17,6 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"

"github.com/kubeovn/kube-ovn/pkg/ovsdb/ovnnb"
"github.com/kubeovn/kube-ovn/pkg/util"
)

Expand Down Expand Up @@ -396,20 +396,57 @@ func genHostAddress(host string, port string) (hostAddress string) {
}

func (c *Controller) SynRouteToPolicy() {
c.syncOneRouteToPolicy(util.OvnICKey, util.OvnICConnected)
c.syncOneRouteToPolicy(util.OvnICKey, util.OvnICStatic)
}

func (c *Controller) RemoveOldChassisInSbDB() error {
azUUID, err := c.ovnLegacyClient.GetAzUUID(lastIcCm["az-name"])
if err != nil {
klog.Errorf("failed to get UUID of AZ %s: %v", lastIcCm["az-name"], err)
}

gateways, err := c.ovnLegacyClient.GetGatewayUUIDsInOneAZ(azUUID)
if err != nil {
klog.Errorf("failed to get gateway UUIDs in AZ %s: %v", azUUID, err)
}

routes, err := c.ovnLegacyClient.GetRouteUUIDsInOneAZ(azUUID)
if err != nil {
klog.Errorf("failed to get route UUIDs in AZ %s: %v", azUUID, err)
}

c.ovnLegacyClient.DestroyGateways(gateways)
c.ovnLegacyClient.DestroyRoutes(routes)
if err := c.ovnLegacyClient.DestroyChassis(azUUID); err != nil {
return err
}
return nil
}

func stripPrefix(policyMatch string) (string, error) {
matches := strings.Split(policyMatch, "==")
if strings.Trim(matches[0], " ") == util.MatchV4Dst {
return strings.Trim(matches[1], " "), nil
} else {
return "", fmt.Errorf("policy %s is mismatched", policyMatch)
}
}

func (c *Controller) syncOneRouteToPolicy(key, value string) {
lr, err := c.ovnClient.GetLogicalRouter(util.DefaultVpc, false)
if err != nil {
klog.Errorf("logical router does not exist %v at %v", err, time.Now())
return
}
lrRouteList, err := c.ovnClient.GetLogicalRouterRouteByOpts(util.OvnICKey, util.OvnICValue)
lrRouteList, err := c.ovnClient.GetLogicalRouterRouteByOpts(key, value)
if err != nil {
klog.Errorf("failed to list lr ovn-ic route %v", err)
return
}
if len(lrRouteList) == 0 {
klog.V(5).Info(" lr ovn-ic route does not exist")
lrPolicyList, err := c.ovnClient.GetLogicalRouterPoliciesByExtID(util.OvnICKey, util.OvnICValue)
lrPolicyList, err := c.ovnClient.GetLogicalRouterPoliciesByExtID(key, value)
if err != nil {
klog.Errorf("failed to list ovn-ic lr policy ", err)
return
Expand All @@ -423,7 +460,7 @@ func (c *Controller) SynRouteToPolicy() {
}

policyMap := map[string]string{}
lrPolicyList, err := c.ovnClient.GetLogicalRouterPoliciesByExtID(util.OvnICKey, util.OvnICValue)
lrPolicyList, err := c.ovnClient.GetLogicalRouterPoliciesByExtID(key, value)
if err != nil {
klog.Errorf("failed to list ovn-ic lr policy ", err)
return
Expand All @@ -443,7 +480,7 @@ func (c *Controller) SynRouteToPolicy() {
matchFiled := util.MatchV4Dst + " == " + lrRoute.IPPrefix
if err := c.ovnClient.AddRouterPolicy(lr, matchFiled, ovnnb.LogicalRouterPolicyActionAllow,
map[string]string{},
map[string]string{util.OvnICKey: util.OvnICValue, "vendor": util.CniTypeName},
map[string]string{key: value, "vendor": util.CniTypeName},
util.OvnICPolicyPriority); err != nil {
klog.Errorf("adding router policy failed %v", err)
}
Expand All @@ -455,36 +492,3 @@ func (c *Controller) SynRouteToPolicy() {
}
}
}

func (c *Controller) RemoveOldChassisInSbDB() error {
azUUID, err := c.ovnLegacyClient.GetAzUUID(lastIcCm["az-name"])
if err != nil {
klog.Errorf("failed to get UUID of AZ %s: %v", lastIcCm["az-name"], err)
}

gateways, err := c.ovnLegacyClient.GetGatewayUUIDsInOneAZ(azUUID)
if err != nil {
klog.Errorf("failed to get gateway UUIDs in AZ %s: %v", azUUID, err)
}

routes, err := c.ovnLegacyClient.GetRouteUUIDsInOneAZ(azUUID)
if err != nil {
klog.Errorf("failed to get route UUIDs in AZ %s: %v", azUUID, err)
}

c.ovnLegacyClient.DestroyGateways(gateways)
c.ovnLegacyClient.DestroyRoutes(routes)
if err := c.ovnLegacyClient.DestroyChassis(azUUID); err != nil {
return err
}
return nil
}

func stripPrefix(policyMatch string) (string, error) {
matches := strings.Split(policyMatch, "==")
if strings.Trim(matches[0], " ") == util.MatchV4Dst {
return strings.Trim(matches[1], " "), nil
} else {
return "", fmt.Errorf("policy %s is mismatched", policyMatch)
}
}
5 changes: 3 additions & 2 deletions pkg/util/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,9 @@ const (
AttachmentProvider = "ovn.kubernetes.io/attachmentprovider"
LbSvcPodImg = "ovn.kubernetes.io/lb_svc_img"

OvnICKey = "origin"
OvnICValue = "connected"
OvnICKey = "origin"
OvnICConnected = "connected"
OvnICStatic = "static"

MatchV4Src = "ip4.src"
MatchV4Dst = "ip4.dst"
Expand Down

0 comments on commit 25f8973

Please sign in to comment.