mirror of
https://github.com/lingble/talos.git
synced 2025-12-03 06:13:49 +00:00
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:
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user