diff --git a/go.mod b/go.mod index 098f5df..3a0ad71 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.16 require ( github.com/EvilSuperstars/go-cidrman v0.0.0-20190607145828-28e79e32899a - github.com/openyurtio/raven-controller-manager v0.1.1-0.20220622025909-98a46a8e8e07 + github.com/openyurtio/raven-controller-manager v0.1.1-0.20220712045115-14910b0bce36 github.com/pkg/errors v0.9.1 github.com/spf13/cobra v1.5.0 github.com/spf13/pflag v1.0.5 diff --git a/go.sum b/go.sum index 4c54348..ab2bfdb 100644 --- a/go.sum +++ b/go.sum @@ -410,8 +410,8 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y github.com/onsi/gomega v1.17.0 h1:9Luw4uT5HTjHTN8+aNcSThgH1vdXnmdJ8xIfZ4wyTRE= github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= -github.com/openyurtio/raven-controller-manager v0.1.1-0.20220622025909-98a46a8e8e07 h1:4ruf6GdKyrLtjKjvfy+HfdoYqSNGVGxtgOPXpg7VX6g= -github.com/openyurtio/raven-controller-manager v0.1.1-0.20220622025909-98a46a8e8e07/go.mod h1:ulMo3cK5muXSEuu0ZHt5CVW6e0KX2zqwILINSq88EUE= +github.com/openyurtio/raven-controller-manager v0.1.1-0.20220712045115-14910b0bce36 h1:HW8NZch3pBHxzYknwga5Wcf3LvcZ7Z5AxHdb0SWQFD4= +github.com/openyurtio/raven-controller-manager v0.1.1-0.20220712045115-14910b0bce36/go.mod h1:QkKI16Qr4wECtjA6e9QV4bNUmQj4zPEJNbz0tYvqdA0= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= @@ -499,7 +499,6 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.3/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= diff --git a/pkg/k8s/engine_controller.go b/pkg/k8s/engine_controller.go index f028dde..5dac50b 100644 --- a/pkg/k8s/engine_controller.go +++ b/pkg/k8s/engine_controller.go @@ -122,7 +122,7 @@ func (c *EngineController) processNextWorkItem() bool { func getMergedSubnets(nodeInfo []v1alpha1.NodeInfo) []string { subnets := make([]string, 0) for _, n := range nodeInfo { - subnets = append(subnets, n.Subnet) + subnets = append(subnets, n.Subnets...) } subnets, _ = cidrman.MergeCIDRs(subnets) return subnets diff --git a/pkg/networkengine/routedriver/vxlan/vxlan.go b/pkg/networkengine/routedriver/vxlan/vxlan.go index 0385def..9321557 100644 --- a/pkg/networkengine/routedriver/vxlan/vxlan.go +++ b/pkg/networkengine/routedriver/vxlan/vxlan.go @@ -232,34 +232,34 @@ func setSysctl(path string, contents []byte) error { // ip route add {remote_subnet} via {local_gateway_raven0_ip} dev raven0 src {node_cni_ip} onlink mtu {mtu} table {routeTableID} func (vx *vxlan) calRouteOnNonGateway(network *types.Network) map[string]*netlink.Route { routes := make(map[string]*netlink.Route) - var src net.IP - srcCIDR := vx.nodeInfo(network).Subnet - src, _, err := net.ParseCIDR(srcCIDR) - if err != nil { - klog.ErrorS(err, "error parsing cidr", "cidr", srcCIDR) - return routes - } + for _, srcCIDR := range vx.nodeInfo(network).Subnets { + src, _, err := net.ParseCIDR(srcCIDR) + if err != nil { + klog.ErrorS(err, "error parsing cidr", "cidr", srcCIDR) + return routes + } - via := vxlanIP(net.ParseIP(network.LocalEndpoint.PrivateIP)) - for _, v := range network.RemoteEndpoints { - for _, dstCIDR := range v.Subnets { - _, ipnet, err := net.ParseCIDR(dstCIDR) - if err != nil { - klog.ErrorS(err, "error parsing cidr", "cidr", dstCIDR) - continue - } - nr := &netlink.Route{ - LinkIndex: vx.vxlanIface.Attrs().Index, - Scope: netlink.SCOPE_UNIVERSE, - Dst: ipnet, - Gw: via, - Table: routeTableID, - Src: src, - Flags: int(netlink.FLAG_ONLINK), - // TODO should minus vpn mtu OverHead - MTU: vx.vxlanIface.Attrs().MTU, + via := vxlanIP(net.ParseIP(network.LocalEndpoint.PrivateIP)) + for _, v := range network.RemoteEndpoints { + for _, dstCIDR := range v.Subnets { + _, ipnet, err := net.ParseCIDR(dstCIDR) + if err != nil { + klog.ErrorS(err, "error parsing cidr", "cidr", dstCIDR) + continue + } + nr := &netlink.Route{ + LinkIndex: vx.vxlanIface.Attrs().Index, + Scope: netlink.SCOPE_UNIVERSE, + Dst: ipnet, + Gw: via, + Table: routeTableID, + Src: src, + Flags: int(netlink.FLAG_ONLINK), + // TODO should minus vpn mtu OverHead + MTU: vx.vxlanIface.Attrs().MTU, + } + routes[networkutil.RouteKey(nr)] = nr } - routes[networkutil.RouteKey(nr)] = nr } } return routes @@ -287,22 +287,24 @@ func (vx *vxlan) calRouteOnGateway(network *types.Network) map[string]*netlink.R if types.NodeName(v.NodeName) == vx.nodeName { continue } - _, dst, err := net.ParseCIDR(v.Subnet) - if err != nil { - klog.ErrorS(err, "error parsing cidr", "cidr", dst) - continue - } - via := vxlanIP(net.ParseIP(v.PrivateIP)) - nr := &netlink.Route{ - LinkIndex: vx.vxlanIface.Attrs().Index, - Scope: netlink.SCOPE_UNIVERSE, - Dst: dst, - Gw: via, - Table: routeTableID, - Flags: int(netlink.FLAG_ONLINK), - MTU: vx.vxlanIface.Attrs().MTU, + for _, dstCIDR := range v.Subnets { + _, dst, err := net.ParseCIDR(dstCIDR) + if err != nil { + klog.ErrorS(err, "error parsing cidr", "cidr", dst) + continue + } + via := vxlanIP(net.ParseIP(v.PrivateIP)) + nr := &netlink.Route{ + LinkIndex: vx.vxlanIface.Attrs().Index, + Scope: netlink.SCOPE_UNIVERSE, + Dst: dst, + Gw: via, + Table: routeTableID, + Flags: int(netlink.FLAG_ONLINK), + MTU: vx.vxlanIface.Attrs().MTU, + } + routes[networkutil.RouteKey(nr)] = nr } - routes[networkutil.RouteKey(nr)] = nr } return routes } @@ -314,21 +316,21 @@ func (vx *vxlan) calRouteOnGateway(network *types.Network) map[string]*netlink.R func (vx *vxlan) calRulesOnGateway(network *types.Network) map[string]*netlink.Rule { rules := make(map[string]*netlink.Rule) for _, v := range network.RemoteNodeInfo { - var srcCIDR *net.IPNet - var err error nodeInfo := network.RemoteNodeInfo[types.NodeName(v.NodeName)] if nodeInfo == nil { klog.Errorf("node %s not found in RemoteNodeInfo", v.NodeName) continue } - _, srcCIDR, err = net.ParseCIDR(nodeInfo.Subnet) - if err != nil { - klog.ErrorS(err, "error parsing cidr", "cidr", srcCIDR) - continue + for _, srcCIDR := range nodeInfo.Subnets { + _, src, err := net.ParseCIDR(srcCIDR) + if err != nil { + klog.ErrorS(err, "error parsing cidr", "cidr", srcCIDR) + continue + } + rule := networkutil.NewRavenRule(rulePriority, routeTableID) + rule.Src = src + rules[networkutil.RuleKey(rule)] = rule } - rule := networkutil.NewRavenRule(rulePriority, routeTableID) - rule.Src = srcCIDR - rules[networkutil.RuleKey(rule)] = rule } return rules }