Skip to content

Commit

Permalink
Merge pull request #1522 from sjoerdsimons/wip/sjoerd/localregistry
Browse files Browse the repository at this point in the history
Add dual-stack support to the etcd registry
  • Loading branch information
manuelbuil authored Feb 21, 2022
2 parents e8339a6 + b0e74be commit 4faee72
Show file tree
Hide file tree
Showing 14 changed files with 324 additions and 98 deletions.
18 changes: 15 additions & 3 deletions Documentation/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ The value of the config is a JSON dictionary with the following keys:

* `Network` (string): IPv4 network in CIDR format to use for the entire flannel network. (This is the only mandatory key.)

* `IPv6Network` (string): IPv6 network in CIDR format to use for the entire flannel network. (Mandatory if EnableIPv6 is true)

* `EnableIPv6` (bool): Enables ipv6 support

* `SubnetLen` (integer): The size of the subnet allocated to each host.
Defaults to 24 (i.e. /24) unless `Network` was configured to be smaller than a /24 in which case it is one less than the network.

Expand All @@ -20,6 +24,15 @@ The value of the config is a JSON dictionary with the following keys:
* `SubnetMax` (string): The end of the IP range at which the subnet allocation should end with.
Defaults to the last subnet of `Network`.

* `IPv6SubnetLen` (integer): The size of the ipv6 subnet allocated to each host.
Defaults to 64 (i.e. /64) unless `Ipv6Network` was configured to be smaller than a /64 in which case it is two less than the network.

* `IPv6SubnetMin` (string): The beginning of IPv6 range which the subnet allocation should start with.
Defaults to the first subnet of `Ipv6Network`.

* `IPv6SubnetMax` (string): The end of the IPv6 range at which the subnet allocation should end with.
Defaults to the last subnet of `Ipv6Network`.

* `Backend` (dictionary): Type of backend to use and specific configurations for that backend.
The list of available backends and the keys that can be put into the this dictionary are listed below.
Defaults to `udp` backend.
Expand Down Expand Up @@ -83,7 +96,7 @@ Set `healthz-port` to a non-zero value will enable a healthz server for flannel.
## Dual-stack
Flannel supports the dual-stack mode of Kubernetes. This means pods and services could use ipv4 and ipv6 at the same time. Currently, dual-stack is only supported for kube subnet manager and vxlan, wireguard or host-gw(linux) backend.
Flannel supports dual-stack mode. This means pods and services could use ipv4 and ipv6 at the same time. Currently, dual-stack is only supported for vxlan, wireguard or host-gw(linux) backends.
Requirements:
* v1.0.1 of flannel binary from [containernetworking/plugins](https://github.com/containernetworking/plugins)
Expand All @@ -92,8 +105,7 @@ Requirements:
* vxlan support ipv6 tunnel require kernel version >= 3.12
Configuration:
* Set flanneld daemon with "--kube-subnet-mgr" CLI option
* Set "EnableIPv6": true and the "IPv6Network", for example "IPv6Network": "2001:cafe:42:0::/56" in the net-conf.json of the kube-flannel-cfg ConfigMap
* Set "EnableIPv6": true and the "IPv6Network", for example "IPv6Network": * "2001:cafe:42:0::/56" in the net-conf.json of the kube-flannel-cfg ConfigMap or in `/coreos.com/network/config` for etcd
If everything works as expected, flanneld should generate a `/run/flannel/subnet.env` file with IPV6 subnet and network. For example:
Expand Down
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,9 @@ func newSubnetManager(ctx context.Context) (subnet.Manager, error) {

// Attempt to renew the lease for the subnet specified in the subnetFile
prevSubnet := ReadCIDRFromSubnetFile(opts.subnetFile, "FLANNEL_SUBNET")
prevIPv6Subnet := ReadIP6CIDRFromSubnetFile(opts.subnetFile, "FLANNEL_IPV6_SUBNET")

return etcdv2.NewLocalManager(cfg, prevSubnet)
return etcdv2.NewLocalManager(cfg, prevSubnet, prevIPv6Subnet)
}

func main() {
Expand Down Expand Up @@ -473,7 +474,8 @@ func MonitorLease(ctx context.Context, sm subnet.Manager, bn backend.Network, wg

wg.Add(1)
go func() {
subnet.WatchLease(ctx, sm, bn.Lease().Subnet, evts)
l := bn.Lease()
subnet.WatchLease(ctx, sm, l.Subnet, l.IPv6Subnet, evts)
wg.Done()
}()

Expand Down
6 changes: 5 additions & 1 deletion pkg/ip/ip6net.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ func (ip6 *IP6) UnmarshalJSON(j []byte) error {
}
}

func (ip6 *IP6) Cmp(other *IP6) int {
return (*big.Int)(ip6).Cmp((*big.Int)(other))
}

// similar to net.IPNet but has uint based representation
type IP6Net struct {
IP *IP6
Expand Down Expand Up @@ -190,7 +194,7 @@ func (n IP6Net) Contains(ip *IP6) bool {
}

func (n IP6Net) Empty() bool {
return n.IP == (*IP6)(big.NewInt(0)) && n.PrefixLen == uint(0)
return IsEmpty(n.IP) && n.PrefixLen == uint(0)
}

// MarshalJSON: json.Marshaler impl
Expand Down
29 changes: 29 additions & 0 deletions pkg/ip/ip6net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ func TestIP6(t *testing.T) {
t.Error("FromIP6 failed")
}

nip = net.ParseIP("::")
ip = FromIP6(nip)
ipStr = ip.String()
if ipStr != "::" {
t.Error(":: FromIP6 failed")
}

if !IsEmpty(ip) {
t.Error("IsEmpty failed")
}

ip, err := ParseIP6("fc00::1")
if err != nil {
t.Error("ParseIP6 failed with: ", err)
Expand All @@ -67,7 +78,25 @@ func TestIP6(t *testing.T) {
}

func TestIP6Net(t *testing.T) {
var n IP6Net
if !n.Empty() {
t.Error("Empty failed")
}

n = mkIP6Net("::", 0)
if !n.Empty() {
t.Error("::/0 Empty failed")
}

n = mkIP6Net("::", 64)
if n.Empty() {
t.Error("::/64 Empty failed")
}

n1 := mkIP6Net("fc00:1::", 64)
if n1.Empty() {
t.Error("fc00:1::/64 Empty failed")
}

if n1.ToIPNet().String() != "fc00:1::/64" {
t.Error("ToIPNet failed")
Expand Down
Loading

0 comments on commit 4faee72

Please sign in to comment.