mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Cleanup: Change "Ip" to "IP" in func and var names
This commit is contained in:
parent
efb24d44c6
commit
9551ecb7c3
@ -91,10 +91,10 @@ func newProxyServer(
|
|||||||
return nil, fmt.Errorf("unable to register configz: %s", err)
|
return nil, fmt.Errorf("unable to register configz: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
protocol := utiliptables.ProtocolIpv4
|
protocol := utiliptables.ProtocolIPv4
|
||||||
if net.ParseIP(config.BindAddress).To4() == nil {
|
if net.ParseIP(config.BindAddress).To4() == nil {
|
||||||
klog.V(0).Infof("IPv6 bind address (%s), assume IPv6 operation", config.BindAddress)
|
klog.V(0).Infof("IPv6 bind address (%s), assume IPv6 operation", config.BindAddress)
|
||||||
protocol = utiliptables.ProtocolIpv6
|
protocol = utiliptables.ProtocolIPv6
|
||||||
}
|
}
|
||||||
|
|
||||||
var iptInterface utiliptables.Interface
|
var iptInterface utiliptables.Interface
|
||||||
@ -201,10 +201,10 @@ func newProxyServer(
|
|||||||
var ipt [2]utiliptables.Interface
|
var ipt [2]utiliptables.Interface
|
||||||
if iptInterface.IsIPv6() {
|
if iptInterface.IsIPv6() {
|
||||||
ipt[1] = iptInterface
|
ipt[1] = iptInterface
|
||||||
ipt[0] = utiliptables.New(execer, utiliptables.ProtocolIpv4)
|
ipt[0] = utiliptables.New(execer, utiliptables.ProtocolIPv4)
|
||||||
} else {
|
} else {
|
||||||
ipt[0] = iptInterface
|
ipt[0] = iptInterface
|
||||||
ipt[1] = utiliptables.New(execer, utiliptables.ProtocolIpv6)
|
ipt[1] = utiliptables.New(execer, utiliptables.ProtocolIPv6)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always ordered to match []ipt
|
// Always ordered to match []ipt
|
||||||
@ -269,10 +269,10 @@ func newProxyServer(
|
|||||||
var ipt [2]utiliptables.Interface
|
var ipt [2]utiliptables.Interface
|
||||||
if iptInterface.IsIPv6() {
|
if iptInterface.IsIPv6() {
|
||||||
ipt[1] = iptInterface
|
ipt[1] = iptInterface
|
||||||
ipt[0] = utiliptables.New(execer, utiliptables.ProtocolIpv4)
|
ipt[0] = utiliptables.New(execer, utiliptables.ProtocolIPv4)
|
||||||
} else {
|
} else {
|
||||||
ipt[0] = iptInterface
|
ipt[0] = iptInterface
|
||||||
ipt[1] = utiliptables.New(execer, utiliptables.ProtocolIpv6)
|
ipt[1] = utiliptables.New(execer, utiliptables.ProtocolIPv6)
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeIPs := nodeIPTuple(config.BindAddress)
|
nodeIPs := nodeIPTuple(config.BindAddress)
|
||||||
|
@ -214,8 +214,8 @@ func Test_getLocalDetector(t *testing.T) {
|
|||||||
{
|
{
|
||||||
mode: proxyconfigapi.LocalModeClusterCIDR,
|
mode: proxyconfigapi.LocalModeClusterCIDR,
|
||||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101/64"},
|
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101/64"},
|
||||||
ipt: utiliptablestest.NewIpv6Fake(),
|
ipt: utiliptablestest.NewIPv6Fake(),
|
||||||
expected: resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/64", utiliptablestest.NewIpv6Fake())),
|
expected: resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/64", utiliptablestest.NewIPv6Fake())),
|
||||||
errExpected: false,
|
errExpected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -228,14 +228,14 @@ func Test_getLocalDetector(t *testing.T) {
|
|||||||
{
|
{
|
||||||
mode: proxyconfigapi.LocalModeClusterCIDR,
|
mode: proxyconfigapi.LocalModeClusterCIDR,
|
||||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101"},
|
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101"},
|
||||||
ipt: utiliptablestest.NewIpv6Fake(),
|
ipt: utiliptablestest.NewIPv6Fake(),
|
||||||
expected: nil,
|
expected: nil,
|
||||||
errExpected: true,
|
errExpected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
mode: proxyconfigapi.LocalModeClusterCIDR,
|
mode: proxyconfigapi.LocalModeClusterCIDR,
|
||||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "10.0.0.0/14"},
|
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "10.0.0.0/14"},
|
||||||
ipt: utiliptablestest.NewIpv6Fake(),
|
ipt: utiliptablestest.NewIPv6Fake(),
|
||||||
expected: nil,
|
expected: nil,
|
||||||
errExpected: true,
|
errExpected: true,
|
||||||
},
|
},
|
||||||
@ -265,8 +265,8 @@ func Test_getLocalDetector(t *testing.T) {
|
|||||||
{
|
{
|
||||||
mode: proxyconfigapi.LocalModeNodeCIDR,
|
mode: proxyconfigapi.LocalModeNodeCIDR,
|
||||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101/64"},
|
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101/64"},
|
||||||
ipt: utiliptablestest.NewIpv6Fake(),
|
ipt: utiliptablestest.NewIPv6Fake(),
|
||||||
expected: resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/96", utiliptablestest.NewIpv6Fake())),
|
expected: resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/96", utiliptablestest.NewIPv6Fake())),
|
||||||
nodeInfo: makeNodeWithPodCIDRs("2002::1234:abcd:ffff:c0a8:101/96"),
|
nodeInfo: makeNodeWithPodCIDRs("2002::1234:abcd:ffff:c0a8:101/96"),
|
||||||
errExpected: false,
|
errExpected: false,
|
||||||
},
|
},
|
||||||
@ -281,7 +281,7 @@ func Test_getLocalDetector(t *testing.T) {
|
|||||||
{
|
{
|
||||||
mode: proxyconfigapi.LocalModeNodeCIDR,
|
mode: proxyconfigapi.LocalModeNodeCIDR,
|
||||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101"},
|
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101"},
|
||||||
ipt: utiliptablestest.NewIpv6Fake(),
|
ipt: utiliptablestest.NewIPv6Fake(),
|
||||||
expected: nil,
|
expected: nil,
|
||||||
nodeInfo: makeNodeWithPodCIDRs("2002::1234:abcd:ffff:c0a8:101"),
|
nodeInfo: makeNodeWithPodCIDRs("2002::1234:abcd:ffff:c0a8:101"),
|
||||||
errExpected: true,
|
errExpected: true,
|
||||||
@ -289,7 +289,7 @@ func Test_getLocalDetector(t *testing.T) {
|
|||||||
{
|
{
|
||||||
mode: proxyconfigapi.LocalModeNodeCIDR,
|
mode: proxyconfigapi.LocalModeNodeCIDR,
|
||||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "10.0.0.0/14"},
|
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "10.0.0.0/14"},
|
||||||
ipt: utiliptablestest.NewIpv6Fake(),
|
ipt: utiliptablestest.NewIPv6Fake(),
|
||||||
expected: nil,
|
expected: nil,
|
||||||
nodeInfo: makeNodeWithPodCIDRs("10.0.0.0/24"),
|
nodeInfo: makeNodeWithPodCIDRs("10.0.0.0/24"),
|
||||||
errExpected: true,
|
errExpected: true,
|
||||||
@ -350,25 +350,25 @@ func Test_getDualStackLocalDetectorTuple(t *testing.T) {
|
|||||||
{
|
{
|
||||||
mode: proxyconfigapi.LocalModeClusterCIDR,
|
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::1234:abcd:ffff:c0a8:101/64"},
|
||||||
ipt: [2]utiliptables.Interface{utiliptablestest.NewFake(), utiliptablestest.NewIpv6Fake()},
|
ipt: [2]utiliptables.Interface{utiliptablestest.NewFake(), utiliptablestest.NewIPv6Fake()},
|
||||||
expected: resolveDualStackLocalDetectors(t)(
|
expected: resolveDualStackLocalDetectors(t)(
|
||||||
proxyutiliptables.NewDetectLocalByCIDR("10.0.0.0/14", utiliptablestest.NewFake()))(
|
proxyutiliptables.NewDetectLocalByCIDR("10.0.0.0/14", utiliptablestest.NewFake()))(
|
||||||
proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/64", utiliptablestest.NewIpv6Fake())),
|
proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/64", utiliptablestest.NewIPv6Fake())),
|
||||||
errExpected: false,
|
errExpected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
mode: proxyconfigapi.LocalModeClusterCIDR,
|
mode: proxyconfigapi.LocalModeClusterCIDR,
|
||||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101/64,10.0.0.0/14"},
|
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101/64,10.0.0.0/14"},
|
||||||
ipt: [2]utiliptables.Interface{utiliptablestest.NewFake(), utiliptablestest.NewIpv6Fake()},
|
ipt: [2]utiliptables.Interface{utiliptablestest.NewFake(), utiliptablestest.NewIPv6Fake()},
|
||||||
expected: resolveDualStackLocalDetectors(t)(
|
expected: resolveDualStackLocalDetectors(t)(
|
||||||
proxyutiliptables.NewDetectLocalByCIDR("10.0.0.0/14", utiliptablestest.NewFake()))(
|
proxyutiliptables.NewDetectLocalByCIDR("10.0.0.0/14", utiliptablestest.NewFake()))(
|
||||||
proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/64", utiliptablestest.NewIpv6Fake())),
|
proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/64", utiliptablestest.NewIPv6Fake())),
|
||||||
errExpected: false,
|
errExpected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
mode: proxyconfigapi.LocalModeClusterCIDR,
|
mode: proxyconfigapi.LocalModeClusterCIDR,
|
||||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "10.0.0.0/14"},
|
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "10.0.0.0/14"},
|
||||||
ipt: [2]utiliptables.Interface{utiliptablestest.NewFake(), utiliptablestest.NewIpv6Fake()},
|
ipt: [2]utiliptables.Interface{utiliptablestest.NewFake(), utiliptablestest.NewIPv6Fake()},
|
||||||
expected: [2]proxyutiliptables.LocalTrafficDetector{
|
expected: [2]proxyutiliptables.LocalTrafficDetector{
|
||||||
resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("10.0.0.0/14", utiliptablestest.NewFake())),
|
resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("10.0.0.0/14", utiliptablestest.NewFake())),
|
||||||
proxyutiliptables.NewNoOpLocalDetector()},
|
proxyutiliptables.NewNoOpLocalDetector()},
|
||||||
@ -377,16 +377,16 @@ func Test_getDualStackLocalDetectorTuple(t *testing.T) {
|
|||||||
{
|
{
|
||||||
mode: proxyconfigapi.LocalModeClusterCIDR,
|
mode: proxyconfigapi.LocalModeClusterCIDR,
|
||||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101/64"},
|
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101/64"},
|
||||||
ipt: [2]utiliptables.Interface{utiliptablestest.NewFake(), utiliptablestest.NewIpv6Fake()},
|
ipt: [2]utiliptables.Interface{utiliptablestest.NewFake(), utiliptablestest.NewIPv6Fake()},
|
||||||
expected: [2]proxyutiliptables.LocalTrafficDetector{
|
expected: [2]proxyutiliptables.LocalTrafficDetector{
|
||||||
proxyutiliptables.NewNoOpLocalDetector(),
|
proxyutiliptables.NewNoOpLocalDetector(),
|
||||||
resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/64", utiliptablestest.NewIpv6Fake()))},
|
resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/64", utiliptablestest.NewIPv6Fake()))},
|
||||||
errExpected: false,
|
errExpected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
mode: proxyconfigapi.LocalModeClusterCIDR,
|
mode: proxyconfigapi.LocalModeClusterCIDR,
|
||||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: ""},
|
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: ""},
|
||||||
ipt: [2]utiliptables.Interface{utiliptablestest.NewFake(), utiliptablestest.NewIpv6Fake()},
|
ipt: [2]utiliptables.Interface{utiliptablestest.NewFake(), utiliptablestest.NewIPv6Fake()},
|
||||||
expected: [2]proxyutiliptables.LocalTrafficDetector{proxyutiliptables.NewNoOpLocalDetector(), proxyutiliptables.NewNoOpLocalDetector()},
|
expected: [2]proxyutiliptables.LocalTrafficDetector{proxyutiliptables.NewNoOpLocalDetector(), proxyutiliptables.NewNoOpLocalDetector()},
|
||||||
errExpected: false,
|
errExpected: false,
|
||||||
},
|
},
|
||||||
@ -394,27 +394,27 @@ func Test_getDualStackLocalDetectorTuple(t *testing.T) {
|
|||||||
{
|
{
|
||||||
mode: proxyconfigapi.LocalModeNodeCIDR,
|
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::1234:abcd:ffff:c0a8:101/64"},
|
||||||
ipt: [2]utiliptables.Interface{utiliptablestest.NewFake(), utiliptablestest.NewIpv6Fake()},
|
ipt: [2]utiliptables.Interface{utiliptablestest.NewFake(), utiliptablestest.NewIPv6Fake()},
|
||||||
expected: resolveDualStackLocalDetectors(t)(
|
expected: resolveDualStackLocalDetectors(t)(
|
||||||
proxyutiliptables.NewDetectLocalByCIDR("10.0.0.0/24", utiliptablestest.NewFake()))(
|
proxyutiliptables.NewDetectLocalByCIDR("10.0.0.0/24", utiliptablestest.NewFake()))(
|
||||||
proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/96", utiliptablestest.NewIpv6Fake())),
|
proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/96", utiliptablestest.NewIPv6Fake())),
|
||||||
nodeInfo: makeNodeWithPodCIDRs("10.0.0.0/24", "2002::1234:abcd:ffff:c0a8:101/96"),
|
nodeInfo: makeNodeWithPodCIDRs("10.0.0.0/24", "2002::1234:abcd:ffff:c0a8:101/96"),
|
||||||
errExpected: false,
|
errExpected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
mode: proxyconfigapi.LocalModeNodeCIDR,
|
mode: proxyconfigapi.LocalModeNodeCIDR,
|
||||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101/64,10.0.0.0/14"},
|
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101/64,10.0.0.0/14"},
|
||||||
ipt: [2]utiliptables.Interface{utiliptablestest.NewFake(), utiliptablestest.NewIpv6Fake()},
|
ipt: [2]utiliptables.Interface{utiliptablestest.NewFake(), utiliptablestest.NewIPv6Fake()},
|
||||||
expected: resolveDualStackLocalDetectors(t)(
|
expected: resolveDualStackLocalDetectors(t)(
|
||||||
proxyutiliptables.NewDetectLocalByCIDR("10.0.0.0/24", utiliptablestest.NewFake()))(
|
proxyutiliptables.NewDetectLocalByCIDR("10.0.0.0/24", utiliptablestest.NewFake()))(
|
||||||
proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/96", utiliptablestest.NewIpv6Fake())),
|
proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/96", utiliptablestest.NewIPv6Fake())),
|
||||||
nodeInfo: makeNodeWithPodCIDRs("2002::1234:abcd:ffff:c0a8:101/96", "10.0.0.0/24"),
|
nodeInfo: makeNodeWithPodCIDRs("2002::1234:abcd:ffff:c0a8:101/96", "10.0.0.0/24"),
|
||||||
errExpected: false,
|
errExpected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
mode: proxyconfigapi.LocalModeNodeCIDR,
|
mode: proxyconfigapi.LocalModeNodeCIDR,
|
||||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "10.0.0.0/14"},
|
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "10.0.0.0/14"},
|
||||||
ipt: [2]utiliptables.Interface{utiliptablestest.NewFake(), utiliptablestest.NewIpv6Fake()},
|
ipt: [2]utiliptables.Interface{utiliptablestest.NewFake(), utiliptablestest.NewIPv6Fake()},
|
||||||
expected: [2]proxyutiliptables.LocalTrafficDetector{
|
expected: [2]proxyutiliptables.LocalTrafficDetector{
|
||||||
resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("10.0.0.0/24", utiliptablestest.NewFake())),
|
resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("10.0.0.0/24", utiliptablestest.NewFake())),
|
||||||
proxyutiliptables.NewNoOpLocalDetector()},
|
proxyutiliptables.NewNoOpLocalDetector()},
|
||||||
@ -424,17 +424,17 @@ func Test_getDualStackLocalDetectorTuple(t *testing.T) {
|
|||||||
{
|
{
|
||||||
mode: proxyconfigapi.LocalModeNodeCIDR,
|
mode: proxyconfigapi.LocalModeNodeCIDR,
|
||||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101/64"},
|
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101/64"},
|
||||||
ipt: [2]utiliptables.Interface{utiliptablestest.NewFake(), utiliptablestest.NewIpv6Fake()},
|
ipt: [2]utiliptables.Interface{utiliptablestest.NewFake(), utiliptablestest.NewIPv6Fake()},
|
||||||
expected: [2]proxyutiliptables.LocalTrafficDetector{
|
expected: [2]proxyutiliptables.LocalTrafficDetector{
|
||||||
proxyutiliptables.NewNoOpLocalDetector(),
|
proxyutiliptables.NewNoOpLocalDetector(),
|
||||||
resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/96", utiliptablestest.NewIpv6Fake()))},
|
resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/96", utiliptablestest.NewIPv6Fake()))},
|
||||||
nodeInfo: makeNodeWithPodCIDRs("2002::1234:abcd:ffff:c0a8:101/96"),
|
nodeInfo: makeNodeWithPodCIDRs("2002::1234:abcd:ffff:c0a8:101/96"),
|
||||||
errExpected: false,
|
errExpected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
mode: proxyconfigapi.LocalModeNodeCIDR,
|
mode: proxyconfigapi.LocalModeNodeCIDR,
|
||||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: ""},
|
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: ""},
|
||||||
ipt: [2]utiliptables.Interface{utiliptablestest.NewFake(), utiliptablestest.NewIpv6Fake()},
|
ipt: [2]utiliptables.Interface{utiliptablestest.NewFake(), utiliptablestest.NewIPv6Fake()},
|
||||||
expected: [2]proxyutiliptables.LocalTrafficDetector{proxyutiliptables.NewNoOpLocalDetector(), proxyutiliptables.NewNoOpLocalDetector()},
|
expected: [2]proxyutiliptables.LocalTrafficDetector{proxyutiliptables.NewNoOpLocalDetector(), proxyutiliptables.NewNoOpLocalDetector()},
|
||||||
nodeInfo: makeNodeWithPodCIDRs(),
|
nodeInfo: makeNodeWithPodCIDRs(),
|
||||||
errExpected: false,
|
errExpected: false,
|
||||||
@ -442,7 +442,7 @@ func Test_getDualStackLocalDetectorTuple(t *testing.T) {
|
|||||||
{
|
{
|
||||||
mode: proxyconfigapi.LocalModeNodeCIDR,
|
mode: proxyconfigapi.LocalModeNodeCIDR,
|
||||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: ""},
|
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: ""},
|
||||||
ipt: [2]utiliptables.Interface{utiliptablestest.NewFake(), utiliptablestest.NewIpv6Fake()},
|
ipt: [2]utiliptables.Interface{utiliptablestest.NewFake(), utiliptablestest.NewIPv6Fake()},
|
||||||
expected: [2]proxyutiliptables.LocalTrafficDetector{proxyutiliptables.NewNoOpLocalDetector(), proxyutiliptables.NewNoOpLocalDetector()},
|
expected: [2]proxyutiliptables.LocalTrafficDetector{proxyutiliptables.NewNoOpLocalDetector(), proxyutiliptables.NewNoOpLocalDetector()},
|
||||||
nodeInfo: nil,
|
nodeInfo: nil,
|
||||||
errExpected: false,
|
errExpected: false,
|
||||||
@ -451,7 +451,7 @@ func Test_getDualStackLocalDetectorTuple(t *testing.T) {
|
|||||||
{
|
{
|
||||||
mode: proxyconfigapi.LocalMode("abcd"),
|
mode: proxyconfigapi.LocalMode("abcd"),
|
||||||
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: ""},
|
config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: ""},
|
||||||
ipt: [2]utiliptables.Interface{utiliptablestest.NewFake(), utiliptablestest.NewIpv6Fake()},
|
ipt: [2]utiliptables.Interface{utiliptablestest.NewFake(), utiliptablestest.NewIPv6Fake()},
|
||||||
expected: [2]proxyutiliptables.LocalTrafficDetector{proxyutiliptables.NewNoOpLocalDetector(), proxyutiliptables.NewNoOpLocalDetector()},
|
expected: [2]proxyutiliptables.LocalTrafficDetector{proxyutiliptables.NewNoOpLocalDetector(), proxyutiliptables.NewNoOpLocalDetector()},
|
||||||
errExpected: false,
|
errExpected: false,
|
||||||
},
|
},
|
||||||
|
@ -51,7 +51,7 @@ func NewFakeIPTables() *fakeIPTables {
|
|||||||
string(utiliptables.TableNAT): sets.NewString("PREROUTING", "INPUT", "OUTPUT", "POSTROUTING"),
|
string(utiliptables.TableNAT): sets.NewString("PREROUTING", "INPUT", "OUTPUT", "POSTROUTING"),
|
||||||
string(utiliptables.TableMangle): sets.NewString("PREROUTING", "INPUT", "FORWARD", "OUTPUT", "POSTROUTING"),
|
string(utiliptables.TableMangle): sets.NewString("PREROUTING", "INPUT", "FORWARD", "OUTPUT", "POSTROUTING"),
|
||||||
},
|
},
|
||||||
protocol: utiliptables.ProtocolIpv4,
|
protocol: utiliptables.ProtocolIPv4,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,7 +224,7 @@ func (f *fakeIPTables) DeleteRule(tableName utiliptables.Table, chainName utilip
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *fakeIPTables) IsIPv6() bool {
|
func (f *fakeIPTables) IsIPv6() bool {
|
||||||
return f.protocol == utiliptables.ProtocolIpv6
|
return f.protocol == utiliptables.ProtocolIPv6
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *fakeIPTables) Protocol() utiliptables.Protocol {
|
func (f *fakeIPTables) Protocol() utiliptables.Protocol {
|
||||||
|
@ -88,10 +88,10 @@ func (hm *hostportManager) Add(id string, podPortMapping *PodPortMapping, natInt
|
|||||||
return fmt.Errorf("invalid or missing IP of pod %s", podFullName)
|
return fmt.Errorf("invalid or missing IP of pod %s", podFullName)
|
||||||
}
|
}
|
||||||
podIP := podPortMapping.IP.String()
|
podIP := podPortMapping.IP.String()
|
||||||
isIpv6 := utilnet.IsIPv6(podPortMapping.IP)
|
isIPv6 := utilnet.IsIPv6(podPortMapping.IP)
|
||||||
|
|
||||||
if isIpv6 != hm.iptables.IsIPv6() {
|
if isIPv6 != hm.iptables.IsIPv6() {
|
||||||
return fmt.Errorf("HostPortManager IP family mismatch: %v, isIPv6 - %v", podIP, isIpv6)
|
return fmt.Errorf("HostPortManager IP family mismatch: %v, isIPv6 - %v", podIP, isIPv6)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = ensureKubeHostportChains(hm.iptables, natInterfaceName); err != nil {
|
if err = ensureKubeHostportChains(hm.iptables, natInterfaceName); err != nil {
|
||||||
@ -180,9 +180,9 @@ func (hm *hostportManager) Add(id string, podPortMapping *PodPortMapping, natInt
|
|||||||
// create a new conntrack entry without any DNAT. That will result in blackhole of the traffic even after correct
|
// create a new conntrack entry without any DNAT. That will result in blackhole of the traffic even after correct
|
||||||
// iptables rules have been added back.
|
// iptables rules have been added back.
|
||||||
if hm.execer != nil && hm.conntrackFound {
|
if hm.execer != nil && hm.conntrackFound {
|
||||||
klog.Infof("Starting to delete udp conntrack entries: %v, isIPv6 - %v", conntrackPortsToRemove, isIpv6)
|
klog.Infof("Starting to delete udp conntrack entries: %v, isIPv6 - %v", conntrackPortsToRemove, isIPv6)
|
||||||
for _, port := range conntrackPortsToRemove {
|
for _, port := range conntrackPortsToRemove {
|
||||||
err = conntrack.ClearEntriesForPort(hm.execer, port, isIpv6, v1.ProtocolUDP)
|
err = conntrack.ClearEntriesForPort(hm.execer, port, isIPv6, v1.ProtocolUDP)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("Failed to clear udp conntrack for port %d, error: %v", port, err)
|
klog.Errorf("Failed to clear udp conntrack for port %d, error: %v", port, err)
|
||||||
}
|
}
|
||||||
|
@ -387,7 +387,7 @@ func TestGetHostportChain(t *testing.T) {
|
|||||||
|
|
||||||
func TestHostportManagerIPv6(t *testing.T) {
|
func TestHostportManagerIPv6(t *testing.T) {
|
||||||
iptables := NewFakeIPTables()
|
iptables := NewFakeIPTables()
|
||||||
iptables.protocol = utiliptables.ProtocolIpv6
|
iptables.protocol = utiliptables.ProtocolIPv6
|
||||||
portOpener := NewFakeSocketManager()
|
portOpener := NewFakeSocketManager()
|
||||||
manager := &hostportManager{
|
manager := &hostportManager{
|
||||||
hostPortMap: make(map[hostport]closeable),
|
hostPortMap: make(map[hostport]closeable),
|
||||||
|
@ -244,7 +244,7 @@ func matchRule(chain *fakeChain, match string) bool {
|
|||||||
|
|
||||||
func TestOpenPodHostportsIPv6(t *testing.T) {
|
func TestOpenPodHostportsIPv6(t *testing.T) {
|
||||||
fakeIPTables := NewFakeIPTables()
|
fakeIPTables := NewFakeIPTables()
|
||||||
fakeIPTables.protocol = utiliptables.ProtocolIpv6
|
fakeIPTables.protocol = utiliptables.ProtocolIPv6
|
||||||
fakeOpener := NewFakeSocketManager()
|
fakeOpener := NewFakeSocketManager()
|
||||||
|
|
||||||
h := &hostportSyncer{
|
h := &hostportSyncer{
|
||||||
|
@ -122,8 +122,8 @@ type kubenetNetworkPlugin struct {
|
|||||||
|
|
||||||
func NewPlugin(networkPluginDirs []string, cacheDir string) network.NetworkPlugin {
|
func NewPlugin(networkPluginDirs []string, cacheDir string) network.NetworkPlugin {
|
||||||
execer := utilexec.New()
|
execer := utilexec.New()
|
||||||
iptInterface := utiliptables.New(execer, utiliptables.ProtocolIpv4)
|
iptInterface := utiliptables.New(execer, utiliptables.ProtocolIPv4)
|
||||||
iptInterfacev6 := utiliptables.New(execer, utiliptables.ProtocolIpv6)
|
iptInterfacev6 := utiliptables.New(execer, utiliptables.ProtocolIPv6)
|
||||||
return &kubenetNetworkPlugin{
|
return &kubenetNetworkPlugin{
|
||||||
podIPs: make(map[kubecontainer.ContainerID]utilsets.String),
|
podIPs: make(map[kubecontainer.ContainerID]utilsets.String),
|
||||||
execer: utilexec.New(),
|
execer: utilexec.New(),
|
||||||
|
@ -523,10 +523,10 @@ func NewMainKubelet(kubeCfg *kubeletconfiginternal.KubeletConfiguration,
|
|||||||
}
|
}
|
||||||
httpClient := &http.Client{}
|
httpClient := &http.Client{}
|
||||||
parsedNodeIP := net.ParseIP(nodeIP)
|
parsedNodeIP := net.ParseIP(nodeIP)
|
||||||
protocol := utilipt.ProtocolIpv4
|
protocol := utilipt.ProtocolIPv4
|
||||||
if utilnet.IsIPv6(parsedNodeIP) {
|
if utilnet.IsIPv6(parsedNodeIP) {
|
||||||
klog.V(0).Infof("IPv6 node IP (%s), assume IPv6 operation", nodeIP)
|
klog.V(0).Infof("IPv6 node IP (%s), assume IPv6 operation", nodeIP)
|
||||||
protocol = utilipt.ProtocolIpv6
|
protocol = utilipt.ProtocolIPv6
|
||||||
}
|
}
|
||||||
|
|
||||||
klet := &Kubelet{
|
klet := &Kubelet{
|
||||||
|
@ -2088,10 +2088,10 @@ func (proxier *Proxier) isIPInExcludeCIDRs(ip net.IP) bool {
|
|||||||
|
|
||||||
func (proxier *Proxier) getLegacyBindAddr(activeBindAddrs map[string]bool, currentBindAddrs []string) map[string]bool {
|
func (proxier *Proxier) getLegacyBindAddr(activeBindAddrs map[string]bool, currentBindAddrs []string) map[string]bool {
|
||||||
legacyAddrs := make(map[string]bool)
|
legacyAddrs := make(map[string]bool)
|
||||||
isIpv6 := utilnet.IsIPv6(proxier.nodeIP)
|
isIPv6 := utilnet.IsIPv6(proxier.nodeIP)
|
||||||
for _, addr := range currentBindAddrs {
|
for _, addr := range currentBindAddrs {
|
||||||
addrIsIPv6 := utilnet.IsIPv6(net.ParseIP(addr))
|
addrIsIPv6 := utilnet.IsIPv6(net.ParseIP(addr))
|
||||||
if addrIsIPv6 && !isIpv6 || !addrIsIPv6 && isIpv6 {
|
if addrIsIPv6 && !isIPv6 || !addrIsIPv6 && isIPv6 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if _, ok := activeBindAddrs[addr]; !ok {
|
if _, ok := activeBindAddrs[addr]; !ok {
|
||||||
|
@ -70,12 +70,12 @@ func TestNewDetectLocalByCIDR(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
cidr: "2002::1234:abcd:ffff:c0a8:101/64",
|
cidr: "2002::1234:abcd:ffff:c0a8:101/64",
|
||||||
ipt: iptablestest.NewIpv6Fake(),
|
ipt: iptablestest.NewIPv6Fake(),
|
||||||
errExpected: false,
|
errExpected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
cidr: "10.0.0.0/14",
|
cidr: "10.0.0.0/14",
|
||||||
ipt: iptablestest.NewIpv6Fake(),
|
ipt: iptablestest.NewIPv6Fake(),
|
||||||
errExpected: true,
|
errExpected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -90,7 +90,7 @@ func TestNewDetectLocalByCIDR(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
cidr: "2002::1234:abcd:ffff:c0a8:101",
|
cidr: "2002::1234:abcd:ffff:c0a8:101",
|
||||||
ipt: iptablestest.NewIpv6Fake(),
|
ipt: iptablestest.NewIPv6Fake(),
|
||||||
errExpected: true,
|
errExpected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -100,7 +100,7 @@ func TestNewDetectLocalByCIDR(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
cidr: "",
|
cidr: "",
|
||||||
ipt: iptablestest.NewIpv6Fake(),
|
ipt: iptablestest.NewIPv6Fake(),
|
||||||
errExpected: true,
|
errExpected: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -137,7 +137,7 @@ func TestDetectLocalByCIDR(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
cidr: "2002::1234:abcd:ffff:c0a8:101/64",
|
cidr: "2002::1234:abcd:ffff:c0a8:101/64",
|
||||||
ipt: iptablestest.NewIpv6Fake(),
|
ipt: iptablestest.NewIPv6Fake(),
|
||||||
chain: "TEST",
|
chain: "TEST",
|
||||||
args: []string{"arg1", "arg2"},
|
args: []string{"arg1", "arg2"},
|
||||||
expectedJumpIfOutput: []string{"arg1", "arg2", "-s", "2002::1234:abcd:ffff:c0a8:101/64", "-j", "TEST"},
|
expectedJumpIfOutput: []string{"arg1", "arg2", "-s", "2002::1234:abcd:ffff:c0a8:101/64", "-j", "TEST"},
|
||||||
|
@ -213,7 +213,7 @@ func (proxier *Proxier) addServicePortPortal(servicePortPortalName ServicePortPo
|
|||||||
return nil, fmt.Errorf("could not parse ip '%q'", listenIP)
|
return nil, fmt.Errorf("could not parse ip '%q'", listenIP)
|
||||||
}
|
}
|
||||||
// add the IP address. Node port binds to all interfaces.
|
// add the IP address. Node port binds to all interfaces.
|
||||||
args := proxier.netshIpv4AddressAddArgs(serviceIP)
|
args := proxier.netshIPv4AddressAddArgs(serviceIP)
|
||||||
if existed, err := proxier.netsh.EnsureIPAddress(args, serviceIP); err != nil {
|
if existed, err := proxier.netsh.EnsureIPAddress(args, serviceIP); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if !existed {
|
} else if !existed {
|
||||||
@ -262,7 +262,7 @@ func (proxier *Proxier) closeServicePortPortal(servicePortPortalName ServicePort
|
|||||||
// close the PortalProxy by deleting the service IP address
|
// close the PortalProxy by deleting the service IP address
|
||||||
if info.portal.ip != allAvailableInterfaces {
|
if info.portal.ip != allAvailableInterfaces {
|
||||||
serviceIP := net.ParseIP(info.portal.ip)
|
serviceIP := net.ParseIP(info.portal.ip)
|
||||||
args := proxier.netshIpv4AddressDeleteArgs(serviceIP)
|
args := proxier.netshIPv4AddressDeleteArgs(serviceIP)
|
||||||
if err := proxier.netsh.DeleteIPAddress(args); err != nil {
|
if err := proxier.netsh.DeleteIPAddress(args); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -474,7 +474,7 @@ func isClosedError(err error) bool {
|
|||||||
return strings.HasSuffix(err.Error(), "use of closed network connection")
|
return strings.HasSuffix(err.Error(), "use of closed network connection")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (proxier *Proxier) netshIpv4AddressAddArgs(destIP net.IP) []string {
|
func (proxier *Proxier) netshIPv4AddressAddArgs(destIP net.IP) []string {
|
||||||
intName := proxier.netsh.GetInterfaceToAddIP()
|
intName := proxier.netsh.GetInterfaceToAddIP()
|
||||||
args := []string{
|
args := []string{
|
||||||
"interface", "ipv4", "add", "address",
|
"interface", "ipv4", "add", "address",
|
||||||
@ -485,7 +485,7 @@ func (proxier *Proxier) netshIpv4AddressAddArgs(destIP net.IP) []string {
|
|||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
func (proxier *Proxier) netshIpv4AddressDeleteArgs(destIP net.IP) []string {
|
func (proxier *Proxier) netshIPv4AddressDeleteArgs(destIP net.IP) []string {
|
||||||
intName := proxier.netsh.GetInterfaceToAddIP()
|
intName := proxier.netsh.GetInterfaceToAddIP()
|
||||||
args := []string{
|
args := []string{
|
||||||
"interface", "ipv4", "delete", "address",
|
"interface", "ipv4", "delete", "address",
|
||||||
|
@ -92,10 +92,10 @@ type Interface interface {
|
|||||||
type Protocol string
|
type Protocol string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// ProtocolIpv4 represents ipv4 protocol in iptables
|
// ProtocolIPv4 represents ipv4 protocol in iptables
|
||||||
ProtocolIpv4 Protocol = "IPv4"
|
ProtocolIPv4 Protocol = "IPv4"
|
||||||
// ProtocolIpv6 represents ipv6 protocol in iptables
|
// ProtocolIPv6 represents ipv6 protocol in iptables
|
||||||
ProtocolIpv6 Protocol = "IPv6"
|
ProtocolIPv6 Protocol = "IPv6"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Table represents different iptable like filter,nat, mangle and raw
|
// Table represents different iptable like filter,nat, mangle and raw
|
||||||
@ -322,7 +322,7 @@ func (runner *runner) DeleteRule(table Table, chain Chain, args ...string) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (runner *runner) IsIPv6() bool {
|
func (runner *runner) IsIPv6() bool {
|
||||||
return runner.protocol == ProtocolIpv6
|
return runner.protocol == ProtocolIPv6
|
||||||
}
|
}
|
||||||
|
|
||||||
func (runner *runner) Protocol() Protocol {
|
func (runner *runner) Protocol() Protocol {
|
||||||
@ -416,14 +416,14 @@ func (runner *runner) restoreInternal(args []string, data []byte, flush FlushFla
|
|||||||
}
|
}
|
||||||
|
|
||||||
func iptablesSaveCommand(protocol Protocol) string {
|
func iptablesSaveCommand(protocol Protocol) string {
|
||||||
if protocol == ProtocolIpv6 {
|
if protocol == ProtocolIPv6 {
|
||||||
return cmdIP6TablesSave
|
return cmdIP6TablesSave
|
||||||
}
|
}
|
||||||
return cmdIPTablesSave
|
return cmdIPTablesSave
|
||||||
}
|
}
|
||||||
|
|
||||||
func iptablesRestoreCommand(protocol Protocol) string {
|
func iptablesRestoreCommand(protocol Protocol) string {
|
||||||
if protocol == ProtocolIpv6 {
|
if protocol == ProtocolIPv6 {
|
||||||
return cmdIP6TablesRestore
|
return cmdIP6TablesRestore
|
||||||
}
|
}
|
||||||
return cmdIPTablesRestore
|
return cmdIPTablesRestore
|
||||||
@ -431,7 +431,7 @@ func iptablesRestoreCommand(protocol Protocol) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func iptablesCommand(protocol Protocol) string {
|
func iptablesCommand(protocol Protocol) string {
|
||||||
if protocol == ProtocolIpv6 {
|
if protocol == ProtocolIPv6 {
|
||||||
return cmdIP6Tables
|
return cmdIP6Tables
|
||||||
}
|
}
|
||||||
return cmdIPTables
|
return cmdIPTables
|
||||||
|
@ -68,11 +68,11 @@ func testIPTablesVersionCmds(t *testing.T, protocol Protocol) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIPTablesVersionCmdsIPv4(t *testing.T) {
|
func TestIPTablesVersionCmdsIPv4(t *testing.T) {
|
||||||
testIPTablesVersionCmds(t, ProtocolIpv4)
|
testIPTablesVersionCmds(t, ProtocolIPv4)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIPTablesVersionCmdsIPv6(t *testing.T) {
|
func TestIPTablesVersionCmdsIPv6(t *testing.T) {
|
||||||
testIPTablesVersionCmds(t, ProtocolIpv6)
|
testIPTablesVersionCmds(t, ProtocolIPv6)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testEnsureChain(t *testing.T, protocol Protocol) {
|
func testEnsureChain(t *testing.T, protocol Protocol) {
|
||||||
@ -127,12 +127,12 @@ func testEnsureChain(t *testing.T, protocol Protocol) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEnsureChainIpv4(t *testing.T) {
|
func TestEnsureChainIPv4(t *testing.T) {
|
||||||
testEnsureChain(t, ProtocolIpv4)
|
testEnsureChain(t, ProtocolIPv4)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEnsureChainIpv6(t *testing.T) {
|
func TestEnsureChainIPv6(t *testing.T) {
|
||||||
testEnsureChain(t, ProtocolIpv6)
|
testEnsureChain(t, ProtocolIPv6)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFlushChain(t *testing.T) {
|
func TestFlushChain(t *testing.T) {
|
||||||
@ -153,7 +153,7 @@ func TestFlushChain(t *testing.T) {
|
|||||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
runner := New(&fexec, ProtocolIpv4)
|
runner := New(&fexec, ProtocolIPv4)
|
||||||
// Success.
|
// Success.
|
||||||
err := runner.FlushChain(TableNAT, Chain("FOOBAR"))
|
err := runner.FlushChain(TableNAT, Chain("FOOBAR"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -190,7 +190,7 @@ func TestDeleteChain(t *testing.T) {
|
|||||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
runner := New(&fexec, ProtocolIpv4)
|
runner := New(&fexec, ProtocolIPv4)
|
||||||
// Success.
|
// Success.
|
||||||
err := runner.DeleteChain(TableNAT, Chain("FOOBAR"))
|
err := runner.DeleteChain(TableNAT, Chain("FOOBAR"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -226,7 +226,7 @@ func TestEnsureRuleAlreadyExists(t *testing.T) {
|
|||||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
runner := New(&fexec, ProtocolIpv4)
|
runner := New(&fexec, ProtocolIPv4)
|
||||||
exists, err := runner.EnsureRule(Append, TableNAT, ChainOutput, "abc", "123")
|
exists, err := runner.EnsureRule(Append, TableNAT, ChainOutput, "abc", "123")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("expected success, got %v", err)
|
t.Errorf("expected success, got %v", err)
|
||||||
@ -262,7 +262,7 @@ func TestEnsureRuleNew(t *testing.T) {
|
|||||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
runner := New(&fexec, ProtocolIpv4)
|
runner := New(&fexec, ProtocolIPv4)
|
||||||
exists, err := runner.EnsureRule(Append, TableNAT, ChainOutput, "abc", "123")
|
exists, err := runner.EnsureRule(Append, TableNAT, ChainOutput, "abc", "123")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("expected success, got %v", err)
|
t.Errorf("expected success, got %v", err)
|
||||||
@ -295,7 +295,7 @@ func TestEnsureRuleErrorChecking(t *testing.T) {
|
|||||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
runner := New(&fexec, ProtocolIpv4)
|
runner := New(&fexec, ProtocolIPv4)
|
||||||
_, err := runner.EnsureRule(Append, TableNAT, ChainOutput, "abc", "123")
|
_, err := runner.EnsureRule(Append, TableNAT, ChainOutput, "abc", "123")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("expected failure")
|
t.Errorf("expected failure")
|
||||||
@ -325,7 +325,7 @@ func TestEnsureRuleErrorCreating(t *testing.T) {
|
|||||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
runner := New(&fexec, ProtocolIpv4)
|
runner := New(&fexec, ProtocolIPv4)
|
||||||
_, err := runner.EnsureRule(Append, TableNAT, ChainOutput, "abc", "123")
|
_, err := runner.EnsureRule(Append, TableNAT, ChainOutput, "abc", "123")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("expected failure")
|
t.Errorf("expected failure")
|
||||||
@ -352,7 +352,7 @@ func TestDeleteRuleDoesNotExist(t *testing.T) {
|
|||||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
runner := New(&fexec, ProtocolIpv4)
|
runner := New(&fexec, ProtocolIPv4)
|
||||||
err := runner.DeleteRule(TableNAT, ChainOutput, "abc", "123")
|
err := runner.DeleteRule(TableNAT, ChainOutput, "abc", "123")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("expected success, got %v", err)
|
t.Errorf("expected success, got %v", err)
|
||||||
@ -385,7 +385,7 @@ func TestDeleteRuleExists(t *testing.T) {
|
|||||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
runner := New(&fexec, ProtocolIpv4)
|
runner := New(&fexec, ProtocolIPv4)
|
||||||
err := runner.DeleteRule(TableNAT, ChainOutput, "abc", "123")
|
err := runner.DeleteRule(TableNAT, ChainOutput, "abc", "123")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("expected success, got %v", err)
|
t.Errorf("expected success, got %v", err)
|
||||||
@ -415,7 +415,7 @@ func TestDeleteRuleErrorChecking(t *testing.T) {
|
|||||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
runner := New(&fexec, ProtocolIpv4)
|
runner := New(&fexec, ProtocolIPv4)
|
||||||
err := runner.DeleteRule(TableNAT, ChainOutput, "abc", "123")
|
err := runner.DeleteRule(TableNAT, ChainOutput, "abc", "123")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("expected failure")
|
t.Errorf("expected failure")
|
||||||
@ -445,7 +445,7 @@ func TestDeleteRuleErrorDeleting(t *testing.T) {
|
|||||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
runner := New(&fexec, ProtocolIpv4)
|
runner := New(&fexec, ProtocolIPv4)
|
||||||
err := runner.DeleteRule(TableNAT, ChainOutput, "abc", "123")
|
err := runner.DeleteRule(TableNAT, ChainOutput, "abc", "123")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("expected failure")
|
t.Errorf("expected failure")
|
||||||
@ -480,7 +480,7 @@ func TestGetIPTablesHasCheckCommand(t *testing.T) {
|
|||||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
ipt := New(&fexec, ProtocolIpv4)
|
ipt := New(&fexec, ProtocolIPv4)
|
||||||
runner := ipt.(*runner)
|
runner := ipt.(*runner)
|
||||||
if testCase.Expected != runner.hasCheck {
|
if testCase.Expected != runner.hasCheck {
|
||||||
t.Errorf("Expected result: %v, Got result: %v", testCase.Expected, runner.hasCheck)
|
t.Errorf("Expected result: %v, Got result: %v", testCase.Expected, runner.hasCheck)
|
||||||
@ -494,12 +494,12 @@ func TestIPTablesCommands(t *testing.T) {
|
|||||||
protocol Protocol
|
protocol Protocol
|
||||||
expectedCmd string
|
expectedCmd string
|
||||||
}{
|
}{
|
||||||
{"iptablesCommand", ProtocolIpv4, cmdIPTables},
|
{"iptablesCommand", ProtocolIPv4, cmdIPTables},
|
||||||
{"iptablesCommand", ProtocolIpv6, cmdIP6Tables},
|
{"iptablesCommand", ProtocolIPv6, cmdIP6Tables},
|
||||||
{"iptablesSaveCommand", ProtocolIpv4, cmdIPTablesSave},
|
{"iptablesSaveCommand", ProtocolIPv4, cmdIPTablesSave},
|
||||||
{"iptablesSaveCommand", ProtocolIpv6, cmdIP6TablesSave},
|
{"iptablesSaveCommand", ProtocolIPv6, cmdIP6TablesSave},
|
||||||
{"iptablesRestoreCommand", ProtocolIpv4, cmdIPTablesRestore},
|
{"iptablesRestoreCommand", ProtocolIPv4, cmdIPTablesRestore},
|
||||||
{"iptablesRestoreCommand", ProtocolIpv6, cmdIP6TablesRestore},
|
{"iptablesRestoreCommand", ProtocolIPv6, cmdIP6TablesRestore},
|
||||||
}
|
}
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
var cmd string
|
var cmd string
|
||||||
@ -641,7 +641,7 @@ func TestWaitFlagUnavailable(t *testing.T) {
|
|||||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
runner := New(&fexec, ProtocolIpv4)
|
runner := New(&fexec, ProtocolIPv4)
|
||||||
err := runner.DeleteChain(TableNAT, Chain("FOOBAR"))
|
err := runner.DeleteChain(TableNAT, Chain("FOOBAR"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("expected success, got %v", err)
|
t.Errorf("expected success, got %v", err)
|
||||||
@ -672,7 +672,7 @@ func TestWaitFlagOld(t *testing.T) {
|
|||||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
runner := New(&fexec, ProtocolIpv4)
|
runner := New(&fexec, ProtocolIPv4)
|
||||||
err := runner.DeleteChain(TableNAT, Chain("FOOBAR"))
|
err := runner.DeleteChain(TableNAT, Chain("FOOBAR"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("expected success, got %v", err)
|
t.Errorf("expected success, got %v", err)
|
||||||
@ -706,7 +706,7 @@ func TestWaitFlagNew(t *testing.T) {
|
|||||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
runner := New(&fexec, ProtocolIpv4)
|
runner := New(&fexec, ProtocolIPv4)
|
||||||
err := runner.DeleteChain(TableNAT, Chain("FOOBAR"))
|
err := runner.DeleteChain(TableNAT, Chain("FOOBAR"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("expected success, got %v", err)
|
t.Errorf("expected success, got %v", err)
|
||||||
@ -737,7 +737,7 @@ func TestWaitIntervalFlagNew(t *testing.T) {
|
|||||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
runner := New(&fexec, ProtocolIpv4)
|
runner := New(&fexec, ProtocolIPv4)
|
||||||
err := runner.DeleteChain(TableNAT, Chain("FOOBAR"))
|
err := runner.DeleteChain(TableNAT, Chain("FOOBAR"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("expected success, got %v", err)
|
t.Errorf("expected success, got %v", err)
|
||||||
@ -817,11 +817,11 @@ COMMIT
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSaveIntoIPv4(t *testing.T) {
|
func TestSaveIntoIPv4(t *testing.T) {
|
||||||
testSaveInto(t, ProtocolIpv4)
|
testSaveInto(t, ProtocolIPv4)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSaveIntoIPv6(t *testing.T) {
|
func TestSaveIntoIPv6(t *testing.T) {
|
||||||
testSaveInto(t, ProtocolIpv6)
|
testSaveInto(t, ProtocolIPv6)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testRestore(t *testing.T, protocol Protocol) {
|
func testRestore(t *testing.T, protocol Protocol) {
|
||||||
@ -908,11 +908,11 @@ func testRestore(t *testing.T, protocol Protocol) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRestoreIPv4(t *testing.T) {
|
func TestRestoreIPv4(t *testing.T) {
|
||||||
testRestore(t, ProtocolIpv4)
|
testRestore(t, ProtocolIPv4)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRestoreIPv6(t *testing.T) {
|
func TestRestoreIPv6(t *testing.T) {
|
||||||
testRestore(t, ProtocolIpv6)
|
testRestore(t, ProtocolIPv6)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestRestoreAll tests only the simplest use case, as flag handling code is already tested in TestRestore
|
// TestRestoreAll tests only the simplest use case, as flag handling code is already tested in TestRestore
|
||||||
@ -932,7 +932,7 @@ func TestRestoreAll(t *testing.T) {
|
|||||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
runner := newInternal(&fexec, ProtocolIpv4, TestLockfilePath)
|
runner := newInternal(&fexec, ProtocolIPv4, TestLockfilePath)
|
||||||
defer os.Remove(TestLockfilePath)
|
defer os.Remove(TestLockfilePath)
|
||||||
|
|
||||||
err := runner.RestoreAll([]byte{}, NoFlushTables, RestoreCounters)
|
err := runner.RestoreAll([]byte{}, NoFlushTables, RestoreCounters)
|
||||||
@ -973,7 +973,7 @@ func TestRestoreAllWait(t *testing.T) {
|
|||||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
runner := newInternal(&fexec, ProtocolIpv4, TestLockfilePath)
|
runner := newInternal(&fexec, ProtocolIPv4, TestLockfilePath)
|
||||||
defer os.Remove(TestLockfilePath)
|
defer os.Remove(TestLockfilePath)
|
||||||
|
|
||||||
err := runner.RestoreAll([]byte{}, NoFlushTables, RestoreCounters)
|
err := runner.RestoreAll([]byte{}, NoFlushTables, RestoreCounters)
|
||||||
@ -1018,7 +1018,7 @@ func TestRestoreAllWaitOldIptablesRestore(t *testing.T) {
|
|||||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
runner := newInternal(&fexec, ProtocolIpv4, TestLockfilePath)
|
runner := newInternal(&fexec, ProtocolIPv4, TestLockfilePath)
|
||||||
defer os.Remove(TestLockfilePath)
|
defer os.Remove(TestLockfilePath)
|
||||||
|
|
||||||
err := runner.RestoreAll([]byte{}, NoFlushTables, RestoreCounters)
|
err := runner.RestoreAll([]byte{}, NoFlushTables, RestoreCounters)
|
||||||
@ -1064,7 +1064,7 @@ func TestRestoreAllGrabNewLock(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
runner := newInternal(&fexec, ProtocolIpv4, TestLockfilePath)
|
runner := newInternal(&fexec, ProtocolIPv4, TestLockfilePath)
|
||||||
defer os.Remove(TestLockfilePath)
|
defer os.Remove(TestLockfilePath)
|
||||||
|
|
||||||
// Grab the /run lock and ensure the RestoreAll fails
|
// Grab the /run lock and ensure the RestoreAll fails
|
||||||
@ -1106,7 +1106,7 @@ func TestRestoreAllGrabOldLock(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
runner := newInternal(&fexec, ProtocolIpv4, TestLockfilePath)
|
runner := newInternal(&fexec, ProtocolIPv4, TestLockfilePath)
|
||||||
defer os.Remove(TestLockfilePath)
|
defer os.Remove(TestLockfilePath)
|
||||||
|
|
||||||
// Grab the abstract @xtables socket
|
// Grab the abstract @xtables socket
|
||||||
@ -1146,7 +1146,7 @@ func TestRestoreAllWaitBackportedIptablesRestore(t *testing.T) {
|
|||||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
runner := newInternal(&fexec, ProtocolIpv4, TestLockfilePath)
|
runner := newInternal(&fexec, ProtocolIPv4, TestLockfilePath)
|
||||||
defer os.Remove(TestLockfilePath)
|
defer os.Remove(TestLockfilePath)
|
||||||
|
|
||||||
err := runner.RestoreAll([]byte{}, NoFlushTables, RestoreCounters)
|
err := runner.RestoreAll([]byte{}, NoFlushTables, RestoreCounters)
|
||||||
|
@ -180,7 +180,7 @@ func (mfc *monitorFakeCmd) Stop() {
|
|||||||
|
|
||||||
func TestIPTablesMonitor(t *testing.T) {
|
func TestIPTablesMonitor(t *testing.T) {
|
||||||
mfe := newMonitorFakeExec()
|
mfe := newMonitorFakeExec()
|
||||||
ipt := New(mfe, ProtocolIpv4)
|
ipt := New(mfe, ProtocolIPv4)
|
||||||
|
|
||||||
var reloads uint32
|
var reloads uint32
|
||||||
stopCh := make(chan struct{})
|
stopCh := make(chan struct{})
|
||||||
|
@ -62,12 +62,12 @@ type FakeIPTables struct {
|
|||||||
|
|
||||||
// NewFake returns a no-op iptables.Interface
|
// NewFake returns a no-op iptables.Interface
|
||||||
func NewFake() *FakeIPTables {
|
func NewFake() *FakeIPTables {
|
||||||
return &FakeIPTables{protocol: iptables.ProtocolIpv4}
|
return &FakeIPTables{protocol: iptables.ProtocolIPv4}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewIpv6Fake returns a no-op iptables.Interface with IsIPv6() == true
|
// NewIPv6Fake returns a no-op iptables.Interface with IsIPv6() == true
|
||||||
func NewIpv6Fake() *FakeIPTables {
|
func NewIPv6Fake() *FakeIPTables {
|
||||||
return &FakeIPTables{protocol: iptables.ProtocolIpv6}
|
return &FakeIPTables{protocol: iptables.ProtocolIPv6}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetHasRandomFully is part of iptables.Interface
|
// SetHasRandomFully is part of iptables.Interface
|
||||||
@ -103,7 +103,7 @@ func (*FakeIPTables) DeleteRule(table iptables.Table, chain iptables.Chain, args
|
|||||||
|
|
||||||
// IsIPv6 is part of iptables.Interface
|
// IsIPv6 is part of iptables.Interface
|
||||||
func (f *FakeIPTables) IsIPv6() bool {
|
func (f *FakeIPTables) IsIPv6() bool {
|
||||||
return f.protocol == iptables.ProtocolIpv6
|
return f.protocol == iptables.ProtocolIPv6
|
||||||
}
|
}
|
||||||
|
|
||||||
// Protocol is part of iptables.Interface
|
// Protocol is part of iptables.Interface
|
||||||
|
Loading…
Reference in New Issue
Block a user