Skip to content

Commit

Permalink
add build for dualstack
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhen-ma committed Dec 11, 2020
1 parent 46cfad7 commit e2cd787
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 23 deletions.
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ kind-install-ipv6:
kubectl taint node kube-ovn-control-plane node-role.kubernetes.io/master:NoSchedule-
ENABLE_SSL=true IPv6=true dist/images/install.sh

kind-init-dual:
kind delete cluster --name=kube-ovn
kube_proxy_mode=iptables ip_family=DualStack ha=false j2 yamls/kind.yaml.j2 -o yamls/kind.yaml
kind create cluster --config yamls/kind.yaml --name kube-ovn
kubectl describe no
docker exec kube-ovn-control-plane ip link add link eth0 mac1 type macvlan
docker exec kube-ovn-worker ip link add link eth0 mac1 type macvlan
docker exec kube-ovn-worker sysctl -w net.ipv6.conf.all.disable_ipv6=0
docker exec kube-ovn-control-plane sysctl -w net.ipv6.conf.all.disable_ipv6=0

kind-install-dual:
kind load docker-image --name kube-ovn ${REGISTRY}/kube-ovn:${RELEASE_TAG}
kubectl taint node kube-ovn-control-plane node-role.kubernetes.io/master:NoSchedule-
ENABLE_SSL=true DualStack=true dist/images/install.sh
kubectl describe no

kind-reload:
kind load docker-image --name kube-ovn ${REGISTRY}/kube-ovn:${RELEASE_TAG}
kubectl delete pod -n kube-system -l app=kube-ovn-controller
Expand Down
10 changes: 9 additions & 1 deletion dist/images/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
set -euo pipefail

IPv6=${IPv6:-false}
DualStack=${DualStack:-false}
ENABLE_SSL=${ENABLE_SSL:-false}
ENABLE_MIRROR=${ENABLE_MIRROR:-false}
HW_OFFLOAD=${HW_OFFLOAD:-false}
Expand All @@ -17,11 +18,18 @@ PINGER_EXTERNAL_ADDRESS="114.114.114.114" # Pinger check external ip probe
PINGER_EXTERNAL_DOMAIN="alauda.cn" # Pinger check external domain probe
if [ "$IPv6" = "true" ]; then
POD_CIDR="fd00:10:16::/64" # Do NOT overlap with NODE/SVC/JOIN CIDR
SVC_CIDR="fd00:10:96::/112" # Do NOT overlap with NODE/POD/JOIN CIDR
SVC_CIDR="fd00:10:96::/112" # Do NOT overlap with NODE/POD/JOIN CIDR
JOIN_CIDR="fd00:100:64::/64" # Do NOT overlap with NODE/POD/SVC CIDR
PINGER_EXTERNAL_ADDRESS="2400:3200::1"
PINGER_EXTERNAL_DOMAIN="google.com"
fi
if [ "$DualStack" = "true" ]; then
POD_CIDR="10.16.0.0/16,fd00:10:16::/64" # Do NOT overlap with NODE/SVC/JOIN CIDR
SVC_CIDR="10.96.0.0/12" # Do NOT overlap with NODE/POD/JOIN CIDR
JOIN_CIDR="100.64.0.0/16,fd00:100:64::/64" # Do NOT overlap with NODE/POD/SVC CIDR
PINGER_EXTERNAL_ADDRESS="114.114.114.114"
PINGER_EXTERNAL_DOMAIN="google.com"
fi

EXCLUDE_IPS="" # EXCLUDE_IPS for default subnet
LABEL="node-role.kubernetes.io/master" # The node label to deploy OVN DB
Expand Down
5 changes: 4 additions & 1 deletion pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,9 @@ func (c *Controller) acquireAddress(pod *v1.Pod, subnet *kubeovnv1.Subnet) (stri

if ok, _ := isStatefulSetPod(pod); !ok {
for _, staticIP := range ipPool {
if c.ipam.IsIPAssignedToPod(staticIP, subnet.Name) {
continue
}
if v4IP, v6IP, mac, err := c.acquireStaticAddress(key, staticIP, macStr, subnet.Name); err == nil {
return v4IP, v6IP, mac, nil
}
Expand Down Expand Up @@ -759,7 +762,7 @@ func (c *Controller) acquireStaticAddress(key, ip, mac, subnet string) (string,
}

if v4IP, v6IP, mac, err = c.ipam.GetStaticAddress(key, ip, mac, subnet); err != nil {
klog.Errorf("failed to get static ip, %v", err)
klog.Errorf("failed to get static ip %v, mac %v, err %v", ip, mac, err)
return "", "", "", err
}
return v4IP, v6IP, mac, nil
Expand Down
25 changes: 17 additions & 8 deletions pkg/daemon/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,12 @@ func (c *Controller) getLocalPodIPsNeedNAT(protocol string) ([]string, error) {
if nsGWNat &&
subnet.Spec.Vpc == util.DefaultVpc &&
nsGWType == kubeovnv1.GWDistributedType &&
pod.Spec.NodeName == hostname &&
util.CheckProtocol(pod.Status.PodIP) == protocol {
localPodIPs = append(localPodIPs, pod.Status.PodIP)
pod.Spec.NodeName == hostname {
if len(pod.Status.PodIPs) == 2 && protocol == kubeovnv1.ProtocolIPv6 {
localPodIPs = append(localPodIPs, pod.Status.PodIPs[1].IP)
} else if util.CheckProtocol(pod.Status.PodIP) == protocol {
localPodIPs = append(localPodIPs, pod.Status.PodIP)
}
}
}

Expand All @@ -303,7 +306,7 @@ func (c *Controller) getSubnetsNeedNAT(protocol string) ([]string, error) {
if subnet.Spec.Vpc == util.DefaultVpc &&
subnet.Spec.GatewayType == kubeovnv1.GWCentralizedType &&
subnet.Status.ActivateGateway == c.config.NodeName &&
subnet.Spec.Protocol == protocol &&
(subnet.Spec.Protocol == kubeovnv1.ProtocolDual || subnet.Spec.Protocol == protocol) &&
subnet.Spec.NatOutgoing {
cidrBlock := getCidrByProtocol(subnet.Spec.CIDRBlock, protocol)
subnetsNeedNat = append(subnetsNeedNat, cidrBlock)
Expand All @@ -313,15 +316,21 @@ func (c *Controller) getSubnetsNeedNAT(protocol string) ([]string, error) {
}

func (c *Controller) getSubnetsCIDR(protocol string) ([]string, error) {
var ret = []string{c.config.ServiceClusterIPRange}
if c.config.NodeLocalDNSIP != "" && net.ParseIP(c.config.NodeLocalDNSIP) != nil {
ret = append(ret, c.config.NodeLocalDNSIP)
}
subnets, err := c.subnetsLister.List(labels.Everything())
if err != nil {
klog.Error("failed to list subnets")
return nil, err
}

ret := make([]string, 0, len(subnets)+3)
if c.config.NodeLocalDNSIP != "" && net.ParseIP(c.config.NodeLocalDNSIP) != nil && util.CheckProtocol(c.config.NodeLocalDNSIP) == protocol {
ret = append(ret, c.config.NodeLocalDNSIP)
}
for _, sip := range strings.Split(c.config.ServiceClusterIPRange, ",") {
if util.CheckProtocol(sip) == protocol {
ret = append(ret, sip)
}
}
for _, subnet := range subnets {
if subnet.Spec.Vpc == util.DefaultVpc {
cidrBlock := getCidrByProtocol(subnet.Spec.CIDRBlock, protocol)
Expand Down
11 changes: 11 additions & 0 deletions pkg/ipam/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,14 @@ func (ipam *IPAM) ContainAddress(address string) bool {
}
return false
}

func (ipam *IPAM) IsIPAssignedToPod(ip, subnetName string) bool {
ipam.mutex.RLock()
defer ipam.mutex.RUnlock()

if subnet, ok := ipam.Subnets[subnetName]; !ok {
return false
} else {
return subnet.isIPAssignedToPod(ip)
}
}
10 changes: 10 additions & 0 deletions pkg/ipam/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,3 +460,13 @@ func (subnet *Subnet) GetPodAddress(podName string) (IP, IP, string, string) {
return v4IP, v6IP, mac, kubeovnv1.ProtocolDual
}
}

func (subnet *Subnet) isIPAssignedToPod(ip string) bool {
if _, ok := subnet.V4IPToPod[IP(ip)]; ok {
return true
}
if _, ok := subnet.V6IPToPod[IP(ip)]; ok {
return true
}
return false
}
5 changes: 3 additions & 2 deletions test/e2e/ip/static_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package ip

import (
"fmt"
"os"
"time"

"github.com/alauda/kube-ovn/pkg/util"
"github.com/alauda/kube-ovn/test/e2e/framework"
. "github.com/onsi/ginkgo"
Expand All @@ -10,8 +13,6 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"os"
"time"
)

var _ = Describe("[IP Allocation]", func() {
Expand Down
11 changes: 0 additions & 11 deletions yamls/kind.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@ networking:
disableDefaultCNI: true
ipFamily: {{ ip_family }}

kubeadmConfigPatches:
- |
kind: ClusterConfiguration
metadata:
name: config
apiServer:
extraArgs:
"feature-gates": "SCTPSupport=true"
etcd:
local:
dataDir: "/tmp/lib/etcd"
nodes:
- role: control-plane
image: kindest/node:v1.19.1
Expand Down

0 comments on commit e2cd787

Please sign in to comment.