Skip to content

Commit

Permalink
Merge pull request #52 from luckymrwang/calico
Browse files Browse the repository at this point in the history
support more than one podCIDR
  • Loading branch information
njucjc authored Jul 13, 2022
2 parents 9d195fd + fb8cefd commit 7cfcc40
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 55 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion pkg/k8s/engine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
102 changes: 52 additions & 50 deletions pkg/networkengine/routedriver/vxlan/vxlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit 7cfcc40

Please sign in to comment.