mirror of
https://github.com/lingble/talos.git
synced 2025-12-15 20:17:05 +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:
@@ -5,6 +5,8 @@
|
||||
package net
|
||||
|
||||
import (
|
||||
"net"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"gotest.tools/assert"
|
||||
@@ -23,3 +25,73 @@ func TestFormatAddress(t *testing.T) {
|
||||
assert.Equal(t, FormatAddress("192.168.1.1"), "192.168.1.1")
|
||||
assert.Equal(t, FormatAddress("alpha.beta.gamma.com"), "alpha.beta.gamma.com")
|
||||
}
|
||||
|
||||
// nolint: scopelint
|
||||
func TestNthIPInNetwork(t *testing.T) {
|
||||
type args struct {
|
||||
network *net.IPNet
|
||||
n int
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want net.IP
|
||||
}{
|
||||
{
|
||||
name: "increment IPv4 by 1",
|
||||
args: args{
|
||||
network: &net.IPNet{
|
||||
IP: net.IP{10, 96, 0, 0},
|
||||
Mask: net.IPMask{255, 255, 255, 0},
|
||||
},
|
||||
n: 1,
|
||||
},
|
||||
want: net.IP{10, 96, 0, 1},
|
||||
},
|
||||
{
|
||||
name: "increment IPv4 by 10",
|
||||
args: args{
|
||||
network: &net.IPNet{
|
||||
IP: net.IP{10, 96, 0, 0},
|
||||
Mask: net.IPMask{255, 255, 255, 0},
|
||||
},
|
||||
n: 10,
|
||||
},
|
||||
want: net.IP{10, 96, 0, 10},
|
||||
},
|
||||
{
|
||||
name: "increment IPv6 by 1",
|
||||
args: args{
|
||||
network: &net.IPNet{
|
||||
IP: net.ParseIP("2001:db8:a0b:12f0::1"),
|
||||
Mask: net.IPMask{255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||
},
|
||||
n: 1,
|
||||
},
|
||||
want: net.ParseIP("2001:db8:a0b:12f0::2"),
|
||||
},
|
||||
{
|
||||
name: "increment IPv6 by 10",
|
||||
args: args{
|
||||
network: &net.IPNet{
|
||||
IP: net.ParseIP("2001:db8:a0b:12f0::1"),
|
||||
Mask: net.IPMask{255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||
},
|
||||
n: 10,
|
||||
},
|
||||
want: net.ParseIP("2001:db8:a0b:12f0::b"),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := NthIPInNetwork(tt.args.network, tt.args.n)
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("NthFromIP() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user