Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
62e58a66
Commit
62e58a66
authored
May 09, 2019
by
Brad Hoekstra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix some lint errors in pkg/proxy
parent
086a86b9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
45 additions
and
18 deletions
+45
-18
server_others.go
cmd/kube-proxy/app/server_others.go
+3
-3
.golint_failures
hack/.golint_failures
+0
-2
proxier.go
pkg/proxy/iptables/proxier.go
+26
-8
endpoints.go
pkg/proxy/util/endpoints.go
+4
-4
utils.go
pkg/proxy/util/utils.go
+12
-1
No files found.
cmd/kube-proxy/app/server_others.go
View file @
62e58a66
...
@@ -237,7 +237,7 @@ func newProxyServer(
...
@@ -237,7 +237,7 @@ func newProxyServer(
},
nil
},
nil
}
}
func
getProxyMode
(
proxyMode
string
,
iptver
iptables
.
IPTables
Versioner
,
khandle
ipvs
.
KernelHandler
,
ipsetver
ipvs
.
IPSetVersioner
,
kcompat
iptables
.
KernelCompatTester
)
string
{
func
getProxyMode
(
proxyMode
string
,
iptver
iptables
.
Versioner
,
khandle
ipvs
.
KernelHandler
,
ipsetver
ipvs
.
IPSetVersioner
,
kcompat
iptables
.
KernelCompatTester
)
string
{
switch
proxyMode
{
switch
proxyMode
{
case
proxyModeUserspace
:
case
proxyModeUserspace
:
return
proxyModeUserspace
return
proxyModeUserspace
...
@@ -250,7 +250,7 @@ func getProxyMode(proxyMode string, iptver iptables.IPTablesVersioner, khandle i
...
@@ -250,7 +250,7 @@ func getProxyMode(proxyMode string, iptver iptables.IPTablesVersioner, khandle i
return
tryIPTablesProxy
(
iptver
,
kcompat
)
return
tryIPTablesProxy
(
iptver
,
kcompat
)
}
}
func
tryIPVSProxy
(
iptver
iptables
.
IPTables
Versioner
,
khandle
ipvs
.
KernelHandler
,
ipsetver
ipvs
.
IPSetVersioner
,
kcompat
iptables
.
KernelCompatTester
)
string
{
func
tryIPVSProxy
(
iptver
iptables
.
Versioner
,
khandle
ipvs
.
KernelHandler
,
ipsetver
ipvs
.
IPSetVersioner
,
kcompat
iptables
.
KernelCompatTester
)
string
{
// guaranteed false on error, error only necessary for debugging
// guaranteed false on error, error only necessary for debugging
// IPVS Proxier relies on ip_vs_* kernel modules and ipset
// IPVS Proxier relies on ip_vs_* kernel modules and ipset
useIPVSProxy
,
err
:=
ipvs
.
CanUseIPVSProxier
(
khandle
,
ipsetver
)
useIPVSProxy
,
err
:=
ipvs
.
CanUseIPVSProxier
(
khandle
,
ipsetver
)
...
@@ -267,7 +267,7 @@ func tryIPVSProxy(iptver iptables.IPTablesVersioner, khandle ipvs.KernelHandler,
...
@@ -267,7 +267,7 @@ func tryIPVSProxy(iptver iptables.IPTablesVersioner, khandle ipvs.KernelHandler,
return
tryIPTablesProxy
(
iptver
,
kcompat
)
return
tryIPTablesProxy
(
iptver
,
kcompat
)
}
}
func
tryIPTablesProxy
(
iptver
iptables
.
IPTables
Versioner
,
kcompat
iptables
.
KernelCompatTester
)
string
{
func
tryIPTablesProxy
(
iptver
iptables
.
Versioner
,
kcompat
iptables
.
KernelCompatTester
)
string
{
// guaranteed false on error, error only necessary for debugging
// guaranteed false on error, error only necessary for debugging
useIPTablesProxy
,
err
:=
iptables
.
CanUseIPTablesProxier
(
iptver
,
kcompat
)
useIPTablesProxy
,
err
:=
iptables
.
CanUseIPTablesProxier
(
iptver
,
kcompat
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
hack/.golint_failures
View file @
62e58a66
...
@@ -194,9 +194,7 @@ pkg/master/tunneler
...
@@ -194,9 +194,7 @@ pkg/master/tunneler
pkg/proxy
pkg/proxy
pkg/proxy/apis/config
pkg/proxy/apis/config
pkg/proxy/apis/config/v1alpha1
pkg/proxy/apis/config/v1alpha1
pkg/proxy/iptables
pkg/proxy/userspace
pkg/proxy/userspace
pkg/proxy/util
pkg/proxy/winkernel
pkg/proxy/winkernel
pkg/proxy/winuserspace
pkg/proxy/winuserspace
pkg/quota/v1/evaluator/core
pkg/quota/v1/evaluator/core
...
...
pkg/proxy/iptables/proxier.go
View file @
62e58a66
...
@@ -73,18 +73,18 @@ const (
...
@@ -73,18 +73,18 @@ const (
// the kubernetes postrouting chain
// the kubernetes postrouting chain
kubePostroutingChain
utiliptables
.
Chain
=
"KUBE-POSTROUTING"
kubePostroutingChain
utiliptables
.
Chain
=
"KUBE-POSTROUTING"
// the mark-for-masquerade chain
//
KubeMarkMasqChain is
the mark-for-masquerade chain
KubeMarkMasqChain
utiliptables
.
Chain
=
"KUBE-MARK-MASQ"
KubeMarkMasqChain
utiliptables
.
Chain
=
"KUBE-MARK-MASQ"
// the mark-for-drop chain
//
KubeMarkDropChain is
the mark-for-drop chain
KubeMarkDropChain
utiliptables
.
Chain
=
"KUBE-MARK-DROP"
KubeMarkDropChain
utiliptables
.
Chain
=
"KUBE-MARK-DROP"
// the kubernetes forward chain
// the kubernetes forward chain
kubeForwardChain
utiliptables
.
Chain
=
"KUBE-FORWARD"
kubeForwardChain
utiliptables
.
Chain
=
"KUBE-FORWARD"
)
)
//
IPTables
Versioner can query the current iptables version.
// Versioner can query the current iptables version.
type
IPTables
Versioner
interface
{
type
Versioner
interface
{
// returns "X.Y.Z"
// returns "X.Y.Z"
GetVersion
()
(
string
,
error
)
GetVersion
()
(
string
,
error
)
}
}
...
@@ -100,7 +100,7 @@ type KernelCompatTester interface {
...
@@ -100,7 +100,7 @@ type KernelCompatTester interface {
// the iptables version and for the existence of kernel features. It may return
// the iptables version and for the existence of kernel features. It may return
// an error if it fails to get the iptables version without error, in which
// an error if it fails to get the iptables version without error, in which
// case it will also return false.
// case it will also return false.
func
CanUseIPTablesProxier
(
iptver
IPTables
Versioner
,
kcompat
KernelCompatTester
)
(
bool
,
error
)
{
func
CanUseIPTablesProxier
(
iptver
Versioner
,
kcompat
KernelCompatTester
)
(
bool
,
error
)
{
minVersion
,
err
:=
utilversion
.
ParseGeneric
(
iptablesMinVersion
)
minVersion
,
err
:=
utilversion
.
ParseGeneric
(
iptablesMinVersion
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
...
@@ -124,12 +124,14 @@ func CanUseIPTablesProxier(iptver IPTablesVersioner, kcompat KernelCompatTester)
...
@@ -124,12 +124,14 @@ func CanUseIPTablesProxier(iptver IPTablesVersioner, kcompat KernelCompatTester)
return
true
,
nil
return
true
,
nil
}
}
// LinuxKernelCompatTester is the Linux implementation of KernelCompatTester
type
LinuxKernelCompatTester
struct
{}
type
LinuxKernelCompatTester
struct
{}
// IsCompatible checks for the required sysctls. We don't care about the value, just
// that it exists. If this Proxier is chosen, we'll initialize it as we
// need.
func
(
lkct
LinuxKernelCompatTester
)
IsCompatible
()
error
{
func
(
lkct
LinuxKernelCompatTester
)
IsCompatible
()
error
{
// Check for the required sysctls. We don't care about the value, just
// that it exists. If this Proxier is chosen, we'll initialize it as we
// need.
_
,
err
:=
utilsysctl
.
New
()
.
GetSysctl
(
sysctlRouteLocalnet
)
_
,
err
:=
utilsysctl
.
New
()
.
GetSysctl
(
sysctlRouteLocalnet
)
return
err
return
err
}
}
...
@@ -507,21 +509,29 @@ func (proxier *Proxier) isInitialized() bool {
...
@@ -507,21 +509,29 @@ func (proxier *Proxier) isInitialized() bool {
return
atomic
.
LoadInt32
(
&
proxier
.
initialized
)
>
0
return
atomic
.
LoadInt32
(
&
proxier
.
initialized
)
>
0
}
}
// OnServiceAdd is called whenever creation of new service object
// is observed.
func
(
proxier
*
Proxier
)
OnServiceAdd
(
service
*
v1
.
Service
)
{
func
(
proxier
*
Proxier
)
OnServiceAdd
(
service
*
v1
.
Service
)
{
proxier
.
OnServiceUpdate
(
nil
,
service
)
proxier
.
OnServiceUpdate
(
nil
,
service
)
}
}
// OnServiceUpdate is called whenever modification of an existing
// service object is observed.
func
(
proxier
*
Proxier
)
OnServiceUpdate
(
oldService
,
service
*
v1
.
Service
)
{
func
(
proxier
*
Proxier
)
OnServiceUpdate
(
oldService
,
service
*
v1
.
Service
)
{
if
proxier
.
serviceChanges
.
Update
(
oldService
,
service
)
&&
proxier
.
isInitialized
()
{
if
proxier
.
serviceChanges
.
Update
(
oldService
,
service
)
&&
proxier
.
isInitialized
()
{
proxier
.
syncRunner
.
Run
()
proxier
.
syncRunner
.
Run
()
}
}
}
}
// OnServiceDelete is called whenever deletion of an existing service
// object is observed.
func
(
proxier
*
Proxier
)
OnServiceDelete
(
service
*
v1
.
Service
)
{
func
(
proxier
*
Proxier
)
OnServiceDelete
(
service
*
v1
.
Service
)
{
proxier
.
OnServiceUpdate
(
service
,
nil
)
proxier
.
OnServiceUpdate
(
service
,
nil
)
}
}
// OnServiceSynced is called once all the initial even handlers were
// called and the state is fully propagated to local cache.
func
(
proxier
*
Proxier
)
OnServiceSynced
()
{
func
(
proxier
*
Proxier
)
OnServiceSynced
()
{
proxier
.
mu
.
Lock
()
proxier
.
mu
.
Lock
()
proxier
.
servicesSynced
=
true
proxier
.
servicesSynced
=
true
...
@@ -532,20 +542,28 @@ func (proxier *Proxier) OnServiceSynced() {
...
@@ -532,20 +542,28 @@ func (proxier *Proxier) OnServiceSynced() {
proxier
.
syncProxyRules
()
proxier
.
syncProxyRules
()
}
}
// OnEndpointsAdd is called whenever creation of new endpoints object
// is observed.
func
(
proxier
*
Proxier
)
OnEndpointsAdd
(
endpoints
*
v1
.
Endpoints
)
{
func
(
proxier
*
Proxier
)
OnEndpointsAdd
(
endpoints
*
v1
.
Endpoints
)
{
proxier
.
OnEndpointsUpdate
(
nil
,
endpoints
)
proxier
.
OnEndpointsUpdate
(
nil
,
endpoints
)
}
}
// OnEndpointsUpdate is called whenever modification of an existing
// endpoints object is observed.
func
(
proxier
*
Proxier
)
OnEndpointsUpdate
(
oldEndpoints
,
endpoints
*
v1
.
Endpoints
)
{
func
(
proxier
*
Proxier
)
OnEndpointsUpdate
(
oldEndpoints
,
endpoints
*
v1
.
Endpoints
)
{
if
proxier
.
endpointsChanges
.
Update
(
oldEndpoints
,
endpoints
)
&&
proxier
.
isInitialized
()
{
if
proxier
.
endpointsChanges
.
Update
(
oldEndpoints
,
endpoints
)
&&
proxier
.
isInitialized
()
{
proxier
.
syncRunner
.
Run
()
proxier
.
syncRunner
.
Run
()
}
}
}
}
// OnEndpointsDelete is called whever deletion of an existing endpoints
// object is observed.
func
(
proxier
*
Proxier
)
OnEndpointsDelete
(
endpoints
*
v1
.
Endpoints
)
{
func
(
proxier
*
Proxier
)
OnEndpointsDelete
(
endpoints
*
v1
.
Endpoints
)
{
proxier
.
OnEndpointsUpdate
(
endpoints
,
nil
)
proxier
.
OnEndpointsUpdate
(
endpoints
,
nil
)
}
}
// OnEndpointsSynced is called once all the initial event handlers were
// called and the state is fully propagated to local cache.
func
(
proxier
*
Proxier
)
OnEndpointsSynced
()
{
func
(
proxier
*
Proxier
)
OnEndpointsSynced
()
{
proxier
.
mu
.
Lock
()
proxier
.
mu
.
Lock
()
proxier
.
endpointsSynced
=
true
proxier
.
endpointsSynced
=
true
...
...
pkg/proxy/util/endpoints.go
View file @
62e58a66
...
@@ -39,12 +39,12 @@ func IPPart(s string) string {
...
@@ -39,12 +39,12 @@ func IPPart(s string) string {
return
""
return
""
}
}
// Check if host string is a valid IP address
// Check if host string is a valid IP address
if
ip
:=
net
.
ParseIP
(
host
);
ip
!=
nil
{
ip
:=
net
.
ParseIP
(
host
)
return
ip
.
String
()
if
ip
==
nil
{
}
else
{
klog
.
Errorf
(
"invalid IP part '%s'"
,
host
)
klog
.
Errorf
(
"invalid IP part '%s'"
,
host
)
return
""
}
}
return
""
return
ip
.
String
()
}
}
// PortPart returns just the port part of an endpoint string.
// PortPart returns just the port part of an endpoint string.
...
...
pkg/proxy/util/utils.go
View file @
62e58a66
...
@@ -33,15 +33,23 @@ import (
...
@@ -33,15 +33,23 @@ import (
)
)
const
(
const
(
// IPv4ZeroCIDR is the CIDR block for the whole IPv4 address space
IPv4ZeroCIDR
=
"0.0.0.0/0"
IPv4ZeroCIDR
=
"0.0.0.0/0"
// IPv6ZeroCIDR is the CIDR block for the whole IPv6 address space
IPv6ZeroCIDR
=
"::/0"
IPv6ZeroCIDR
=
"::/0"
)
)
var
(
var
(
// ErrAddressNotAllowed indicates the address is not allowed
ErrAddressNotAllowed
=
errors
.
New
(
"address not allowed"
)
ErrAddressNotAllowed
=
errors
.
New
(
"address not allowed"
)
ErrNoAddresses
=
errors
.
New
(
"No addresses for hostname"
)
// ErrNoAddresses indicates there are no addresses for the hostname
ErrNoAddresses
=
errors
.
New
(
"No addresses for hostname"
)
)
)
// IsZeroCIDR checks whether the input CIDR string is either
// the IPv4 or IPv6 zero CIDR
func
IsZeroCIDR
(
cidr
string
)
bool
{
func
IsZeroCIDR
(
cidr
string
)
bool
{
if
cidr
==
IPv4ZeroCIDR
||
cidr
==
IPv6ZeroCIDR
{
if
cidr
==
IPv4ZeroCIDR
||
cidr
==
IPv6ZeroCIDR
{
return
true
return
true
...
@@ -89,6 +97,8 @@ func IsProxyableHostname(ctx context.Context, resolv Resolver, hostname string)
...
@@ -89,6 +97,8 @@ func IsProxyableHostname(ctx context.Context, resolv Resolver, hostname string)
return
nil
return
nil
}
}
// IsLocalIP checks if a given IP address is bound to an interface
// on the local system
func
IsLocalIP
(
ip
string
)
(
bool
,
error
)
{
func
IsLocalIP
(
ip
string
)
(
bool
,
error
)
{
addrs
,
err
:=
net
.
InterfaceAddrs
()
addrs
,
err
:=
net
.
InterfaceAddrs
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -106,6 +116,7 @@ func IsLocalIP(ip string) (bool, error) {
...
@@ -106,6 +116,7 @@ func IsLocalIP(ip string) (bool, error) {
return
false
,
nil
return
false
,
nil
}
}
// ShouldSkipService checks if a given service should skip proxying
func
ShouldSkipService
(
svcName
types
.
NamespacedName
,
service
*
v1
.
Service
)
bool
{
func
ShouldSkipService
(
svcName
types
.
NamespacedName
,
service
*
v1
.
Service
)
bool
{
// if ClusterIP is "None" or empty, skip proxying
// if ClusterIP is "None" or empty, skip proxying
if
!
helper
.
IsServiceIPSet
(
service
)
{
if
!
helper
.
IsServiceIPSet
(
service
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment