Skip to content

Commit

Permalink
fix: remove dns table from nodeswitch and remove unused other_config:…
Browse files Browse the repository at this point in the history
…namespace
  • Loading branch information
oilbeater committed Apr 10, 2019
1 parent 4d26cad commit e999833
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
10 changes: 5 additions & 5 deletions pkg/controller/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -62,15 +62,15 @@ 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
}
return nil
}

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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/daemon/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 11 additions & 8 deletions pkg/ovs/ovn-nbctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/ovs/ovn.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Client struct {
ClusterRouter string
ClusterTcpLoadBalancer string
ClusterUdpLoadBalancer string
NodeSwitch string
NodeSwitchCIDR string
}

Expand All @@ -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,
}
}

0 comments on commit e999833

Please sign in to comment.