mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 06:54:01 +00:00
kube-proxy: don't use invalid cidrs in unit test
CIDRs like 192.168.200.3/24 and fd00:20::1/64 replaced with 192.168.200.0/24 and fd00:20::/64
This commit is contained in:
parent
85097f3d2c
commit
41ba76d23e
@ -129,9 +129,9 @@ func Test_getLocalDetector(t *testing.T) {
|
||||
{
|
||||
name: "LocalModeClusterCIDR, IPv6 cluster",
|
||||
mode: proxyconfigapi.LocalModeClusterCIDR,
|
||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101/64"},
|
||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002:0:0:1234::/64"},
|
||||
family: v1.IPv6Protocol,
|
||||
expected: resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/64")),
|
||||
expected: resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("2002:0:0:1234::/64")),
|
||||
errExpected: false,
|
||||
},
|
||||
{
|
||||
@ -145,7 +145,7 @@ func Test_getLocalDetector(t *testing.T) {
|
||||
{
|
||||
name: "LocalModeClusterCIDR, IPv4 cluster with IPv6 config",
|
||||
mode: proxyconfigapi.LocalModeClusterCIDR,
|
||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101/64"},
|
||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002:0:0:1234::/64"},
|
||||
family: v1.IPv4Protocol,
|
||||
expected: proxyutiliptables.NewNoOpLocalDetector(),
|
||||
errExpected: false,
|
||||
@ -153,7 +153,7 @@ func Test_getLocalDetector(t *testing.T) {
|
||||
{
|
||||
name: "LocalModeClusterCIDR, IPv4 kube-proxy in dual-stack IPv6-primary cluster",
|
||||
mode: proxyconfigapi.LocalModeClusterCIDR,
|
||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101/64,10.0.0.0/14"},
|
||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002:0:0:1234::/64,10.0.0.0/14"},
|
||||
family: v1.IPv4Protocol,
|
||||
expected: resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("10.0.0.0/14")),
|
||||
errExpected: false,
|
||||
@ -179,10 +179,10 @@ func Test_getLocalDetector(t *testing.T) {
|
||||
{
|
||||
name: "LocalModeNodeCIDR, IPv6 cluster",
|
||||
mode: proxyconfigapi.LocalModeNodeCIDR,
|
||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101/64"},
|
||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002:0:0:1234::/64"},
|
||||
family: v1.IPv6Protocol,
|
||||
expected: resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/96")),
|
||||
nodePodCIDRs: []string{"2002::1234:abcd:ffff:c0a8:101/96"},
|
||||
expected: resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:0:0/96")),
|
||||
nodePodCIDRs: []string{"2002::1234:abcd:ffff:0:0/96"},
|
||||
errExpected: false,
|
||||
},
|
||||
{
|
||||
@ -197,19 +197,19 @@ func Test_getLocalDetector(t *testing.T) {
|
||||
{
|
||||
name: "LocalModeNodeCIDR, IPv4 cluster with IPv6 config",
|
||||
mode: proxyconfigapi.LocalModeNodeCIDR,
|
||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101/64"},
|
||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002:0:0:1234::/64"},
|
||||
family: v1.IPv4Protocol,
|
||||
expected: proxyutiliptables.NewNoOpLocalDetector(),
|
||||
nodePodCIDRs: []string{"2002::1234:abcd:ffff:c0a8:101/96"},
|
||||
nodePodCIDRs: []string{"2002::1234:abcd:ffff:0:0/96"},
|
||||
errExpected: false,
|
||||
},
|
||||
{
|
||||
name: "LocalModeNodeCIDR, IPv6 kube-proxy in dual-stack IPv4-primary cluster",
|
||||
mode: proxyconfigapi.LocalModeNodeCIDR,
|
||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "10.0.0.0/14,2002::1234:abcd:ffff:c0a8:101/64"},
|
||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "10.0.0.0/14,2002:0:0:1234::/64"},
|
||||
family: v1.IPv6Protocol,
|
||||
expected: resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/96")),
|
||||
nodePodCIDRs: []string{"10.0.0.0/24", "2002::1234:abcd:ffff:c0a8:101/96"},
|
||||
expected: resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:0:0/96")),
|
||||
nodePodCIDRs: []string{"10.0.0.0/24", "2002::1234:abcd:ffff:0:0/96"},
|
||||
errExpected: false,
|
||||
},
|
||||
{
|
||||
@ -307,19 +307,19 @@ func Test_getDualStackLocalDetectorTuple(t *testing.T) {
|
||||
{
|
||||
name: "LocalModeClusterCIDR, dual-stack IPv4-primary cluster",
|
||||
mode: proxyconfigapi.LocalModeClusterCIDR,
|
||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "10.0.0.0/14,2002::1234:abcd:ffff:c0a8:101/64"},
|
||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "10.0.0.0/14,2002:0:0:1234::/64"},
|
||||
expected: resolveDualStackLocalDetectors(t)(
|
||||
proxyutiliptables.NewDetectLocalByCIDR("10.0.0.0/14"))(
|
||||
proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/64")),
|
||||
proxyutiliptables.NewDetectLocalByCIDR("2002:0:0:1234::/64")),
|
||||
errExpected: false,
|
||||
},
|
||||
{
|
||||
name: "LocalModeClusterCIDR, dual-stack IPv6-primary cluster",
|
||||
mode: proxyconfigapi.LocalModeClusterCIDR,
|
||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101/64,10.0.0.0/14"},
|
||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002:0:0:1234::/64,10.0.0.0/14"},
|
||||
expected: resolveDualStackLocalDetectors(t)(
|
||||
proxyutiliptables.NewDetectLocalByCIDR("10.0.0.0/14"))(
|
||||
proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/64")),
|
||||
proxyutiliptables.NewDetectLocalByCIDR("2002:0:0:1234::/64")),
|
||||
errExpected: false,
|
||||
},
|
||||
{
|
||||
@ -334,10 +334,10 @@ func Test_getDualStackLocalDetectorTuple(t *testing.T) {
|
||||
{
|
||||
name: "LocalModeClusterCIDR, single-stack IPv6 cluster",
|
||||
mode: proxyconfigapi.LocalModeClusterCIDR,
|
||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101/64"},
|
||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002:0:0:1234::/64"},
|
||||
expected: [2]proxyutiliptables.LocalTrafficDetector{
|
||||
proxyutiliptables.NewNoOpLocalDetector(),
|
||||
resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/64"))},
|
||||
resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("2002:0:0:1234::/64"))},
|
||||
errExpected: false,
|
||||
},
|
||||
{
|
||||
@ -351,21 +351,21 @@ func Test_getDualStackLocalDetectorTuple(t *testing.T) {
|
||||
{
|
||||
name: "LocalModeNodeCIDR, dual-stack IPv4-primary cluster",
|
||||
mode: proxyconfigapi.LocalModeNodeCIDR,
|
||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "10.0.0.0/14,2002::1234:abcd:ffff:c0a8:101/64"},
|
||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "10.0.0.0/14,2002:0:0:1234::/64"},
|
||||
expected: resolveDualStackLocalDetectors(t)(
|
||||
proxyutiliptables.NewDetectLocalByCIDR("10.0.0.0/24"))(
|
||||
proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/96")),
|
||||
nodePodCIDRs: []string{"10.0.0.0/24", "2002::1234:abcd:ffff:c0a8:101/96"},
|
||||
proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:0:0/96")),
|
||||
nodePodCIDRs: []string{"10.0.0.0/24", "2002::1234:abcd:ffff:0:0/96"},
|
||||
errExpected: false,
|
||||
},
|
||||
{
|
||||
name: "LocalModeNodeCIDR, dual-stack IPv6-primary cluster",
|
||||
mode: proxyconfigapi.LocalModeNodeCIDR,
|
||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101/64,10.0.0.0/14"},
|
||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002:0:0:1234::/64,10.0.0.0/14"},
|
||||
expected: resolveDualStackLocalDetectors(t)(
|
||||
proxyutiliptables.NewDetectLocalByCIDR("10.0.0.0/24"))(
|
||||
proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/96")),
|
||||
nodePodCIDRs: []string{"2002::1234:abcd:ffff:c0a8:101/96", "10.0.0.0/24"},
|
||||
proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:0:0/96")),
|
||||
nodePodCIDRs: []string{"2002::1234:abcd:ffff:0:0/96", "10.0.0.0/24"},
|
||||
errExpected: false,
|
||||
},
|
||||
{
|
||||
@ -381,11 +381,11 @@ func Test_getDualStackLocalDetectorTuple(t *testing.T) {
|
||||
{
|
||||
name: "LocalModeNodeCIDR, single-stack IPv6 cluster",
|
||||
mode: proxyconfigapi.LocalModeNodeCIDR,
|
||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101/64"},
|
||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002:0:0:1234::/64"},
|
||||
expected: [2]proxyutiliptables.LocalTrafficDetector{
|
||||
proxyutiliptables.NewNoOpLocalDetector(),
|
||||
resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/96"))},
|
||||
nodePodCIDRs: []string{"2002::1234:abcd:ffff:c0a8:101/96"},
|
||||
resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:0:0/96"))},
|
||||
nodePodCIDRs: []string{"2002::1234:abcd:ffff:0:0/96"},
|
||||
errExpected: false,
|
||||
},
|
||||
{
|
||||
|
@ -48,7 +48,7 @@ func TestNewDetectLocalByCIDR(t *testing.T) {
|
||||
errExpected: false,
|
||||
},
|
||||
{
|
||||
cidr: "2002::1234:abcd:ffff:c0a8:101/64",
|
||||
cidr: "2002:0:0:1234::/64",
|
||||
errExpected: false,
|
||||
},
|
||||
{
|
||||
@ -56,11 +56,7 @@ func TestNewDetectLocalByCIDR(t *testing.T) {
|
||||
errExpected: true,
|
||||
},
|
||||
{
|
||||
cidr: "2002::1234:abcd:ffff:c0a8:101",
|
||||
errExpected: true,
|
||||
},
|
||||
{
|
||||
cidr: "",
|
||||
cidr: "2002:0:0:1234::",
|
||||
errExpected: true,
|
||||
},
|
||||
{
|
||||
@ -94,9 +90,9 @@ func TestDetectLocalByCIDR(t *testing.T) {
|
||||
expectedIfNotLocalOutput: []string{"!", "-s", "10.0.0.0/14"},
|
||||
},
|
||||
{
|
||||
cidr: "2002::1234:abcd:ffff:c0a8:101/64",
|
||||
expectedIfLocalOutput: []string{"-s", "2002::1234:abcd:ffff:c0a8:101/64"},
|
||||
expectedIfNotLocalOutput: []string{"!", "-s", "2002::1234:abcd:ffff:c0a8:101/64"},
|
||||
cidr: "2002:0:0:1234::/64",
|
||||
expectedIfLocalOutput: []string{"-s", "2002:0:0:1234::/64"},
|
||||
expectedIfNotLocalOutput: []string{"!", "-s", "2002:0:0:1234::/64"},
|
||||
},
|
||||
}
|
||||
for _, c := range cases {
|
||||
|
@ -372,58 +372,58 @@ func TestMapCIDRsByIPFamily(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "want IPv4 and receive IPv6",
|
||||
ipString: []string{"fd00:20::1/64"},
|
||||
ipString: []string{"fd00:20::/64"},
|
||||
wantIPv6: false,
|
||||
expectCorrect: nil,
|
||||
expectIncorrect: []string{"fd00:20::1/64"},
|
||||
expectIncorrect: []string{"fd00:20::/64"},
|
||||
},
|
||||
{
|
||||
desc: "want IPv6 and receive IPv4",
|
||||
ipString: []string{"192.168.200.2/24"},
|
||||
ipString: []string{"192.168.200.0/24"},
|
||||
wantIPv6: true,
|
||||
expectCorrect: nil,
|
||||
expectIncorrect: []string{"192.168.200.2/24"},
|
||||
expectIncorrect: []string{"192.168.200.0/24"},
|
||||
},
|
||||
{
|
||||
desc: "want IPv6 and receive IPv4 and IPv6",
|
||||
ipString: []string{"192.168.200.2/24", "192.1.34.23/24", "fd00:20::1/64", "2001:db9::3/64"},
|
||||
ipString: []string{"192.168.200.0/24", "192.1.34.0/24", "fd00:20::/64", "2001:db9::/64"},
|
||||
wantIPv6: true,
|
||||
expectCorrect: []string{"fd00:20::1/64", "2001:db9::3/64"},
|
||||
expectIncorrect: []string{"192.168.200.2/24", "192.1.34.23/24"},
|
||||
expectCorrect: []string{"fd00:20::/64", "2001:db9::/64"},
|
||||
expectIncorrect: []string{"192.168.200.0/24", "192.1.34.0/24"},
|
||||
},
|
||||
{
|
||||
desc: "want IPv4 and receive IPv4 and IPv6",
|
||||
ipString: []string{"192.168.200.2/24", "192.1.34.23/24", "fd00:20::1/64", "2001:db9::3/64"},
|
||||
ipString: []string{"192.168.200.0/24", "192.1.34.0/24", "fd00:20::/64", "2001:db9::/64"},
|
||||
wantIPv6: false,
|
||||
expectCorrect: []string{"192.168.200.2/24", "192.1.34.23/24"},
|
||||
expectIncorrect: []string{"fd00:20::1/64", "2001:db9::3/64"},
|
||||
expectCorrect: []string{"192.168.200.0/24", "192.1.34.0/24"},
|
||||
expectIncorrect: []string{"fd00:20::/64", "2001:db9::/64"},
|
||||
},
|
||||
{
|
||||
desc: "want IPv4 and receive IPv4 only",
|
||||
ipString: []string{"192.168.200.2/24", "192.1.34.23/24"},
|
||||
ipString: []string{"192.168.200.0/24", "192.1.34.0/24"},
|
||||
wantIPv6: false,
|
||||
expectCorrect: []string{"192.168.200.2/24", "192.1.34.23/24"},
|
||||
expectCorrect: []string{"192.168.200.0/24", "192.1.34.0/24"},
|
||||
expectIncorrect: nil,
|
||||
},
|
||||
{
|
||||
desc: "want IPv6 and receive IPv4 only",
|
||||
ipString: []string{"192.168.200.2/24", "192.1.34.23/24"},
|
||||
ipString: []string{"192.168.200.0/24", "192.1.34.0/24"},
|
||||
wantIPv6: true,
|
||||
expectCorrect: nil,
|
||||
expectIncorrect: []string{"192.168.200.2/24", "192.1.34.23/24"},
|
||||
expectIncorrect: []string{"192.168.200.0/24", "192.1.34.0/24"},
|
||||
},
|
||||
{
|
||||
desc: "want IPv4 and receive IPv6 only",
|
||||
ipString: []string{"fd00:20::1/64", "2001:db9::3/64"},
|
||||
ipString: []string{"fd00:20::/64", "2001:db9::/64"},
|
||||
wantIPv6: false,
|
||||
expectCorrect: nil,
|
||||
expectIncorrect: []string{"fd00:20::1/64", "2001:db9::3/64"},
|
||||
expectIncorrect: []string{"fd00:20::/64", "2001:db9::/64"},
|
||||
},
|
||||
{
|
||||
desc: "want IPv6 and receive IPv6 only",
|
||||
ipString: []string{"fd00:20::1/64", "2001:db9::3/64"},
|
||||
ipString: []string{"fd00:20::/64", "2001:db9::/64"},
|
||||
wantIPv6: true,
|
||||
expectCorrect: []string{"fd00:20::1/64", "2001:db9::3/64"},
|
||||
expectCorrect: []string{"fd00:20::/64", "2001:db9::/64"},
|
||||
expectIncorrect: nil,
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user