Skip to content

Commit 62e58a6

Browse files
committed
Fix some lint errors in pkg/proxy
1 parent 086a86b commit 62e58a6

File tree

5 files changed

+45
-18
lines changed

5 files changed

+45
-18
lines changed

cmd/kube-proxy/app/server_others.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func newProxyServer(
237237
}, nil
238238
}
239239

240-
func getProxyMode(proxyMode string, iptver iptables.IPTablesVersioner, khandle ipvs.KernelHandler, ipsetver ipvs.IPSetVersioner, kcompat iptables.KernelCompatTester) string {
240+
func getProxyMode(proxyMode string, iptver iptables.Versioner, khandle ipvs.KernelHandler, ipsetver ipvs.IPSetVersioner, kcompat iptables.KernelCompatTester) string {
241241
switch proxyMode {
242242
case proxyModeUserspace:
243243
return proxyModeUserspace
@@ -250,7 +250,7 @@ func getProxyMode(proxyMode string, iptver iptables.IPTablesVersioner, khandle i
250250
return tryIPTablesProxy(iptver, kcompat)
251251
}
252252

253-
func tryIPVSProxy(iptver iptables.IPTablesVersioner, khandle ipvs.KernelHandler, ipsetver ipvs.IPSetVersioner, kcompat iptables.KernelCompatTester) string {
253+
func tryIPVSProxy(iptver iptables.Versioner, khandle ipvs.KernelHandler, ipsetver ipvs.IPSetVersioner, kcompat iptables.KernelCompatTester) string {
254254
// guaranteed false on error, error only necessary for debugging
255255
// IPVS Proxier relies on ip_vs_* kernel modules and ipset
256256
useIPVSProxy, err := ipvs.CanUseIPVSProxier(khandle, ipsetver)
@@ -267,7 +267,7 @@ func tryIPVSProxy(iptver iptables.IPTablesVersioner, khandle ipvs.KernelHandler,
267267
return tryIPTablesProxy(iptver, kcompat)
268268
}
269269

270-
func tryIPTablesProxy(iptver iptables.IPTablesVersioner, kcompat iptables.KernelCompatTester) string {
270+
func tryIPTablesProxy(iptver iptables.Versioner, kcompat iptables.KernelCompatTester) string {
271271
// guaranteed false on error, error only necessary for debugging
272272
useIPTablesProxy, err := iptables.CanUseIPTablesProxier(iptver, kcompat)
273273
if err != nil {

hack/.golint_failures

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,7 @@ pkg/master/tunneler
194194
pkg/proxy
195195
pkg/proxy/apis/config
196196
pkg/proxy/apis/config/v1alpha1
197-
pkg/proxy/iptables
198197
pkg/proxy/userspace
199-
pkg/proxy/util
200198
pkg/proxy/winkernel
201199
pkg/proxy/winuserspace
202200
pkg/quota/v1/evaluator/core

pkg/proxy/iptables/proxier.go

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,18 @@ const (
7373
// the kubernetes postrouting chain
7474
kubePostroutingChain utiliptables.Chain = "KUBE-POSTROUTING"
7575

76-
// the mark-for-masquerade chain
76+
// KubeMarkMasqChain is the mark-for-masquerade chain
7777
KubeMarkMasqChain utiliptables.Chain = "KUBE-MARK-MASQ"
7878

79-
// the mark-for-drop chain
79+
// KubeMarkDropChain is the mark-for-drop chain
8080
KubeMarkDropChain utiliptables.Chain = "KUBE-MARK-DROP"
8181

8282
// the kubernetes forward chain
8383
kubeForwardChain utiliptables.Chain = "KUBE-FORWARD"
8484
)
8585

86-
// IPTablesVersioner can query the current iptables version.
87-
type IPTablesVersioner interface {
86+
// Versioner can query the current iptables version.
87+
type Versioner interface {
8888
// returns "X.Y.Z"
8989
GetVersion() (string, error)
9090
}
@@ -100,7 +100,7 @@ type KernelCompatTester interface {
100100
// the iptables version and for the existence of kernel features. It may return
101101
// an error if it fails to get the iptables version without error, in which
102102
// case it will also return false.
103-
func CanUseIPTablesProxier(iptver IPTablesVersioner, kcompat KernelCompatTester) (bool, error) {
103+
func CanUseIPTablesProxier(iptver Versioner, kcompat KernelCompatTester) (bool, error) {
104104
minVersion, err := utilversion.ParseGeneric(iptablesMinVersion)
105105
if err != nil {
106106
return false, err
@@ -124,12 +124,14 @@ func CanUseIPTablesProxier(iptver IPTablesVersioner, kcompat KernelCompatTester)
124124
return true, nil
125125
}
126126

127+
// LinuxKernelCompatTester is the Linux implementation of KernelCompatTester
127128
type LinuxKernelCompatTester struct{}
128129

130+
// IsCompatible checks for the required sysctls. We don't care about the value, just
131+
// that it exists. If this Proxier is chosen, we'll initialize it as we
132+
// need.
129133
func (lkct LinuxKernelCompatTester) IsCompatible() error {
130-
// Check for the required sysctls. We don't care about the value, just
131-
// that it exists. If this Proxier is chosen, we'll initialize it as we
132-
// need.
134+
133135
_, err := utilsysctl.New().GetSysctl(sysctlRouteLocalnet)
134136
return err
135137
}
@@ -507,21 +509,29 @@ func (proxier *Proxier) isInitialized() bool {
507509
return atomic.LoadInt32(&proxier.initialized) > 0
508510
}
509511

512+
// OnServiceAdd is called whenever creation of new service object
513+
// is observed.
510514
func (proxier *Proxier) OnServiceAdd(service *v1.Service) {
511515
proxier.OnServiceUpdate(nil, service)
512516
}
513517

518+
// OnServiceUpdate is called whenever modification of an existing
519+
// service object is observed.
514520
func (proxier *Proxier) OnServiceUpdate(oldService, service *v1.Service) {
515521
if proxier.serviceChanges.Update(oldService, service) && proxier.isInitialized() {
516522
proxier.syncRunner.Run()
517523
}
518524
}
519525

526+
// OnServiceDelete is called whenever deletion of an existing service
527+
// object is observed.
520528
func (proxier *Proxier) OnServiceDelete(service *v1.Service) {
521529
proxier.OnServiceUpdate(service, nil)
522530

523531
}
524532

533+
// OnServiceSynced is called once all the initial even handlers were
534+
// called and the state is fully propagated to local cache.
525535
func (proxier *Proxier) OnServiceSynced() {
526536
proxier.mu.Lock()
527537
proxier.servicesSynced = true
@@ -532,20 +542,28 @@ func (proxier *Proxier) OnServiceSynced() {
532542
proxier.syncProxyRules()
533543
}
534544

545+
// OnEndpointsAdd is called whenever creation of new endpoints object
546+
// is observed.
535547
func (proxier *Proxier) OnEndpointsAdd(endpoints *v1.Endpoints) {
536548
proxier.OnEndpointsUpdate(nil, endpoints)
537549
}
538550

551+
// OnEndpointsUpdate is called whenever modification of an existing
552+
// endpoints object is observed.
539553
func (proxier *Proxier) OnEndpointsUpdate(oldEndpoints, endpoints *v1.Endpoints) {
540554
if proxier.endpointsChanges.Update(oldEndpoints, endpoints) && proxier.isInitialized() {
541555
proxier.syncRunner.Run()
542556
}
543557
}
544558

559+
// OnEndpointsDelete is called whever deletion of an existing endpoints
560+
// object is observed.
545561
func (proxier *Proxier) OnEndpointsDelete(endpoints *v1.Endpoints) {
546562
proxier.OnEndpointsUpdate(endpoints, nil)
547563
}
548564

565+
// OnEndpointsSynced is called once all the initial event handlers were
566+
// called and the state is fully propagated to local cache.
549567
func (proxier *Proxier) OnEndpointsSynced() {
550568
proxier.mu.Lock()
551569
proxier.endpointsSynced = true

pkg/proxy/util/endpoints.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ func IPPart(s string) string {
3939
return ""
4040
}
4141
// Check if host string is a valid IP address
42-
if ip := net.ParseIP(host); ip != nil {
43-
return ip.String()
44-
} else {
42+
ip := net.ParseIP(host)
43+
if ip == nil {
4544
klog.Errorf("invalid IP part '%s'", host)
45+
return ""
4646
}
47-
return ""
47+
return ip.String()
4848
}
4949

5050
// PortPart returns just the port part of an endpoint string.

pkg/proxy/util/utils.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,23 @@ import (
3333
)
3434

3535
const (
36+
// IPv4ZeroCIDR is the CIDR block for the whole IPv4 address space
3637
IPv4ZeroCIDR = "0.0.0.0/0"
38+
39+
// IPv6ZeroCIDR is the CIDR block for the whole IPv6 address space
3740
IPv6ZeroCIDR = "::/0"
3841
)
3942

4043
var (
44+
// ErrAddressNotAllowed indicates the address is not allowed
4145
ErrAddressNotAllowed = errors.New("address not allowed")
42-
ErrNoAddresses = errors.New("No addresses for hostname")
46+
47+
// ErrNoAddresses indicates there are no addresses for the hostname
48+
ErrNoAddresses = errors.New("No addresses for hostname")
4349
)
4450

51+
// IsZeroCIDR checks whether the input CIDR string is either
52+
// the IPv4 or IPv6 zero CIDR
4553
func IsZeroCIDR(cidr string) bool {
4654
if cidr == IPv4ZeroCIDR || cidr == IPv6ZeroCIDR {
4755
return true
@@ -89,6 +97,8 @@ func IsProxyableHostname(ctx context.Context, resolv Resolver, hostname string)
8997
return nil
9098
}
9199

100+
// IsLocalIP checks if a given IP address is bound to an interface
101+
// on the local system
92102
func IsLocalIP(ip string) (bool, error) {
93103
addrs, err := net.InterfaceAddrs()
94104
if err != nil {
@@ -106,6 +116,7 @@ func IsLocalIP(ip string) (bool, error) {
106116
return false, nil
107117
}
108118

119+
// ShouldSkipService checks if a given service should skip proxying
109120
func ShouldSkipService(svcName types.NamespacedName, service *v1.Service) bool {
110121
// if ClusterIP is "None" or empty, skip proxying
111122
if !helper.IsServiceIPSet(service) {

0 commit comments

Comments
 (0)