From a095672d0531d5cfa9fc6f155694380e4bfd52f1 Mon Sep 17 00:00:00 2001 From: dolibali Date: Mon, 16 Dec 2024 05:42:45 +0000 Subject: [PATCH] fix some normative issues 24.12.16 Signed-off-by: dolibali --- pkg/controller/node.go | 12 ++++++------ pkg/daemon/init.go | 10 +++++----- pkg/ovs/ovn-nb-logical_router_policy.go | 1 + 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/pkg/controller/node.go b/pkg/controller/node.go index 343d6731685..6a9ae25312c 100644 --- a/pkg/controller/node.go +++ b/pkg/controller/node.go @@ -1044,12 +1044,6 @@ func (c *Controller) addPolicyRouteForLocalDNSCacheOnNode(dnsIPs []string, nodeP return c.deletePolicyRouteForLocalDNSCacheOnNode(nodeName, af) } - policies, err := c.OVNNbClient.GetLogicalRouterPoliciesByExtID(c.config.ClusterRouter, "node", nodeName) - if err != nil { - klog.Errorf("failed to list logical router policies with external-ids:node = %q: %v", nodeName, err) - return err - } - var ( externalIDs = map[string]string{ "vendor": util.CniTypeName, @@ -1066,6 +1060,12 @@ func (c *Controller) addPolicyRouteForLocalDNSCacheOnNode(dnsIPs []string, nodeP matches.Add(fmt.Sprintf("ip%d.src == $%s && ip%d.dst == %s", af, pgAs, af, ip)) } + policies, err := c.OVNNbClient.GetLogicalRouterPoliciesByExtID(c.config.ClusterRouter, "node", nodeName) + if err != nil { + klog.Errorf("failed to list logical router policies with external-ids:node = %q: %v", nodeName, err) + return err + } + for _, policy := range policies { if len(policy.ExternalIDs) == 0 || policy.ExternalIDs["vendor"] != util.CniTypeName || policy.ExternalIDs["isLocalDnsCache"] != "true" { continue diff --git a/pkg/daemon/init.go b/pkg/daemon/init.go index 2b3ed3bc3e6..00ecb75b71a 100644 --- a/pkg/daemon/init.go +++ b/pkg/daemon/init.go @@ -52,7 +52,7 @@ func InitOVSBridges() (map[string]string, error) { // InitNodeGateway init ovn0 func InitNodeGateway(config *Configuration) error { - var portName, ip, cidr, macAddr, gw, ipAddr string + var portName, ip, joinCIDR, macAddr, gw, ipAddr string for { nodeName := config.NodeName node, err := config.KubeClient.CoreV1().Nodes().Get(context.Background(), nodeName, metav1.GetOptions{}) @@ -72,7 +72,7 @@ func InitNodeGateway(config *Configuration) error { } macAddr = node.Annotations[util.MacAddressAnnotation] ip = node.Annotations[util.IPAddressAnnotation] - cidr = node.Annotations[util.CidrAnnotation] + joinCIDR = node.Annotations[util.CidrAnnotation] portName = node.Annotations[util.PortNameAnnotation] gw = node.Annotations[util.GatewayAnnotation] break @@ -82,12 +82,12 @@ func InitNodeGateway(config *Configuration) error { return fmt.Errorf("failed to parse mac %s %w", mac, err) } - ipAddr, err = util.GetIPAddrWithMask(ip, cidr) + ipAddr, err = util.GetIPAddrWithMask(ip, joinCIDR) if err != nil { - klog.Errorf("failed to get ip %s with mask %s, %v", ip, cidr, err) + klog.Errorf("failed to get ip %s with mask %s, %v", ip, joinCIDR, err) return err } - return configureNodeNic(portName, ipAddr, gw, cidr, mac, config.MTU) + return configureNodeNic(portName, ipAddr, gw, joinCIDR, mac, config.MTU) } func InitMirror(config *Configuration) error { diff --git a/pkg/ovs/ovn-nb-logical_router_policy.go b/pkg/ovs/ovn-nb-logical_router_policy.go index 97f9a10ba84..c8427bb4fdb 100644 --- a/pkg/ovs/ovn-nb-logical_router_policy.go +++ b/pkg/ovs/ovn-nb-logical_router_policy.go @@ -29,6 +29,7 @@ func (c *OVNNbClient) AddLogicalRouterPolicy(lrName string, priority int, match, return fmt.Errorf("get policy priority %d match %s in logical router %s: %w", priority, match, lrName, err) } + // Same priority, same match, only retain the first policy duplicate := make([]string, 0, len(policyList)) var policyFound *ovnnb.LogicalRouterPolicy for _, policy := range policyList {