diff --git a/cmd/kube-proxy/app/server_others.go b/cmd/kube-proxy/app/server_others.go index 4eff0043d3e..f6b73bdb451 100644 --- a/cmd/kube-proxy/app/server_others.go +++ b/cmd/kube-proxy/app/server_others.go @@ -199,7 +199,7 @@ func newProxyServer( // Create iptables handlers for both families, one is already created // Always ordered as IPv4, IPv6 var ipt [2]utiliptables.Interface - if iptInterface.IsIpv6() { + if iptInterface.IsIPv6() { ipt[1] = iptInterface ipt[0] = utiliptables.New(execer, utiliptables.ProtocolIpv4) } else { @@ -267,7 +267,7 @@ func newProxyServer( // Create iptables handlers for both families, one is already created // Always ordered as IPv4, IPv6 var ipt [2]utiliptables.Interface - if iptInterface.IsIpv6() { + if iptInterface.IsIPv6() { ipt[1] = iptInterface ipt[0] = utiliptables.New(execer, utiliptables.ProtocolIpv4) } else { diff --git a/pkg/kubelet/dockershim/network/hostport/fake_iptables.go b/pkg/kubelet/dockershim/network/hostport/fake_iptables.go index 1f15170bdcb..e7b0abd49db 100644 --- a/pkg/kubelet/dockershim/network/hostport/fake_iptables.go +++ b/pkg/kubelet/dockershim/network/hostport/fake_iptables.go @@ -223,7 +223,7 @@ func (f *fakeIPTables) DeleteRule(tableName utiliptables.Table, chainName utilip return nil } -func (f *fakeIPTables) IsIpv6() bool { +func (f *fakeIPTables) IsIPv6() bool { return f.protocol == utiliptables.ProtocolIpv6 } diff --git a/pkg/kubelet/dockershim/network/hostport/hostport.go b/pkg/kubelet/dockershim/network/hostport/hostport.go index 3c01b6e866d..1cf83d134c6 100644 --- a/pkg/kubelet/dockershim/network/hostport/hostport.go +++ b/pkg/kubelet/dockershim/network/hostport/hostport.go @@ -137,7 +137,7 @@ func ensureKubeHostportChains(iptables utiliptables.Interface, natInterfaceName if natInterfaceName != "" && natInterfaceName != "lo" { // Need to SNAT traffic from localhost localhost := "127.0.0.0/8" - if iptables.IsIpv6() { + if iptables.IsIPv6() { localhost = "::1/128" } args = []string{"-m", "comment", "--comment", "SNAT for localhost access to hostports", "-o", natInterfaceName, "-s", localhost, "-j", "MASQUERADE"} diff --git a/pkg/kubelet/dockershim/network/hostport/hostport_manager.go b/pkg/kubelet/dockershim/network/hostport/hostport_manager.go index 9d1286aaaf2..38eabcb0ed0 100644 --- a/pkg/kubelet/dockershim/network/hostport/hostport_manager.go +++ b/pkg/kubelet/dockershim/network/hostport/hostport_manager.go @@ -90,7 +90,7 @@ func (hm *hostportManager) Add(id string, podPortMapping *PodPortMapping, natInt podIP := podPortMapping.IP.String() 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) } diff --git a/pkg/kubelet/dockershim/network/hostport/hostport_syncer.go b/pkg/kubelet/dockershim/network/hostport/hostport_syncer.go index 2d8b1bf4368..517c5a30889 100644 --- a/pkg/kubelet/dockershim/network/hostport/hostport_syncer.go +++ b/pkg/kubelet/dockershim/network/hostport/hostport_syncer.go @@ -199,7 +199,7 @@ func (h *hostportSyncer) SyncHostports(natInterfaceName string, activePodPortMap klog.V(4).Infof("syncHostportsRules took %v", time.Since(start)) }() - hostportPodMap, err := gatherAllHostports(activePodPortMappings, h.iptables.IsIpv6()) + hostportPodMap, err := gatherAllHostports(activePodPortMappings, h.iptables.IsIPv6()) if err != nil { return err } diff --git a/pkg/proxy/iptables/proxier.go b/pkg/proxy/iptables/proxier.go index 67c22a4c3f2..4344319482d 100644 --- a/pkg/proxy/iptables/proxier.go +++ b/pkg/proxy/iptables/proxier.go @@ -289,7 +289,7 @@ func NewProxier(ipt utiliptables.Interface, serviceHealthServer := healthcheck.NewServiceHealthServer(hostname, recorder) - isIPv6 := ipt.IsIpv6() + isIPv6 := ipt.IsIPv6() proxier := &Proxier{ portsMap: make(map[utilproxy.LocalPort]utilproxy.Closeable), serviceMap: make(proxy.ServiceMap), @@ -1468,7 +1468,7 @@ func (proxier *Proxier) syncProxyRules() { if err != nil { klog.Errorf("Failed to get node ip address matching nodeport cidr") } else { - isIPv6 := proxier.iptables.IsIpv6() + isIPv6 := proxier.iptables.IsIPv6() for address := range addresses { // TODO(thockin, m1093782566): If/when we have dual-stack support we will want to distinguish v4 from v6 zero-CIDRs. if utilproxy.IsZeroCIDR(address) { diff --git a/pkg/proxy/ipvs/proxier.go b/pkg/proxy/ipvs/proxier.go index b2b5c6bb5fb..b7bf69f5862 100644 --- a/pkg/proxy/ipvs/proxier.go +++ b/pkg/proxy/ipvs/proxier.go @@ -2090,8 +2090,8 @@ func (proxier *Proxier) getLegacyBindAddr(activeBindAddrs map[string]bool, curre legacyAddrs := make(map[string]bool) isIpv6 := utilnet.IsIPv6(proxier.nodeIP) for _, addr := range currentBindAddrs { - addrIsIpv6 := utilnet.IsIPv6(net.ParseIP(addr)) - if addrIsIpv6 && !isIpv6 || !addrIsIpv6 && isIpv6 { + addrIsIPv6 := utilnet.IsIPv6(net.ParseIP(addr)) + if addrIsIPv6 && !isIpv6 || !addrIsIPv6 && isIpv6 { continue } if _, ok := activeBindAddrs[addr]; !ok { diff --git a/pkg/proxy/util/iptables/traffic.go b/pkg/proxy/util/iptables/traffic.go index 1ec572921fe..84f6ef3ddf1 100644 --- a/pkg/proxy/util/iptables/traffic.go +++ b/pkg/proxy/util/iptables/traffic.go @@ -66,8 +66,8 @@ type detectLocalByCIDR struct { // NewDetectLocalByCIDR implements the LocalTrafficDetector interface using a CIDR. This can be used when a single CIDR // range can be used to capture the notion of local traffic. func NewDetectLocalByCIDR(cidr string, ipt utiliptables.Interface) (LocalTrafficDetector, error) { - if utilnet.IsIPv6CIDRString(cidr) != ipt.IsIpv6() { - return nil, fmt.Errorf("CIDR %s has incorrect IP version: expect isIPv6=%t", cidr, ipt.IsIpv6()) + if utilnet.IsIPv6CIDRString(cidr) != ipt.IsIPv6() { + return nil, fmt.Errorf("CIDR %s has incorrect IP version: expect isIPv6=%t", cidr, ipt.IsIPv6()) } _, _, err := net.ParseCIDR(cidr) if err != nil { diff --git a/pkg/util/iptables/iptables.go b/pkg/util/iptables/iptables.go index 5ae88b9e42c..a15ac3a968b 100644 --- a/pkg/util/iptables/iptables.go +++ b/pkg/util/iptables/iptables.go @@ -55,8 +55,8 @@ type Interface interface { EnsureRule(position RulePosition, table Table, chain Chain, args ...string) (bool, error) // DeleteRule checks if the specified rule is present and, if so, deletes it. DeleteRule(table Table, chain Chain, args ...string) error - // IsIpv6 returns true if this is managing ipv6 tables. - IsIpv6() bool + // IsIPv6 returns true if this is managing ipv6 tables. + IsIPv6() bool // Protocol returns the IP family this instance is managing, Protocol() Protocol // SaveInto calls `iptables-save` for table and stores result in a given buffer. @@ -321,7 +321,7 @@ func (runner *runner) DeleteRule(table Table, chain Chain, args ...string) error return nil } -func (runner *runner) IsIpv6() bool { +func (runner *runner) IsIPv6() bool { return runner.protocol == ProtocolIpv6 } diff --git a/pkg/util/iptables/testing/fake.go b/pkg/util/iptables/testing/fake.go index 9bfdb9e9b32..907cdc6c643 100644 --- a/pkg/util/iptables/testing/fake.go +++ b/pkg/util/iptables/testing/fake.go @@ -101,8 +101,8 @@ func (*FakeIPTables) DeleteRule(table iptables.Table, chain iptables.Chain, args return nil } -// IsIpv6 is part of iptables.Interface -func (f *FakeIPTables) IsIpv6() bool { +// IsIPv6 is part of iptables.Interface +func (f *FakeIPTables) IsIPv6() bool { return f.protocol == iptables.ProtocolIpv6 }