From 9551ecb7c3318749af6a716fd0daaf6b701416d9 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Fri, 10 Apr 2020 09:25:48 -0700 Subject: [PATCH] Cleanup: Change "Ip" to "IP" in func and var names --- cmd/kube-proxy/app/server_others.go | 12 +-- cmd/kube-proxy/app/server_others_test.go | 52 ++++++------- .../network/hostport/fake_iptables.go | 4 +- .../network/hostport/hostport_manager.go | 10 +-- .../network/hostport/hostport_manager_test.go | 2 +- .../network/hostport/hostport_syncer_test.go | 2 +- .../network/kubenet/kubenet_linux.go | 4 +- pkg/kubelet/kubelet.go | 4 +- pkg/proxy/ipvs/proxier.go | 4 +- pkg/proxy/util/iptables/traffic_test.go | 10 +-- pkg/proxy/winuserspace/proxier.go | 8 +- pkg/util/iptables/iptables.go | 16 ++-- pkg/util/iptables/iptables_test.go | 74 +++++++++---------- pkg/util/iptables/monitor_test.go | 2 +- pkg/util/iptables/testing/fake.go | 10 +-- 15 files changed, 107 insertions(+), 107 deletions(-) diff --git a/cmd/kube-proxy/app/server_others.go b/cmd/kube-proxy/app/server_others.go index f6b73bdb451..38cd4c14deb 100644 --- a/cmd/kube-proxy/app/server_others.go +++ b/cmd/kube-proxy/app/server_others.go @@ -91,10 +91,10 @@ func newProxyServer( return nil, fmt.Errorf("unable to register configz: %s", err) } - protocol := utiliptables.ProtocolIpv4 + protocol := utiliptables.ProtocolIPv4 if net.ParseIP(config.BindAddress).To4() == nil { klog.V(0).Infof("IPv6 bind address (%s), assume IPv6 operation", config.BindAddress) - protocol = utiliptables.ProtocolIpv6 + protocol = utiliptables.ProtocolIPv6 } var iptInterface utiliptables.Interface @@ -201,10 +201,10 @@ func newProxyServer( var ipt [2]utiliptables.Interface if iptInterface.IsIPv6() { ipt[1] = iptInterface - ipt[0] = utiliptables.New(execer, utiliptables.ProtocolIpv4) + ipt[0] = utiliptables.New(execer, utiliptables.ProtocolIPv4) } else { ipt[0] = iptInterface - ipt[1] = utiliptables.New(execer, utiliptables.ProtocolIpv6) + ipt[1] = utiliptables.New(execer, utiliptables.ProtocolIPv6) } // Always ordered to match []ipt @@ -269,10 +269,10 @@ func newProxyServer( var ipt [2]utiliptables.Interface if iptInterface.IsIPv6() { ipt[1] = iptInterface - ipt[0] = utiliptables.New(execer, utiliptables.ProtocolIpv4) + ipt[0] = utiliptables.New(execer, utiliptables.ProtocolIPv4) } else { ipt[0] = iptInterface - ipt[1] = utiliptables.New(execer, utiliptables.ProtocolIpv6) + ipt[1] = utiliptables.New(execer, utiliptables.ProtocolIPv6) } nodeIPs := nodeIPTuple(config.BindAddress) diff --git a/cmd/kube-proxy/app/server_others_test.go b/cmd/kube-proxy/app/server_others_test.go index f074aee887f..30a09c8576a 100644 --- a/cmd/kube-proxy/app/server_others_test.go +++ b/cmd/kube-proxy/app/server_others_test.go @@ -214,8 +214,8 @@ func Test_getLocalDetector(t *testing.T) { { mode: proxyconfigapi.LocalModeClusterCIDR, config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101/64"}, - ipt: utiliptablestest.NewIpv6Fake(), - expected: resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/64", utiliptablestest.NewIpv6Fake())), + ipt: utiliptablestest.NewIPv6Fake(), + expected: resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/64", utiliptablestest.NewIPv6Fake())), errExpected: false, }, { @@ -228,14 +228,14 @@ func Test_getLocalDetector(t *testing.T) { { mode: proxyconfigapi.LocalModeClusterCIDR, config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101"}, - ipt: utiliptablestest.NewIpv6Fake(), + ipt: utiliptablestest.NewIPv6Fake(), expected: nil, errExpected: true, }, { mode: proxyconfigapi.LocalModeClusterCIDR, config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "10.0.0.0/14"}, - ipt: utiliptablestest.NewIpv6Fake(), + ipt: utiliptablestest.NewIPv6Fake(), expected: nil, errExpected: true, }, @@ -265,8 +265,8 @@ func Test_getLocalDetector(t *testing.T) { { mode: proxyconfigapi.LocalModeNodeCIDR, config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101/64"}, - ipt: utiliptablestest.NewIpv6Fake(), - expected: resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("2002::1234:abcd:ffff:c0a8:101/96", utiliptablestest.NewIpv6Fake())), + ipt: 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"), errExpected: false, }, @@ -281,7 +281,7 @@ func Test_getLocalDetector(t *testing.T) { { mode: proxyconfigapi.LocalModeNodeCIDR, config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "2002::1234:abcd:ffff:c0a8:101"}, - ipt: utiliptablestest.NewIpv6Fake(), + ipt: utiliptablestest.NewIPv6Fake(), expected: nil, nodeInfo: makeNodeWithPodCIDRs("2002::1234:abcd:ffff:c0a8:101"), errExpected: true, @@ -289,7 +289,7 @@ func Test_getLocalDetector(t *testing.T) { { mode: proxyconfigapi.LocalModeNodeCIDR, config: &proxyconfigapi.KubeProxyConfiguration{ClusterCIDR: "10.0.0.0/14"}, - ipt: utiliptablestest.NewIpv6Fake(), + ipt: utiliptablestest.NewIPv6Fake(), expected: nil, nodeInfo: makeNodeWithPodCIDRs("10.0.0.0/24"), errExpected: true, @@ -350,25 +350,25 @@ func Test_getDualStackLocalDetectorTuple(t *testing.T) { { mode: proxyconfigapi.LocalModeClusterCIDR, 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)( 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, }, { mode: proxyconfigapi.LocalModeClusterCIDR, 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)( 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, }, { mode: proxyconfigapi.LocalModeClusterCIDR, 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{ resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("10.0.0.0/14", utiliptablestest.NewFake())), proxyutiliptables.NewNoOpLocalDetector()}, @@ -377,16 +377,16 @@ func Test_getDualStackLocalDetectorTuple(t *testing.T) { { mode: proxyconfigapi.LocalModeClusterCIDR, 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{ 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, }, { mode: proxyconfigapi.LocalModeClusterCIDR, 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()}, errExpected: false, }, @@ -394,27 +394,27 @@ func Test_getDualStackLocalDetectorTuple(t *testing.T) { { mode: proxyconfigapi.LocalModeNodeCIDR, 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)( 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"), errExpected: false, }, { mode: proxyconfigapi.LocalModeNodeCIDR, 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)( 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"), errExpected: false, }, { mode: proxyconfigapi.LocalModeNodeCIDR, 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{ resolveLocalDetector(t)(proxyutiliptables.NewDetectLocalByCIDR("10.0.0.0/24", utiliptablestest.NewFake())), proxyutiliptables.NewNoOpLocalDetector()}, @@ -424,17 +424,17 @@ func Test_getDualStackLocalDetectorTuple(t *testing.T) { { mode: proxyconfigapi.LocalModeNodeCIDR, 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{ 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"), errExpected: false, }, { mode: proxyconfigapi.LocalModeNodeCIDR, 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()}, nodeInfo: makeNodeWithPodCIDRs(), errExpected: false, @@ -442,7 +442,7 @@ func Test_getDualStackLocalDetectorTuple(t *testing.T) { { mode: proxyconfigapi.LocalModeNodeCIDR, 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()}, nodeInfo: nil, errExpected: false, @@ -451,7 +451,7 @@ func Test_getDualStackLocalDetectorTuple(t *testing.T) { { mode: proxyconfigapi.LocalMode("abcd"), 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()}, errExpected: false, }, diff --git a/pkg/kubelet/dockershim/network/hostport/fake_iptables.go b/pkg/kubelet/dockershim/network/hostport/fake_iptables.go index e7b0abd49db..be59dd5a9a6 100644 --- a/pkg/kubelet/dockershim/network/hostport/fake_iptables.go +++ b/pkg/kubelet/dockershim/network/hostport/fake_iptables.go @@ -51,7 +51,7 @@ func NewFakeIPTables() *fakeIPTables { string(utiliptables.TableNAT): sets.NewString("PREROUTING", "INPUT", "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 { - return f.protocol == utiliptables.ProtocolIpv6 + return f.protocol == utiliptables.ProtocolIPv6 } func (f *fakeIPTables) Protocol() utiliptables.Protocol { diff --git a/pkg/kubelet/dockershim/network/hostport/hostport_manager.go b/pkg/kubelet/dockershim/network/hostport/hostport_manager.go index 38eabcb0ed0..f7e076ac49a 100644 --- a/pkg/kubelet/dockershim/network/hostport/hostport_manager.go +++ b/pkg/kubelet/dockershim/network/hostport/hostport_manager.go @@ -88,10 +88,10 @@ func (hm *hostportManager) Add(id string, podPortMapping *PodPortMapping, natInt return fmt.Errorf("invalid or missing IP of pod %s", podFullName) } podIP := podPortMapping.IP.String() - isIpv6 := utilnet.IsIPv6(podPortMapping.IP) + isIPv6 := utilnet.IsIPv6(podPortMapping.IP) - if isIpv6 != hm.iptables.IsIPv6() { - return fmt.Errorf("HostPortManager IP family mismatch: %v, isIPv6 - %v", podIP, isIpv6) + if isIPv6 != hm.iptables.IsIPv6() { + return fmt.Errorf("HostPortManager IP family mismatch: %v, isIPv6 - %v", podIP, isIPv6) } 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 // iptables rules have been added back. 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 { - err = conntrack.ClearEntriesForPort(hm.execer, port, isIpv6, v1.ProtocolUDP) + err = conntrack.ClearEntriesForPort(hm.execer, port, isIPv6, v1.ProtocolUDP) if err != nil { klog.Errorf("Failed to clear udp conntrack for port %d, error: %v", port, err) } diff --git a/pkg/kubelet/dockershim/network/hostport/hostport_manager_test.go b/pkg/kubelet/dockershim/network/hostport/hostport_manager_test.go index cb18e1d9180..a8d03affd92 100644 --- a/pkg/kubelet/dockershim/network/hostport/hostport_manager_test.go +++ b/pkg/kubelet/dockershim/network/hostport/hostport_manager_test.go @@ -387,7 +387,7 @@ func TestGetHostportChain(t *testing.T) { func TestHostportManagerIPv6(t *testing.T) { iptables := NewFakeIPTables() - iptables.protocol = utiliptables.ProtocolIpv6 + iptables.protocol = utiliptables.ProtocolIPv6 portOpener := NewFakeSocketManager() manager := &hostportManager{ hostPortMap: make(map[hostport]closeable), diff --git a/pkg/kubelet/dockershim/network/hostport/hostport_syncer_test.go b/pkg/kubelet/dockershim/network/hostport/hostport_syncer_test.go index 3179b3782e8..874da8780bb 100644 --- a/pkg/kubelet/dockershim/network/hostport/hostport_syncer_test.go +++ b/pkg/kubelet/dockershim/network/hostport/hostport_syncer_test.go @@ -244,7 +244,7 @@ func matchRule(chain *fakeChain, match string) bool { func TestOpenPodHostportsIPv6(t *testing.T) { fakeIPTables := NewFakeIPTables() - fakeIPTables.protocol = utiliptables.ProtocolIpv6 + fakeIPTables.protocol = utiliptables.ProtocolIPv6 fakeOpener := NewFakeSocketManager() h := &hostportSyncer{ diff --git a/pkg/kubelet/dockershim/network/kubenet/kubenet_linux.go b/pkg/kubelet/dockershim/network/kubenet/kubenet_linux.go index bf7a828ec2d..e878e7c6175 100644 --- a/pkg/kubelet/dockershim/network/kubenet/kubenet_linux.go +++ b/pkg/kubelet/dockershim/network/kubenet/kubenet_linux.go @@ -122,8 +122,8 @@ type kubenetNetworkPlugin struct { func NewPlugin(networkPluginDirs []string, cacheDir string) network.NetworkPlugin { execer := utilexec.New() - iptInterface := utiliptables.New(execer, utiliptables.ProtocolIpv4) - iptInterfacev6 := utiliptables.New(execer, utiliptables.ProtocolIpv6) + iptInterface := utiliptables.New(execer, utiliptables.ProtocolIPv4) + iptInterfacev6 := utiliptables.New(execer, utiliptables.ProtocolIPv6) return &kubenetNetworkPlugin{ podIPs: make(map[kubecontainer.ContainerID]utilsets.String), execer: utilexec.New(), diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index ffd4cd537ba..d4beb6685da 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -523,10 +523,10 @@ func NewMainKubelet(kubeCfg *kubeletconfiginternal.KubeletConfiguration, } httpClient := &http.Client{} parsedNodeIP := net.ParseIP(nodeIP) - protocol := utilipt.ProtocolIpv4 + protocol := utilipt.ProtocolIPv4 if utilnet.IsIPv6(parsedNodeIP) { klog.V(0).Infof("IPv6 node IP (%s), assume IPv6 operation", nodeIP) - protocol = utilipt.ProtocolIpv6 + protocol = utilipt.ProtocolIPv6 } klet := &Kubelet{ diff --git a/pkg/proxy/ipvs/proxier.go b/pkg/proxy/ipvs/proxier.go index b7bf69f5862..9f571e446a2 100644 --- a/pkg/proxy/ipvs/proxier.go +++ b/pkg/proxy/ipvs/proxier.go @@ -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 { legacyAddrs := make(map[string]bool) - isIpv6 := utilnet.IsIPv6(proxier.nodeIP) + isIPv6 := utilnet.IsIPv6(proxier.nodeIP) for _, addr := range currentBindAddrs { addrIsIPv6 := utilnet.IsIPv6(net.ParseIP(addr)) - if addrIsIPv6 && !isIpv6 || !addrIsIPv6 && isIpv6 { + if addrIsIPv6 && !isIPv6 || !addrIsIPv6 && isIPv6 { continue } if _, ok := activeBindAddrs[addr]; !ok { diff --git a/pkg/proxy/util/iptables/traffic_test.go b/pkg/proxy/util/iptables/traffic_test.go index 1ecee9b200f..c346dfb79fc 100644 --- a/pkg/proxy/util/iptables/traffic_test.go +++ b/pkg/proxy/util/iptables/traffic_test.go @@ -70,12 +70,12 @@ func TestNewDetectLocalByCIDR(t *testing.T) { }, { cidr: "2002::1234:abcd:ffff:c0a8:101/64", - ipt: iptablestest.NewIpv6Fake(), + ipt: iptablestest.NewIPv6Fake(), errExpected: false, }, { cidr: "10.0.0.0/14", - ipt: iptablestest.NewIpv6Fake(), + ipt: iptablestest.NewIPv6Fake(), errExpected: true, }, { @@ -90,7 +90,7 @@ func TestNewDetectLocalByCIDR(t *testing.T) { }, { cidr: "2002::1234:abcd:ffff:c0a8:101", - ipt: iptablestest.NewIpv6Fake(), + ipt: iptablestest.NewIPv6Fake(), errExpected: true, }, { @@ -100,7 +100,7 @@ func TestNewDetectLocalByCIDR(t *testing.T) { }, { cidr: "", - ipt: iptablestest.NewIpv6Fake(), + ipt: iptablestest.NewIPv6Fake(), errExpected: true, }, } @@ -137,7 +137,7 @@ func TestDetectLocalByCIDR(t *testing.T) { }, { cidr: "2002::1234:abcd:ffff:c0a8:101/64", - ipt: iptablestest.NewIpv6Fake(), + ipt: iptablestest.NewIPv6Fake(), chain: "TEST", args: []string{"arg1", "arg2"}, expectedJumpIfOutput: []string{"arg1", "arg2", "-s", "2002::1234:abcd:ffff:c0a8:101/64", "-j", "TEST"}, diff --git a/pkg/proxy/winuserspace/proxier.go b/pkg/proxy/winuserspace/proxier.go index bfeb4fdee2c..42f1c64af7e 100644 --- a/pkg/proxy/winuserspace/proxier.go +++ b/pkg/proxy/winuserspace/proxier.go @@ -213,7 +213,7 @@ func (proxier *Proxier) addServicePortPortal(servicePortPortalName ServicePortPo return nil, fmt.Errorf("could not parse ip '%q'", listenIP) } // 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 { return nil, err } else if !existed { @@ -262,7 +262,7 @@ func (proxier *Proxier) closeServicePortPortal(servicePortPortalName ServicePort // close the PortalProxy by deleting the service IP address if info.portal.ip != allAvailableInterfaces { serviceIP := net.ParseIP(info.portal.ip) - args := proxier.netshIpv4AddressDeleteArgs(serviceIP) + args := proxier.netshIPv4AddressDeleteArgs(serviceIP) if err := proxier.netsh.DeleteIPAddress(args); err != nil { return err } @@ -474,7 +474,7 @@ func isClosedError(err error) bool { 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() args := []string{ "interface", "ipv4", "add", "address", @@ -485,7 +485,7 @@ func (proxier *Proxier) netshIpv4AddressAddArgs(destIP net.IP) []string { return args } -func (proxier *Proxier) netshIpv4AddressDeleteArgs(destIP net.IP) []string { +func (proxier *Proxier) netshIPv4AddressDeleteArgs(destIP net.IP) []string { intName := proxier.netsh.GetInterfaceToAddIP() args := []string{ "interface", "ipv4", "delete", "address", diff --git a/pkg/util/iptables/iptables.go b/pkg/util/iptables/iptables.go index a15ac3a968b..946f898e90a 100644 --- a/pkg/util/iptables/iptables.go +++ b/pkg/util/iptables/iptables.go @@ -92,10 +92,10 @@ type Interface interface { type Protocol string const ( - // ProtocolIpv4 represents ipv4 protocol in iptables - ProtocolIpv4 Protocol = "IPv4" - // ProtocolIpv6 represents ipv6 protocol in iptables - ProtocolIpv6 Protocol = "IPv6" + // ProtocolIPv4 represents ipv4 protocol in iptables + ProtocolIPv4 Protocol = "IPv4" + // ProtocolIPv6 represents ipv6 protocol in iptables + ProtocolIPv6 Protocol = "IPv6" ) // 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 { - return runner.protocol == ProtocolIpv6 + return runner.protocol == ProtocolIPv6 } func (runner *runner) Protocol() Protocol { @@ -416,14 +416,14 @@ func (runner *runner) restoreInternal(args []string, data []byte, flush FlushFla } func iptablesSaveCommand(protocol Protocol) string { - if protocol == ProtocolIpv6 { + if protocol == ProtocolIPv6 { return cmdIP6TablesSave } return cmdIPTablesSave } func iptablesRestoreCommand(protocol Protocol) string { - if protocol == ProtocolIpv6 { + if protocol == ProtocolIPv6 { return cmdIP6TablesRestore } return cmdIPTablesRestore @@ -431,7 +431,7 @@ func iptablesRestoreCommand(protocol Protocol) string { } func iptablesCommand(protocol Protocol) string { - if protocol == ProtocolIpv6 { + if protocol == ProtocolIPv6 { return cmdIP6Tables } return cmdIPTables diff --git a/pkg/util/iptables/iptables_test.go b/pkg/util/iptables/iptables_test.go index 85855caced5..7a578419f51 100644 --- a/pkg/util/iptables/iptables_test.go +++ b/pkg/util/iptables/iptables_test.go @@ -68,11 +68,11 @@ func testIPTablesVersionCmds(t *testing.T, protocol Protocol) { } func TestIPTablesVersionCmdsIPv4(t *testing.T) { - testIPTablesVersionCmds(t, ProtocolIpv4) + testIPTablesVersionCmds(t, ProtocolIPv4) } func TestIPTablesVersionCmdsIPv6(t *testing.T) { - testIPTablesVersionCmds(t, ProtocolIpv6) + testIPTablesVersionCmds(t, ProtocolIPv6) } func testEnsureChain(t *testing.T, protocol Protocol) { @@ -127,12 +127,12 @@ func testEnsureChain(t *testing.T, protocol Protocol) { } } -func TestEnsureChainIpv4(t *testing.T) { - testEnsureChain(t, ProtocolIpv4) +func TestEnsureChainIPv4(t *testing.T) { + testEnsureChain(t, ProtocolIPv4) } -func TestEnsureChainIpv6(t *testing.T) { - testEnsureChain(t, ProtocolIpv6) +func TestEnsureChainIPv6(t *testing.T) { + testEnsureChain(t, ProtocolIPv6) } 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...) }, }, } - runner := New(&fexec, ProtocolIpv4) + runner := New(&fexec, ProtocolIPv4) // Success. err := runner.FlushChain(TableNAT, Chain("FOOBAR")) 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...) }, }, } - runner := New(&fexec, ProtocolIpv4) + runner := New(&fexec, ProtocolIPv4) // Success. err := runner.DeleteChain(TableNAT, Chain("FOOBAR")) 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...) }, }, } - runner := New(&fexec, ProtocolIpv4) + runner := New(&fexec, ProtocolIPv4) exists, err := runner.EnsureRule(Append, TableNAT, ChainOutput, "abc", "123") if err != nil { 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...) }, }, } - runner := New(&fexec, ProtocolIpv4) + runner := New(&fexec, ProtocolIPv4) exists, err := runner.EnsureRule(Append, TableNAT, ChainOutput, "abc", "123") if err != nil { 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...) }, }, } - runner := New(&fexec, ProtocolIpv4) + runner := New(&fexec, ProtocolIPv4) _, err := runner.EnsureRule(Append, TableNAT, ChainOutput, "abc", "123") if err == nil { 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...) }, }, } - runner := New(&fexec, ProtocolIpv4) + runner := New(&fexec, ProtocolIPv4) _, err := runner.EnsureRule(Append, TableNAT, ChainOutput, "abc", "123") if err == nil { 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...) }, }, } - runner := New(&fexec, ProtocolIpv4) + runner := New(&fexec, ProtocolIPv4) err := runner.DeleteRule(TableNAT, ChainOutput, "abc", "123") if err != nil { 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...) }, }, } - runner := New(&fexec, ProtocolIpv4) + runner := New(&fexec, ProtocolIPv4) err := runner.DeleteRule(TableNAT, ChainOutput, "abc", "123") if err != nil { 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...) }, }, } - runner := New(&fexec, ProtocolIpv4) + runner := New(&fexec, ProtocolIPv4) err := runner.DeleteRule(TableNAT, ChainOutput, "abc", "123") if err == nil { 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...) }, }, } - runner := New(&fexec, ProtocolIpv4) + runner := New(&fexec, ProtocolIPv4) err := runner.DeleteRule(TableNAT, ChainOutput, "abc", "123") if err == nil { 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...) }, }, } - ipt := New(&fexec, ProtocolIpv4) + ipt := New(&fexec, ProtocolIPv4) runner := ipt.(*runner) if 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 expectedCmd string }{ - {"iptablesCommand", ProtocolIpv4, cmdIPTables}, - {"iptablesCommand", ProtocolIpv6, cmdIP6Tables}, - {"iptablesSaveCommand", ProtocolIpv4, cmdIPTablesSave}, - {"iptablesSaveCommand", ProtocolIpv6, cmdIP6TablesSave}, - {"iptablesRestoreCommand", ProtocolIpv4, cmdIPTablesRestore}, - {"iptablesRestoreCommand", ProtocolIpv6, cmdIP6TablesRestore}, + {"iptablesCommand", ProtocolIPv4, cmdIPTables}, + {"iptablesCommand", ProtocolIPv6, cmdIP6Tables}, + {"iptablesSaveCommand", ProtocolIPv4, cmdIPTablesSave}, + {"iptablesSaveCommand", ProtocolIPv6, cmdIP6TablesSave}, + {"iptablesRestoreCommand", ProtocolIPv4, cmdIPTablesRestore}, + {"iptablesRestoreCommand", ProtocolIPv6, cmdIP6TablesRestore}, } for _, testCase := range testCases { 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...) }, }, } - runner := New(&fexec, ProtocolIpv4) + runner := New(&fexec, ProtocolIPv4) err := runner.DeleteChain(TableNAT, Chain("FOOBAR")) if err != nil { 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...) }, }, } - runner := New(&fexec, ProtocolIpv4) + runner := New(&fexec, ProtocolIPv4) err := runner.DeleteChain(TableNAT, Chain("FOOBAR")) if err != nil { 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...) }, }, } - runner := New(&fexec, ProtocolIpv4) + runner := New(&fexec, ProtocolIPv4) err := runner.DeleteChain(TableNAT, Chain("FOOBAR")) if err != nil { 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...) }, }, } - runner := New(&fexec, ProtocolIpv4) + runner := New(&fexec, ProtocolIPv4) err := runner.DeleteChain(TableNAT, Chain("FOOBAR")) if err != nil { t.Errorf("expected success, got %v", err) @@ -817,11 +817,11 @@ COMMIT } func TestSaveIntoIPv4(t *testing.T) { - testSaveInto(t, ProtocolIpv4) + testSaveInto(t, ProtocolIPv4) } func TestSaveIntoIPv6(t *testing.T) { - testSaveInto(t, ProtocolIpv6) + testSaveInto(t, ProtocolIPv6) } func testRestore(t *testing.T, protocol Protocol) { @@ -908,11 +908,11 @@ func testRestore(t *testing.T, protocol Protocol) { } func TestRestoreIPv4(t *testing.T) { - testRestore(t, ProtocolIpv4) + testRestore(t, ProtocolIPv4) } 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 @@ -932,7 +932,7 @@ func TestRestoreAll(t *testing.T) { 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) 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...) }, }, } - runner := newInternal(&fexec, ProtocolIpv4, TestLockfilePath) + runner := newInternal(&fexec, ProtocolIPv4, TestLockfilePath) defer os.Remove(TestLockfilePath) 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...) }, }, } - runner := newInternal(&fexec, ProtocolIpv4, TestLockfilePath) + runner := newInternal(&fexec, ProtocolIPv4, TestLockfilePath) defer os.Remove(TestLockfilePath) 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) // 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) // 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...) }, }, } - runner := newInternal(&fexec, ProtocolIpv4, TestLockfilePath) + runner := newInternal(&fexec, ProtocolIPv4, TestLockfilePath) defer os.Remove(TestLockfilePath) err := runner.RestoreAll([]byte{}, NoFlushTables, RestoreCounters) diff --git a/pkg/util/iptables/monitor_test.go b/pkg/util/iptables/monitor_test.go index 06465987097..a9d915e90e5 100644 --- a/pkg/util/iptables/monitor_test.go +++ b/pkg/util/iptables/monitor_test.go @@ -180,7 +180,7 @@ func (mfc *monitorFakeCmd) Stop() { func TestIPTablesMonitor(t *testing.T) { mfe := newMonitorFakeExec() - ipt := New(mfe, ProtocolIpv4) + ipt := New(mfe, ProtocolIPv4) var reloads uint32 stopCh := make(chan struct{}) diff --git a/pkg/util/iptables/testing/fake.go b/pkg/util/iptables/testing/fake.go index 907cdc6c643..46b5641b499 100644 --- a/pkg/util/iptables/testing/fake.go +++ b/pkg/util/iptables/testing/fake.go @@ -62,12 +62,12 @@ type FakeIPTables struct { // NewFake returns a no-op iptables.Interface func NewFake() *FakeIPTables { - return &FakeIPTables{protocol: iptables.ProtocolIpv4} + return &FakeIPTables{protocol: iptables.ProtocolIPv4} } -// NewIpv6Fake returns a no-op iptables.Interface with IsIPv6() == true -func NewIpv6Fake() *FakeIPTables { - return &FakeIPTables{protocol: iptables.ProtocolIpv6} +// NewIPv6Fake returns a no-op iptables.Interface with IsIPv6() == true +func NewIPv6Fake() *FakeIPTables { + return &FakeIPTables{protocol: iptables.ProtocolIPv6} } // 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 func (f *FakeIPTables) IsIPv6() bool { - return f.protocol == iptables.ProtocolIpv6 + return f.protocol == iptables.ProtocolIPv6 } // Protocol is part of iptables.Interface