diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index ab5256493bb..a38858ab31c 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -86,7 +86,7 @@ func NewController( controller := &Controller{ config: config, - ovnClient: ovs.NewClient(config.OvnNbHost, config.OvnNbPort, "", 0, config.ClusterRouter, config.ClusterTcpLoadBalancer, config.ClusterUdpLoadBalancer, config.NodeSwitchCIDR), + ovnClient: ovs.NewClient(config.OvnNbHost, config.OvnNbPort, "", 0, config.ClusterRouter, config.ClusterTcpLoadBalancer, config.ClusterUdpLoadBalancer, config.NodeSwitch, config.NodeSwitchCIDR), kubeclientset: config.KubeClient, podsLister: podInformer.Lister(), diff --git a/pkg/controller/init.go b/pkg/controller/init.go index a44fcd47035..1477979d8d6 100644 --- a/pkg/controller/init.go +++ b/pkg/controller/init.go @@ -50,7 +50,7 @@ func InitDefaultLogicalSwitch(config *Configuration) error { } func InitNodeSwitch(config *Configuration) error { - client := ovs.NewClient(config.OvnNbHost, config.OvnNbPort, "", 0, config.ClusterRouter, config.ClusterTcpLoadBalancer, config.ClusterUdpLoadBalancer, config.NodeSwitchCIDR) + client := ovs.NewClient(config.OvnNbHost, config.OvnNbPort, "", 0, config.ClusterRouter, config.ClusterTcpLoadBalancer, config.ClusterUdpLoadBalancer, config.NodeSwitch, config.NodeSwitchCIDR) ss, err := client.ListLogicalSwitch() if err != nil { return err @@ -62,7 +62,7 @@ func InitNodeSwitch(config *Configuration) error { } } - err = client.CreateLogicalSwitch(config.NodeSwitch, config.NodeSwitchCIDR, config.NodeSwitchGateway, config.NodeSwitchGateway, "") + err = client.CreateLogicalSwitch(config.NodeSwitch, config.NodeSwitchCIDR, config.NodeSwitchGateway, config.NodeSwitchGateway) if err != nil { return err } @@ -70,7 +70,7 @@ func InitNodeSwitch(config *Configuration) error { } func InitClusterRouter(config *Configuration) error { - client := ovs.NewClient(config.OvnNbHost, config.OvnNbPort, "", 0, config.ClusterRouter, config.ClusterTcpLoadBalancer, config.ClusterUdpLoadBalancer, config.NodeSwitchCIDR) + client := ovs.NewClient(config.OvnNbHost, config.OvnNbPort, "", 0, config.ClusterRouter, config.ClusterTcpLoadBalancer, config.ClusterUdpLoadBalancer, config.NodeSwitch, config.NodeSwitchCIDR) lrs, err := client.ListLogicalRouter() if err != nil { return err @@ -85,7 +85,7 @@ func InitClusterRouter(config *Configuration) error { } func InitLoadBalancer(config *Configuration) error { - client := ovs.NewClient(config.OvnNbHost, config.OvnNbPort, "", 0, config.ClusterRouter, config.ClusterTcpLoadBalancer, config.ClusterUdpLoadBalancer, config.NodeSwitchCIDR) + client := ovs.NewClient(config.OvnNbHost, config.OvnNbPort, "", 0, config.ClusterRouter, config.ClusterTcpLoadBalancer, config.ClusterUdpLoadBalancer, config.NodeSwitch, config.NodeSwitchCIDR) tcpLb, err := client.FindLoadbalancer(config.ClusterTcpLoadBalancer) if err != nil { return fmt.Errorf("failed to find tcp lb %v", err) @@ -119,7 +119,7 @@ func InitLoadBalancer(config *Configuration) error { } func InitDnsTable(config *Configuration) error { - client := ovs.NewClient(config.OvnNbHost, config.OvnNbPort, "", 0, config.ClusterRouter, config.ClusterTcpLoadBalancer, config.ClusterUdpLoadBalancer, config.NodeSwitchCIDR) + client := ovs.NewClient(config.OvnNbHost, config.OvnNbPort, "", 0, config.ClusterRouter, config.ClusterTcpLoadBalancer, config.ClusterUdpLoadBalancer, config.NodeSwitch, config.NodeSwitchCIDR) uuid, err := client.CreateDnsTable() if err != nil { return err diff --git a/pkg/controller/namespace.go b/pkg/controller/namespace.go index 9f10f2d4b33..0b1cce80098 100644 --- a/pkg/controller/namespace.go +++ b/pkg/controller/namespace.go @@ -198,7 +198,7 @@ func (c *Controller) handleAddNamespace(key string) error { excludeIps = gateway } // If multiple namespace use same ls name, only first one will success - err = c.ovnClient.CreateLogicalSwitch(ls, cidr, gateway, excludeIps, ns.Name) + err = c.ovnClient.CreateLogicalSwitch(ls, cidr, gateway, excludeIps) if err != nil { return err } diff --git a/pkg/daemon/controller.go b/pkg/daemon/controller.go index a64f3db3940..d7063f6bf63 100644 --- a/pkg/daemon/controller.go +++ b/pkg/daemon/controller.go @@ -45,7 +45,7 @@ type Controller struct { func NewController(config *Configuration, informerFactory informers.SharedInformerFactory) (*Controller, error) { namespaceInformer := informerFactory.Core().V1().Namespaces() podInformer := informerFactory.Core().V1().Pods() - ovnClient := ovs.NewClient(config.OvnNbHost, config.OvnNbPort, config.OvnSbHost, config.OvnSbPort, "", "", "", "") + ovnClient := ovs.NewClient(config.OvnNbHost, config.OvnNbPort, config.OvnSbHost, config.OvnSbPort, "", "", "", "", "") iptablesMgr, err := iptables.New() if err != nil { return nil, err diff --git a/pkg/ovs/ovn-nbctl.go b/pkg/ovs/ovn-nbctl.go index ef891858d42..28b86264139 100644 --- a/pkg/ovs/ovn-nbctl.go +++ b/pkg/ovs/ovn-nbctl.go @@ -158,12 +158,11 @@ func (c Client) CreateOutsideLogicalSwitch(ls, edgeLr, ip, mac string) error { return nil } -func (c Client) CreateLogicalSwitch(ls, subnet, gateway, excludeIps, namespace string) error { +func (c Client) CreateLogicalSwitch(ls, subnet, gateway, excludeIps string) error { _, err := c.ovnNbCommand(WaitSb, MayExist, "ls-add", ls, "--", "set", "logical_switch", ls, fmt.Sprintf("other_config:subnet=%s", subnet), "--", "set", "logical_switch", ls, fmt.Sprintf("other_config:gateway=%s", gateway), "--", - "set", "logical_switch", ls, fmt.Sprintf("other_config:exclude_ips=%s", excludeIps), "--", - "set", "logical_switch", ls, fmt.Sprintf("other_config:namespace=%s", namespace)) + "set", "logical_switch", ls, fmt.Sprintf("other_config:exclude_ips=%s", excludeIps)) if err != nil { klog.Errorf("create switch %s failed %v", ls, err) return err @@ -190,12 +189,16 @@ func (c Client) CreateLogicalSwitch(ls, subnet, gateway, excludeIps, namespace s return err } - err = c.AddDnsTableToLogicalSwitch(ls) - if err != nil { - klog.Errorf("failed to add cluster dns to %s, %v", ls, err) - return err + // DO NOT add ovn dns to node switch + if ls != c.NodeSwitch { + err = c.AddDnsTableToLogicalSwitch(ls) + if err != nil { + klog.Errorf("failed to add cluster dns to %s, %v", ls, err) + return err + } } - return err + + return nil } func (c Client) ListLogicalSwitch() ([]string, error) { diff --git a/pkg/ovs/ovn.go b/pkg/ovs/ovn.go index 1b16b8904fa..95f6b295ab2 100644 --- a/pkg/ovs/ovn.go +++ b/pkg/ovs/ovn.go @@ -16,6 +16,7 @@ type Client struct { ClusterRouter string ClusterTcpLoadBalancer string ClusterUdpLoadBalancer string + NodeSwitch string NodeSwitchCIDR string } @@ -32,13 +33,14 @@ const ( var GlobalDnsTable string -func NewClient(ovnNbHost string, ovnNbPort int, ovnSbHost string, ovnSbPort int, clusterRouter, clusterTcpLoadBalancer, clusterUdpLoadBalancer, nodeSwitchCIDR string) *Client { +func NewClient(ovnNbHost string, ovnNbPort int, ovnSbHost string, ovnSbPort int, clusterRouter, clusterTcpLoadBalancer, clusterUdpLoadBalancer, nodeSwitch, nodeSwitchCIDR string) *Client { return &Client{ OvnNbAddress: fmt.Sprintf("tcp:%s:%d", ovnNbHost, ovnNbPort), OvnSbAddress: fmt.Sprintf("tcp:%s:%d", ovnSbHost, ovnSbPort), ClusterRouter: clusterRouter, ClusterTcpLoadBalancer: clusterTcpLoadBalancer, ClusterUdpLoadBalancer: clusterUdpLoadBalancer, + NodeSwitch: nodeSwitch, NodeSwitchCIDR: nodeSwitchCIDR, } }