feat: add CNI, and pod and service CIDR to configurator

This adds more methods to the Cluster interface that allows for more
granular control of the cluster network settings.

Signed-off-by: Andrew Rynhard <andrew@andrewrynhard.com>
This commit is contained in:
Andrew Rynhard
2019-10-07 18:53:23 -07:00
parent b29391f0be
commit 04313bd48c
7 changed files with 165 additions and 7 deletions

View File

@@ -6,6 +6,8 @@ package net
import (
"net"
"github.com/pkg/errors"
)
// IPAddrs finds and returns a list of non-loopback IPv4 addresses of the
@@ -40,3 +42,24 @@ func FormatAddress(addr string) string {
}
return addr
}
// NthIPInNetwork takes an IPNet and returns the nth IP in it.
func NthIPInNetwork(network *net.IPNet, n int) (net.IP, error) {
ip := network.IP
dst := make([]byte, len(ip))
copy(dst, ip)
for i := 0; i < n; i++ {
for j := len(dst) - 1; j >= 0; j-- {
dst[j]++
if dst[j] > 0 {
break
}
}
}
if network.Contains(dst) {
return dst, nil
}
return nil, errors.New("network does not contain enough IPs")
}