Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: now route with connected/static will all be sync #2231

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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