diff --git a/dist/functional-test.sh b/dist/functional-test.sh index b93e5853ae..9fd4e046d4 100755 --- a/dist/functional-test.sh +++ b/dist/functional-test.sh @@ -59,9 +59,10 @@ write_config_etcd() { flannel_conf="{ \"Network\": \"$FLANNEL_NET\", \"Backend\": { \"Type\": \"${backend}\" } }" fi - while ! docker run --rm -e ETCDCTL_API=3 $ETCDCTL_IMG etcdctl --endpoints=$etcd_endpt put /coreos.com/network/config "$flannel_conf" >/dev/null + while ! docker run --rm -e ETCDCTL_API=3 $ETCDCTL_IMG etcdctl --endpoints=$etcd_endpt put /coreos.com/network/config "$flannel_conf" do sleep 0.1 + echo "Retrying write_config_etcd with backend $1" done } @@ -70,6 +71,7 @@ create_ping_dest() { for host_num in 1 2; do while ! docker exec flannel-e2e-test-flannel$host_num ls /run/flannel/subnet.env >/dev/null 2>&1; do sleep 0.1 + echo "Retrying create_ping_dest() with host_num=$host_num" done # Use declare to allow the host_num variable to be part of the ping_dest variable name. -g is needed to make it global @@ -133,8 +135,11 @@ pings() { # These perf tests don't actually assert on anything test_hostgw_perf() { + echo "Inside test_hostgw_perf()" write_config_etcd host-gw + echo "In test_hostgw_perf(). write_config_etcd done!" create_ping_dest + echo "In test_hostgw_perf(). Create_ping_dest done!" perf } @@ -172,9 +177,12 @@ test_wireguard_perf() { perf() { # Perf test - run iperf server on flannel1 and client on flannel2 - docker rm -f flannel-e2e-test-flannel1-iperf 2>/dev/null - docker run -d --name flannel-e2e-test-flannel1-iperf --net=container:flannel-e2e-test-flannel1 iperf3:latest >/dev/null + docker rm -f flannel-e2e-test-flannel1-iperf + echo "Inside perf(). docker rm done" + docker run -d --name flannel-e2e-test-flannel1-iperf --net=container:flannel-e2e-test-flannel1 iperf3:latest + echo "Inside perf(). docker run -d done" docker run --rm --net=container:flannel-e2e-test-flannel2 iperf3:latest -c $ping_dest1 -B $ping_dest2 + echo "Inside perf(). docker run -rm done" } test_multi() { diff --git a/main.go b/main.go index a9860a2c38..d34bc4fdef 100644 --- a/main.go +++ b/main.go @@ -628,3 +628,4 @@ func ReadIP6CIDRFromSubnetFile(path string, CIDRKey string) ip.IP6Net { } return prevCIDR } + diff --git a/subnet/etcd/local_manager.go b/subnet/etcd/local_manager.go index 3f358b6fd5..6406ef11f8 100644 --- a/subnet/etcd/local_manager.go +++ b/subnet/etcd/local_manager.go @@ -202,11 +202,8 @@ func (m *LocalManager) allocateSubnet(config *Config, leases []Lease) (ip.IP4Net log.Infof("Picking ipv6 subnet in range %s ... %s", config.IPv6SubnetMin, config.IPv6SubnetMax) } - type IPs struct { - ip ip.IP4 - ip6 *ip.IP6 - } - var availableIPs []IPs + var availableIPs []ip.IP4 + var availableIPv6s []*ip.IP6 sn := ip.IP4Net{IP: config.SubnetMin, PrefixLen: config.SubnetLen} var sn6 ip.IP6Net @@ -216,38 +213,37 @@ func (m *LocalManager) allocateSubnet(config *Config, leases []Lease) (ip.IP4Net OuterLoop: for ; sn.IP <= config.SubnetMax && len(availableIPs) < 100; sn = sn.Next() { - if !sn6.Empty() { - if sn6.IP.Cmp(config.IPv6SubnetMax) >= 0 { - break OuterLoop - } - } for _, l := range leases { if sn.Overlaps(l.Subnet) { continue OuterLoop } - if !sn6.Empty() && sn6.Overlaps(l.IPv6Subnet) { - continue OuterLoop - } } + availableIPs = append(availableIPs, sn.IP) + } - if !sn6.Empty() { - availableIPs = append(availableIPs, IPs{ip: sn.IP, ip6: sn6.IP}) - sn6 = sn6.Next() - } else { - availableIPs = append(availableIPs, IPs{ip: sn.IP, ip6: nil}) + if !sn6.Empty() { + OuterLoopv6: + for ; sn6.IP.Cmp(config.IPv6SubnetMax) <= 0 && len(availableIPv6s) < 100; sn6 = sn6.Next() { + for _, l := range leases { + if sn6.Overlaps(l.IPv6Subnet) { + continue OuterLoopv6 + } + } + availableIPv6s = append(availableIPv6s, sn6.IP) } } - if len(availableIPs) == 0 { + if len(availableIPs) == 0 || (!sn6.Empty() && len(availableIPv6s) == 0) { return ip.IP4Net{}, ip.IP6Net{}, errors.New("out of subnets") } else { i := randInt(0, len(availableIPs)) - ipnet := ip.IP4Net{IP: availableIPs[i].ip, PrefixLen: config.SubnetLen} + ipnet := ip.IP4Net{IP: availableIPs[i], PrefixLen: config.SubnetLen} - if availableIPs[i].ip6 == nil { + if sn6.Empty() { return ipnet, ip.IP6Net{}, nil } - return ipnet, ip.IP6Net{IP: availableIPs[i].ip6, PrefixLen: config.IPv6SubnetLen}, nil + i = randInt(0, len(availableIPv6s)) + return ipnet, ip.IP6Net{IP: availableIPv6s[i], PrefixLen: config.IPv6SubnetLen}, nil } }