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
fbf8a133
Commit
fbf8a133
authored
Nov 15, 2017
by
m1093782566
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use ipset doing snat and packet filter in ipvs proxy
parent
c124fcf7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
101 additions
and
45 deletions
+101
-45
BUILD
cmd/kube-proxy/app/BUILD
+1
-0
server.go
cmd/kube-proxy/app/server.go
+3
-1
server_others.go
cmd/kube-proxy/app/server_others.go
+14
-10
BUILD
pkg/proxy/ipvs/BUILD
+6
-0
proxier.go
pkg/proxy/ipvs/proxier.go
+0
-0
proxier_test.go
pkg/proxy/ipvs/proxier_test.go
+61
-34
endpoints.go
pkg/proxy/util/endpoints.go
+16
-0
No files found.
cmd/kube-proxy/app/BUILD
View file @
fbf8a133
...
@@ -41,6 +41,7 @@ go_library(
...
@@ -41,6 +41,7 @@ go_library(
"//pkg/proxy/userspace:go_default_library",
"//pkg/proxy/userspace:go_default_library",
"//pkg/util/configz:go_default_library",
"//pkg/util/configz:go_default_library",
"//pkg/util/dbus:go_default_library",
"//pkg/util/dbus:go_default_library",
"//pkg/util/ipset:go_default_library",
"//pkg/util/iptables:go_default_library",
"//pkg/util/iptables:go_default_library",
"//pkg/util/ipvs:go_default_library",
"//pkg/util/ipvs:go_default_library",
"//pkg/util/mount:go_default_library",
"//pkg/util/mount:go_default_library",
...
...
cmd/kube-proxy/app/server.go
View file @
fbf8a133
...
@@ -63,6 +63,7 @@ import (
...
@@ -63,6 +63,7 @@ import (
"k8s.io/kubernetes/pkg/proxy/ipvs"
"k8s.io/kubernetes/pkg/proxy/ipvs"
"k8s.io/kubernetes/pkg/proxy/userspace"
"k8s.io/kubernetes/pkg/proxy/userspace"
"k8s.io/kubernetes/pkg/util/configz"
"k8s.io/kubernetes/pkg/util/configz"
utilipset
"k8s.io/kubernetes/pkg/util/ipset"
utiliptables
"k8s.io/kubernetes/pkg/util/iptables"
utiliptables
"k8s.io/kubernetes/pkg/util/iptables"
utilipvs
"k8s.io/kubernetes/pkg/util/ipvs"
utilipvs
"k8s.io/kubernetes/pkg/util/ipvs"
utilnode
"k8s.io/kubernetes/pkg/util/node"
utilnode
"k8s.io/kubernetes/pkg/util/node"
...
@@ -356,6 +357,7 @@ type ProxyServer struct {
...
@@ -356,6 +357,7 @@ type ProxyServer struct {
EventClient
v1core
.
EventsGetter
EventClient
v1core
.
EventsGetter
IptInterface
utiliptables
.
Interface
IptInterface
utiliptables
.
Interface
IpvsInterface
utilipvs
.
Interface
IpvsInterface
utilipvs
.
Interface
IpsetInterface
utilipset
.
Interface
execer
exec
.
Interface
execer
exec
.
Interface
Proxier
proxy
.
ProxyProvider
Proxier
proxy
.
ProxyProvider
Broadcaster
record
.
EventBroadcaster
Broadcaster
record
.
EventBroadcaster
...
@@ -422,7 +424,7 @@ func (s *ProxyServer) Run() error {
...
@@ -422,7 +424,7 @@ func (s *ProxyServer) Run() error {
if
s
.
CleanupAndExit
{
if
s
.
CleanupAndExit
{
encounteredError
:=
userspace
.
CleanupLeftovers
(
s
.
IptInterface
)
encounteredError
:=
userspace
.
CleanupLeftovers
(
s
.
IptInterface
)
encounteredError
=
iptables
.
CleanupLeftovers
(
s
.
IptInterface
)
||
encounteredError
encounteredError
=
iptables
.
CleanupLeftovers
(
s
.
IptInterface
)
||
encounteredError
encounteredError
=
ipvs
.
CleanupLeftovers
(
s
.
IpvsInterface
,
s
.
IptInterface
)
||
encounteredError
encounteredError
=
ipvs
.
CleanupLeftovers
(
s
.
IpvsInterface
,
s
.
IptInterface
,
s
.
IpsetInterface
)
||
encounteredError
if
encounteredError
{
if
encounteredError
{
return
errors
.
New
(
"encountered an error while tearing down rules."
)
return
errors
.
New
(
"encountered an error while tearing down rules."
)
}
}
...
...
cmd/kube-proxy/app/server_others.go
View file @
fbf8a133
...
@@ -43,6 +43,7 @@ import (
...
@@ -43,6 +43,7 @@ import (
"k8s.io/kubernetes/pkg/proxy/userspace"
"k8s.io/kubernetes/pkg/proxy/userspace"
"k8s.io/kubernetes/pkg/util/configz"
"k8s.io/kubernetes/pkg/util/configz"
utildbus
"k8s.io/kubernetes/pkg/util/dbus"
utildbus
"k8s.io/kubernetes/pkg/util/dbus"
utilipset
"k8s.io/kubernetes/pkg/util/ipset"
utiliptables
"k8s.io/kubernetes/pkg/util/iptables"
utiliptables
"k8s.io/kubernetes/pkg/util/iptables"
utilipvs
"k8s.io/kubernetes/pkg/util/ipvs"
utilipvs
"k8s.io/kubernetes/pkg/util/ipvs"
utilnode
"k8s.io/kubernetes/pkg/util/node"
utilnode
"k8s.io/kubernetes/pkg/util/node"
...
@@ -72,6 +73,7 @@ func NewProxyServer(config *proxyconfigapi.KubeProxyConfiguration, cleanupAndExi
...
@@ -72,6 +73,7 @@ func NewProxyServer(config *proxyconfigapi.KubeProxyConfiguration, cleanupAndExi
var
iptInterface
utiliptables
.
Interface
var
iptInterface
utiliptables
.
Interface
var
ipvsInterface
utilipvs
.
Interface
var
ipvsInterface
utilipvs
.
Interface
var
ipsetInterface
utilipset
.
Interface
var
dbus
utildbus
.
Interface
var
dbus
utildbus
.
Interface
// Create a iptables utils.
// Create a iptables utils.
...
@@ -80,6 +82,7 @@ func NewProxyServer(config *proxyconfigapi.KubeProxyConfiguration, cleanupAndExi
...
@@ -80,6 +82,7 @@ func NewProxyServer(config *proxyconfigapi.KubeProxyConfiguration, cleanupAndExi
dbus
=
utildbus
.
New
()
dbus
=
utildbus
.
New
()
iptInterface
=
utiliptables
.
New
(
execer
,
dbus
,
protocol
)
iptInterface
=
utiliptables
.
New
(
execer
,
dbus
,
protocol
)
ipvsInterface
=
utilipvs
.
New
(
execer
)
ipvsInterface
=
utilipvs
.
New
(
execer
)
ipsetInterface
=
utilipset
.
New
(
execer
)
// We omit creation of pretty much everything if we run in cleanup mode
// We omit creation of pretty much everything if we run in cleanup mode
if
cleanupAndExit
{
if
cleanupAndExit
{
...
@@ -87,6 +90,7 @@ func NewProxyServer(config *proxyconfigapi.KubeProxyConfiguration, cleanupAndExi
...
@@ -87,6 +90,7 @@ func NewProxyServer(config *proxyconfigapi.KubeProxyConfiguration, cleanupAndExi
execer
:
execer
,
execer
:
execer
,
IptInterface
:
iptInterface
,
IptInterface
:
iptInterface
,
IpvsInterface
:
ipvsInterface
,
IpvsInterface
:
ipvsInterface
,
IpsetInterface
:
ipsetInterface
,
CleanupAndExit
:
cleanupAndExit
,
CleanupAndExit
:
cleanupAndExit
,
},
nil
},
nil
}
}
...
@@ -119,7 +123,7 @@ func NewProxyServer(config *proxyconfigapi.KubeProxyConfiguration, cleanupAndExi
...
@@ -119,7 +123,7 @@ func NewProxyServer(config *proxyconfigapi.KubeProxyConfiguration, cleanupAndExi
var
serviceEventHandler
proxyconfig
.
ServiceHandler
var
serviceEventHandler
proxyconfig
.
ServiceHandler
var
endpointsEventHandler
proxyconfig
.
EndpointsHandler
var
endpointsEventHandler
proxyconfig
.
EndpointsHandler
proxyMode
:=
getProxyMode
(
string
(
config
.
Mode
),
iptInterface
,
iptables
.
LinuxKernelCompatTester
{})
proxyMode
:=
getProxyMode
(
string
(
config
.
Mode
),
iptInterface
,
ip
setInterface
,
ip
tables
.
LinuxKernelCompatTester
{})
if
proxyMode
==
proxyModeIPTables
{
if
proxyMode
==
proxyModeIPTables
{
glog
.
V
(
0
)
.
Info
(
"Using iptables Proxier."
)
glog
.
V
(
0
)
.
Info
(
"Using iptables Proxier."
)
nodeIP
:=
net
.
ParseIP
(
config
.
BindAddress
)
nodeIP
:=
net
.
ParseIP
(
config
.
BindAddress
)
...
@@ -159,12 +163,13 @@ func NewProxyServer(config *proxyconfigapi.KubeProxyConfiguration, cleanupAndExi
...
@@ -159,12 +163,13 @@ func NewProxyServer(config *proxyconfigapi.KubeProxyConfiguration, cleanupAndExi
userspace
.
CleanupLeftovers
(
iptInterface
)
userspace
.
CleanupLeftovers
(
iptInterface
)
// IPVS Proxier will generate some iptables rules,
// IPVS Proxier will generate some iptables rules,
// need to clean them before switching to other proxy mode.
// need to clean them before switching to other proxy mode.
ipvs
.
CleanupLeftovers
(
ipvsInterface
,
iptInterface
)
ipvs
.
CleanupLeftovers
(
ipvsInterface
,
iptInterface
,
ipsetInterface
)
}
else
if
proxyMode
==
proxyModeIPVS
{
}
else
if
proxyMode
==
proxyModeIPVS
{
glog
.
V
(
0
)
.
Info
(
"Using ipvs Proxier."
)
glog
.
V
(
0
)
.
Info
(
"Using ipvs Proxier."
)
proxierIPVS
,
err
:=
ipvs
.
NewProxier
(
proxierIPVS
,
err
:=
ipvs
.
NewProxier
(
iptInterface
,
iptInterface
,
ipvsInterface
,
ipvsInterface
,
ipsetInterface
,
utilsysctl
.
New
(),
utilsysctl
.
New
(),
execer
,
execer
,
config
.
IPVS
.
SyncPeriod
.
Duration
,
config
.
IPVS
.
SyncPeriod
.
Duration
,
...
@@ -220,7 +225,7 @@ func NewProxyServer(config *proxyconfigapi.KubeProxyConfiguration, cleanupAndExi
...
@@ -220,7 +225,7 @@ func NewProxyServer(config *proxyconfigapi.KubeProxyConfiguration, cleanupAndExi
iptables
.
CleanupLeftovers
(
iptInterface
)
iptables
.
CleanupLeftovers
(
iptInterface
)
// IPVS Proxier will generate some iptables rules,
// IPVS Proxier will generate some iptables rules,
// need to clean them before switching to other proxy mode.
// need to clean them before switching to other proxy mode.
ipvs
.
CleanupLeftovers
(
ipvsInterface
,
iptInterface
)
ipvs
.
CleanupLeftovers
(
ipvsInterface
,
iptInterface
,
ipsetInterface
)
}
}
iptInterface
.
AddReloadFunc
(
proxier
.
Sync
)
iptInterface
.
AddReloadFunc
(
proxier
.
Sync
)
...
@@ -230,6 +235,7 @@ func NewProxyServer(config *proxyconfigapi.KubeProxyConfiguration, cleanupAndExi
...
@@ -230,6 +235,7 @@ func NewProxyServer(config *proxyconfigapi.KubeProxyConfiguration, cleanupAndExi
EventClient
:
eventClient
,
EventClient
:
eventClient
,
IptInterface
:
iptInterface
,
IptInterface
:
iptInterface
,
IpvsInterface
:
ipvsInterface
,
IpvsInterface
:
ipvsInterface
,
IpsetInterface
:
ipsetInterface
,
execer
:
execer
,
execer
:
execer
,
Proxier
:
proxier
,
Proxier
:
proxier
,
Broadcaster
:
eventBroadcaster
,
Broadcaster
:
eventBroadcaster
,
...
@@ -249,7 +255,7 @@ func NewProxyServer(config *proxyconfigapi.KubeProxyConfiguration, cleanupAndExi
...
@@ -249,7 +255,7 @@ func NewProxyServer(config *proxyconfigapi.KubeProxyConfiguration, cleanupAndExi
},
nil
},
nil
}
}
func
getProxyMode
(
proxyMode
string
,
iptver
iptables
.
IPTablesVersioner
,
kcompat
iptables
.
KernelCompatTester
)
string
{
func
getProxyMode
(
proxyMode
string
,
iptver
iptables
.
IPTablesVersioner
,
ipsetver
ipvs
.
IPSetVersioner
,
kcompat
iptables
.
KernelCompatTester
)
string
{
if
proxyMode
==
proxyModeUserspace
{
if
proxyMode
==
proxyModeUserspace
{
return
proxyModeUserspace
return
proxyModeUserspace
}
}
...
@@ -260,7 +266,7 @@ func getProxyMode(proxyMode string, iptver iptables.IPTablesVersioner, kcompat i
...
@@ -260,7 +266,7 @@ func getProxyMode(proxyMode string, iptver iptables.IPTablesVersioner, kcompat i
if
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
SupportIPVSProxyMode
)
{
if
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
SupportIPVSProxyMode
)
{
if
proxyMode
==
proxyModeIPVS
{
if
proxyMode
==
proxyModeIPVS
{
return
tryIPVSProxy
(
iptver
,
kcompat
)
return
tryIPVSProxy
(
iptver
,
ipsetver
,
kcompat
)
}
else
{
}
else
{
glog
.
Warningf
(
"Can't use ipvs proxier, trying iptables proxier"
)
glog
.
Warningf
(
"Can't use ipvs proxier, trying iptables proxier"
)
return
tryIPTablesProxy
(
iptver
,
kcompat
)
return
tryIPTablesProxy
(
iptver
,
kcompat
)
...
@@ -270,10 +276,10 @@ func getProxyMode(proxyMode string, iptver iptables.IPTablesVersioner, kcompat i
...
@@ -270,10 +276,10 @@ func getProxyMode(proxyMode string, iptver iptables.IPTablesVersioner, kcompat i
return
tryIPTablesProxy
(
iptver
,
kcompat
)
return
tryIPTablesProxy
(
iptver
,
kcompat
)
}
}
func
tryIPVSProxy
(
iptver
iptables
.
IPTablesVersioner
,
kcompat
iptables
.
KernelCompatTester
)
string
{
func
tryIPVSProxy
(
iptver
iptables
.
IPTablesVersioner
,
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
tables
// IPVS Proxier relies on ip
set
useIPVSProxy
,
err
:=
ipvs
.
CanUseIPVSProxier
()
useIPVSProxy
,
err
:=
ipvs
.
CanUseIPVSProxier
(
ipsetver
)
if
err
!=
nil
{
if
err
!=
nil
{
// Try to fallback to iptables before falling back to userspace
// Try to fallback to iptables before falling back to userspace
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"can't determine whether to use ipvs proxy, error: %v"
,
err
))
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"can't determine whether to use ipvs proxy, error: %v"
,
err
))
...
@@ -282,8 +288,6 @@ func tryIPVSProxy(iptver iptables.IPTablesVersioner, kcompat iptables.KernelComp
...
@@ -282,8 +288,6 @@ func tryIPVSProxy(iptver iptables.IPTablesVersioner, kcompat iptables.KernelComp
return
proxyModeIPVS
return
proxyModeIPVS
}
}
// TODO: Check ipvs version
// Try to fallback to iptables before falling back to userspace
// Try to fallback to iptables before falling back to userspace
glog
.
V
(
1
)
.
Infof
(
"Can't use ipvs proxier, trying iptables proxier"
)
glog
.
V
(
1
)
.
Infof
(
"Can't use ipvs proxier, trying iptables proxier"
)
return
tryIPTablesProxy
(
iptver
,
kcompat
)
return
tryIPTablesProxy
(
iptver
,
kcompat
)
...
...
pkg/proxy/ipvs/BUILD
View file @
fbf8a133
...
@@ -9,6 +9,7 @@ load(
...
@@ -9,6 +9,7 @@ load(
go_test(
go_test(
name = "go_default_test",
name = "go_default_test",
srcs = [
srcs = [
"ipset_test.go",
"proxier_test.go",
"proxier_test.go",
],
],
importpath = "k8s.io/kubernetes/pkg/proxy/ipvs",
importpath = "k8s.io/kubernetes/pkg/proxy/ipvs",
...
@@ -18,6 +19,8 @@ go_test(
...
@@ -18,6 +19,8 @@ go_test(
"//pkg/proxy:go_default_library",
"//pkg/proxy:go_default_library",
"//pkg/proxy/ipvs/testing:go_default_library",
"//pkg/proxy/ipvs/testing:go_default_library",
"//pkg/proxy/util:go_default_library",
"//pkg/proxy/util:go_default_library",
"//pkg/util/ipset:go_default_library",
"//pkg/util/ipset/testing:go_default_library",
"//pkg/util/iptables:go_default_library",
"//pkg/util/iptables:go_default_library",
"//pkg/util/iptables/testing:go_default_library",
"//pkg/util/iptables/testing:go_default_library",
"//pkg/util/ipvs:go_default_library",
"//pkg/util/ipvs:go_default_library",
...
@@ -35,6 +38,7 @@ go_test(
...
@@ -35,6 +38,7 @@ go_test(
go_library(
go_library(
name = "go_default_library",
name = "go_default_library",
srcs = [
srcs = [
"ipset.go",
"netlink.go",
"netlink.go",
"netlink_unsupported.go",
"netlink_unsupported.go",
"proxier.go",
"proxier.go",
...
@@ -55,9 +59,11 @@ go_library(
...
@@ -55,9 +59,11 @@ go_library(
"//pkg/proxy/metrics:go_default_library",
"//pkg/proxy/metrics:go_default_library",
"//pkg/proxy/util:go_default_library",
"//pkg/proxy/util:go_default_library",
"//pkg/util/async:go_default_library",
"//pkg/util/async:go_default_library",
"//pkg/util/ipset:go_default_library",
"//pkg/util/iptables:go_default_library",
"//pkg/util/iptables:go_default_library",
"//pkg/util/ipvs:go_default_library",
"//pkg/util/ipvs:go_default_library",
"//pkg/util/sysctl:go_default_library",
"//pkg/util/sysctl:go_default_library",
"//pkg/util/version:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
...
...
pkg/proxy/ipvs/proxier.go
View file @
fbf8a133
This diff is collapsed.
Click to expand it.
pkg/proxy/ipvs/proxier_test.go
View file @
fbf8a133
...
@@ -33,6 +33,8 @@ import (
...
@@ -33,6 +33,8 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/sets"
netlinktest
"k8s.io/kubernetes/pkg/proxy/ipvs/testing"
netlinktest
"k8s.io/kubernetes/pkg/proxy/ipvs/testing"
proxyutil
"k8s.io/kubernetes/pkg/proxy/util"
proxyutil
"k8s.io/kubernetes/pkg/proxy/util"
utilipset
"k8s.io/kubernetes/pkg/util/ipset"
ipsettest
"k8s.io/kubernetes/pkg/util/ipset/testing"
utiliptables
"k8s.io/kubernetes/pkg/util/iptables"
utiliptables
"k8s.io/kubernetes/pkg/util/iptables"
iptablestest
"k8s.io/kubernetes/pkg/util/iptables/testing"
iptablestest
"k8s.io/kubernetes/pkg/util/iptables/testing"
utilipvs
"k8s.io/kubernetes/pkg/util/ipvs"
utilipvs
"k8s.io/kubernetes/pkg/util/ipvs"
...
@@ -85,7 +87,7 @@ func (fake *fakeHealthChecker) SyncEndpoints(newEndpoints map[types.NamespacedNa
...
@@ -85,7 +87,7 @@ func (fake *fakeHealthChecker) SyncEndpoints(newEndpoints map[types.NamespacedNa
return
nil
return
nil
}
}
func
NewFakeProxier
(
ipt
utiliptables
.
Interface
,
ipvs
utilipvs
.
Interface
,
nodeIPs
[]
net
.
IP
)
*
Proxier
{
func
NewFakeProxier
(
ipt
utiliptables
.
Interface
,
ipvs
utilipvs
.
Interface
,
ipset
utilipset
.
Interface
,
nodeIPs
[]
net
.
IP
)
*
Proxier
{
fcmd
:=
fakeexec
.
FakeCmd
{
fcmd
:=
fakeexec
.
FakeCmd
{
CombinedOutputScript
:
[]
fakeexec
.
FakeCombinedOutputAction
{
CombinedOutputScript
:
[]
fakeexec
.
FakeCombinedOutputAction
{
func
()
([]
byte
,
error
)
{
return
[]
byte
(
"dummy device have been created"
),
nil
},
func
()
([]
byte
,
error
)
{
return
[]
byte
(
"dummy device have been created"
),
nil
},
...
@@ -98,24 +100,34 @@ func NewFakeProxier(ipt utiliptables.Interface, ipvs utilipvs.Interface, nodeIPs
...
@@ -98,24 +100,34 @@ func NewFakeProxier(ipt utiliptables.Interface, ipvs utilipvs.Interface, nodeIPs
LookPathFunc
:
func
(
cmd
string
)
(
string
,
error
)
{
return
cmd
,
nil
},
LookPathFunc
:
func
(
cmd
string
)
(
string
,
error
)
{
return
cmd
,
nil
},
}
}
return
&
Proxier
{
return
&
Proxier
{
exec
:
fexec
,
exec
:
fexec
,
serviceMap
:
make
(
proxyServiceMap
),
serviceMap
:
make
(
proxyServiceMap
),
serviceChanges
:
newServiceChangeMap
(),
serviceChanges
:
newServiceChangeMap
(),
endpointsMap
:
make
(
proxyEndpointsMap
),
endpointsMap
:
make
(
proxyEndpointsMap
),
endpointsChanges
:
newEndpointsChangeMap
(
testHostname
),
endpointsChanges
:
newEndpointsChangeMap
(
testHostname
),
iptables
:
ipt
,
iptables
:
ipt
,
ipvs
:
ipvs
,
ipvs
:
ipvs
,
clusterCIDR
:
"10.0.0.0/24"
,
ipset
:
ipset
,
hostname
:
testHostname
,
clusterCIDR
:
"10.0.0.0/24"
,
portsMap
:
make
(
map
[
proxyutil
.
LocalPort
]
proxyutil
.
Closeable
),
hostname
:
testHostname
,
portMapper
:
&
fakePortOpener
{[]
*
proxyutil
.
LocalPort
{}},
portsMap
:
make
(
map
[
proxyutil
.
LocalPort
]
proxyutil
.
Closeable
),
healthChecker
:
newFakeHealthChecker
(),
portMapper
:
&
fakePortOpener
{[]
*
proxyutil
.
LocalPort
{}},
ipvsScheduler
:
DefaultScheduler
,
healthChecker
:
newFakeHealthChecker
(),
ipGetter
:
&
fakeIPGetter
{
nodeIPs
:
nodeIPs
},
ipvsScheduler
:
DefaultScheduler
,
iptablesData
:
bytes
.
NewBuffer
(
nil
),
ipGetter
:
&
fakeIPGetter
{
nodeIPs
:
nodeIPs
},
natChains
:
bytes
.
NewBuffer
(
nil
),
iptablesData
:
bytes
.
NewBuffer
(
nil
),
natRules
:
bytes
.
NewBuffer
(
nil
),
natChains
:
bytes
.
NewBuffer
(
nil
),
netlinkHandle
:
netlinktest
.
NewFakeNetlinkHandle
(),
natRules
:
bytes
.
NewBuffer
(
nil
),
netlinkHandle
:
netlinktest
.
NewFakeNetlinkHandle
(),
loopbackSet
:
NewIPSet
(
ipset
,
KubeLoopBackIPSet
,
utilipset
.
HashIPPortIP
,
false
),
clusterIPSet
:
NewIPSet
(
ipset
,
KubeClusterIPSet
,
utilipset
.
HashIPPort
,
false
),
externalIPSet
:
NewIPSet
(
ipset
,
KubeExternalIPSet
,
utilipset
.
HashIPPort
,
false
),
lbIngressSet
:
NewIPSet
(
ipset
,
KubeLoadBalancerSet
,
utilipset
.
HashIPPort
,
false
),
lbMasqSet
:
NewIPSet
(
ipset
,
KubeLoadBalancerMasqSet
,
utilipset
.
HashIPPort
,
false
),
lbWhiteListIPSet
:
NewIPSet
(
ipset
,
KubeLoadBalancerSourceIPSet
,
utilipset
.
HashIPPortIP
,
false
),
lbWhiteListCIDRSet
:
NewIPSet
(
ipset
,
KubeLoadBalancerSourceCIDRSet
,
utilipset
.
HashIPPortNet
,
false
),
nodePortSetTCP
:
NewIPSet
(
ipset
,
KubeNodePortSetTCP
,
utilipset
.
BitmapPort
,
false
),
nodePortSetUDP
:
NewIPSet
(
ipset
,
KubeNodePortSetUDP
,
utilipset
.
BitmapPort
,
false
),
}
}
}
}
...
@@ -171,10 +183,11 @@ func makeTestEndpoints(namespace, name string, eptFunc func(*api.Endpoints)) *ap
...
@@ -171,10 +183,11 @@ func makeTestEndpoints(namespace, name string, eptFunc func(*api.Endpoints)) *ap
func
TestNodePort
(
t
*
testing
.
T
)
{
func
TestNodePort
(
t
*
testing
.
T
)
{
ipt
:=
iptablestest
.
NewFake
()
ipt
:=
iptablestest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
ipset
:=
ipsettest
.
NewFake
()
nodeIPv4
:=
net
.
ParseIP
(
"100.101.102.103"
)
nodeIPv4
:=
net
.
ParseIP
(
"100.101.102.103"
)
nodeIPv6
:=
net
.
ParseIP
(
"2001:db8::1:1"
)
nodeIPv6
:=
net
.
ParseIP
(
"2001:db8::1:1"
)
nodeIPs
:=
sets
.
NewString
(
nodeIPv4
.
String
(),
nodeIPv6
.
String
())
nodeIPs
:=
sets
.
NewString
(
nodeIPv4
.
String
(),
nodeIPv6
.
String
())
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
[]
net
.
IP
{
nodeIPv4
,
nodeIPv6
})
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
ipset
,
[]
net
.
IP
{
nodeIPv4
,
nodeIPv6
})
svcIP
:=
"10.20.30.41"
svcIP
:=
"10.20.30.41"
svcPort
:=
80
svcPort
:=
80
svcNodePort
:=
3001
svcNodePort
:=
3001
...
@@ -248,8 +261,9 @@ func TestNodePort(t *testing.T) {
...
@@ -248,8 +261,9 @@ func TestNodePort(t *testing.T) {
func
TestNodePortNoEndpoint
(
t
*
testing
.
T
)
{
func
TestNodePortNoEndpoint
(
t
*
testing
.
T
)
{
ipt
:=
iptablestest
.
NewFake
()
ipt
:=
iptablestest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
ipset
:=
ipsettest
.
NewFake
()
nodeIP
:=
net
.
ParseIP
(
"100.101.102.103"
)
nodeIP
:=
net
.
ParseIP
(
"100.101.102.103"
)
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
[]
net
.
IP
{
nodeIP
})
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
ipset
,
[]
net
.
IP
{
nodeIP
})
svcIP
:=
"10.20.30.41"
svcIP
:=
"10.20.30.41"
svcPort
:=
80
svcPort
:=
80
svcNodePort
:=
3001
svcNodePort
:=
3001
...
@@ -301,7 +315,8 @@ func TestNodePortNoEndpoint(t *testing.T) {
...
@@ -301,7 +315,8 @@ func TestNodePortNoEndpoint(t *testing.T) {
func
TestClusterIPNoEndpoint
(
t
*
testing
.
T
)
{
func
TestClusterIPNoEndpoint
(
t
*
testing
.
T
)
{
ipt
:=
iptablestest
.
NewFake
()
ipt
:=
iptablestest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
nil
)
ipset
:=
ipsettest
.
NewFake
()
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
ipset
,
nil
)
svcIP
:=
"10.20.30.41"
svcIP
:=
"10.20.30.41"
svcPort
:=
80
svcPort
:=
80
svcPortName
:=
proxy
.
ServicePortName
{
svcPortName
:=
proxy
.
ServicePortName
{
...
@@ -344,7 +359,8 @@ func TestClusterIPNoEndpoint(t *testing.T) {
...
@@ -344,7 +359,8 @@ func TestClusterIPNoEndpoint(t *testing.T) {
func
TestClusterIP
(
t
*
testing
.
T
)
{
func
TestClusterIP
(
t
*
testing
.
T
)
{
ipt
:=
iptablestest
.
NewFake
()
ipt
:=
iptablestest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
nil
)
ipset
:=
ipsettest
.
NewFake
()
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
ipset
,
nil
)
svcIPv4
:=
"10.20.30.41"
svcIPv4
:=
"10.20.30.41"
svcPortV4
:=
80
svcPortV4
:=
80
...
@@ -450,7 +466,8 @@ func TestClusterIP(t *testing.T) {
...
@@ -450,7 +466,8 @@ func TestClusterIP(t *testing.T) {
func
TestExternalIPsNoEndpoint
(
t
*
testing
.
T
)
{
func
TestExternalIPsNoEndpoint
(
t
*
testing
.
T
)
{
ipt
:=
iptablestest
.
NewFake
()
ipt
:=
iptablestest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
nil
)
ipset
:=
ipsettest
.
NewFake
()
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
ipset
,
nil
)
svcIP
:=
"10.20.30.41"
svcIP
:=
"10.20.30.41"
svcPort
:=
80
svcPort
:=
80
svcExternalIPs
:=
"50.60.70.81"
svcExternalIPs
:=
"50.60.70.81"
...
@@ -504,7 +521,8 @@ func TestExternalIPsNoEndpoint(t *testing.T) {
...
@@ -504,7 +521,8 @@ func TestExternalIPsNoEndpoint(t *testing.T) {
func
TestExternalIPs
(
t
*
testing
.
T
)
{
func
TestExternalIPs
(
t
*
testing
.
T
)
{
ipt
:=
iptablestest
.
NewFake
()
ipt
:=
iptablestest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
nil
)
ipset
:=
ipsettest
.
NewFake
()
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
ipset
,
nil
)
svcIP
:=
"10.20.30.41"
svcIP
:=
"10.20.30.41"
svcPort
:=
80
svcPort
:=
80
svcExternalIPs
:=
sets
.
NewString
(
"50.60.70.81"
,
"2012::51"
)
svcExternalIPs
:=
sets
.
NewString
(
"50.60.70.81"
,
"2012::51"
)
...
@@ -573,7 +591,8 @@ func TestExternalIPs(t *testing.T) {
...
@@ -573,7 +591,8 @@ func TestExternalIPs(t *testing.T) {
func
TestLoadBalancer
(
t
*
testing
.
T
)
{
func
TestLoadBalancer
(
t
*
testing
.
T
)
{
ipt
:=
iptablestest
.
NewFake
()
ipt
:=
iptablestest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
nil
)
ipset
:=
ipsettest
.
NewFake
()
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
ipset
,
nil
)
svcIP
:=
"10.20.30.41"
svcIP
:=
"10.20.30.41"
svcPort
:=
80
svcPort
:=
80
svcNodePort
:=
3001
svcNodePort
:=
3001
...
@@ -624,8 +643,9 @@ func strPtr(s string) *string {
...
@@ -624,8 +643,9 @@ func strPtr(s string) *string {
func
TestOnlyLocalNodePorts
(
t
*
testing
.
T
)
{
func
TestOnlyLocalNodePorts
(
t
*
testing
.
T
)
{
ipt
:=
iptablestest
.
NewFake
()
ipt
:=
iptablestest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
ipset
:=
ipsettest
.
NewFake
()
nodeIP
:=
net
.
ParseIP
(
"100.101.102.103"
)
nodeIP
:=
net
.
ParseIP
(
"100.101.102.103"
)
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
[]
net
.
IP
{
nodeIP
})
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
ipset
,
[]
net
.
IP
{
nodeIP
})
svcIP
:=
"10.20.30.41"
svcIP
:=
"10.20.30.41"
svcPort
:=
80
svcPort
:=
80
svcNodePort
:=
3001
svcNodePort
:=
3001
...
@@ -705,7 +725,8 @@ func TestOnlyLocalNodePorts(t *testing.T) {
...
@@ -705,7 +725,8 @@ func TestOnlyLocalNodePorts(t *testing.T) {
func
TestOnlyLocalLoadBalancing
(
t
*
testing
.
T
)
{
func
TestOnlyLocalLoadBalancing
(
t
*
testing
.
T
)
{
ipt
:=
iptablestest
.
NewFake
()
ipt
:=
iptablestest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
nil
)
ipset
:=
ipsettest
.
NewFake
()
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
ipset
,
nil
)
svcIP
:=
"10.20.30.41"
svcIP
:=
"10.20.30.41"
svcPort
:=
80
svcPort
:=
80
svcNodePort
:=
3001
svcNodePort
:=
3001
...
@@ -769,7 +790,8 @@ func addTestPort(array []api.ServicePort, name string, protocol api.Protocol, po
...
@@ -769,7 +790,8 @@ func addTestPort(array []api.ServicePort, name string, protocol api.Protocol, po
func
TestBuildServiceMapAddRemove
(
t
*
testing
.
T
)
{
func
TestBuildServiceMapAddRemove
(
t
*
testing
.
T
)
{
ipt
:=
iptablestest
.
NewFake
()
ipt
:=
iptablestest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
nil
)
ipset
:=
ipsettest
.
NewFake
()
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
ipset
,
nil
)
services
:=
[]
*
api
.
Service
{
services
:=
[]
*
api
.
Service
{
makeTestService
(
"somewhere-else"
,
"cluster-ip"
,
func
(
svc
*
api
.
Service
)
{
makeTestService
(
"somewhere-else"
,
"cluster-ip"
,
func
(
svc
*
api
.
Service
)
{
...
@@ -874,7 +896,8 @@ func TestBuildServiceMapAddRemove(t *testing.T) {
...
@@ -874,7 +896,8 @@ func TestBuildServiceMapAddRemove(t *testing.T) {
func
TestBuildServiceMapServiceHeadless
(
t
*
testing
.
T
)
{
func
TestBuildServiceMapServiceHeadless
(
t
*
testing
.
T
)
{
ipt
:=
iptablestest
.
NewFake
()
ipt
:=
iptablestest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
nil
)
ipset
:=
ipsettest
.
NewFake
()
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
ipset
,
nil
)
makeServiceMap
(
fp
,
makeServiceMap
(
fp
,
makeTestService
(
"somewhere-else"
,
"headless"
,
func
(
svc
*
api
.
Service
)
{
makeTestService
(
"somewhere-else"
,
"headless"
,
func
(
svc
*
api
.
Service
)
{
...
@@ -907,7 +930,8 @@ func TestBuildServiceMapServiceHeadless(t *testing.T) {
...
@@ -907,7 +930,8 @@ func TestBuildServiceMapServiceHeadless(t *testing.T) {
func
TestBuildServiceMapServiceTypeExternalName
(
t
*
testing
.
T
)
{
func
TestBuildServiceMapServiceTypeExternalName
(
t
*
testing
.
T
)
{
ipt
:=
iptablestest
.
NewFake
()
ipt
:=
iptablestest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
nil
)
ipset
:=
ipsettest
.
NewFake
()
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
ipset
,
nil
)
makeServiceMap
(
fp
,
makeServiceMap
(
fp
,
makeTestService
(
"somewhere-else"
,
"external-name"
,
func
(
svc
*
api
.
Service
)
{
makeTestService
(
"somewhere-else"
,
"external-name"
,
func
(
svc
*
api
.
Service
)
{
...
@@ -934,7 +958,8 @@ func TestBuildServiceMapServiceTypeExternalName(t *testing.T) {
...
@@ -934,7 +958,8 @@ func TestBuildServiceMapServiceTypeExternalName(t *testing.T) {
func
TestBuildServiceMapServiceUpdate
(
t
*
testing
.
T
)
{
func
TestBuildServiceMapServiceUpdate
(
t
*
testing
.
T
)
{
ipt
:=
iptablestest
.
NewFake
()
ipt
:=
iptablestest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
nil
)
ipset
:=
ipsettest
.
NewFake
()
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
ipset
,
nil
)
servicev1
:=
makeTestService
(
"somewhere"
,
"some-service"
,
func
(
svc
*
api
.
Service
)
{
servicev1
:=
makeTestService
(
"somewhere"
,
"some-service"
,
func
(
svc
*
api
.
Service
)
{
svc
.
Spec
.
Type
=
api
.
ServiceTypeClusterIP
svc
.
Spec
.
Type
=
api
.
ServiceTypeClusterIP
...
@@ -1016,8 +1041,9 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
...
@@ -1016,8 +1041,9 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
func
TestSessionAffinity
(
t
*
testing
.
T
)
{
func
TestSessionAffinity
(
t
*
testing
.
T
)
{
ipt
:=
iptablestest
.
NewFake
()
ipt
:=
iptablestest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
ipset
:=
ipsettest
.
NewFake
()
nodeIP
:=
net
.
ParseIP
(
"100.101.102.103"
)
nodeIP
:=
net
.
ParseIP
(
"100.101.102.103"
)
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
[]
net
.
IP
{
nodeIP
})
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
ipset
,
[]
net
.
IP
{
nodeIP
})
svcIP
:=
"10.20.30.41"
svcIP
:=
"10.20.30.41"
svcPort
:=
80
svcPort
:=
80
svcNodePort
:=
3001
svcNodePort
:=
3001
...
@@ -1879,7 +1905,8 @@ func Test_updateEndpointsMap(t *testing.T) {
...
@@ -1879,7 +1905,8 @@ func Test_updateEndpointsMap(t *testing.T) {
for
tci
,
tc
:=
range
testCases
{
for
tci
,
tc
:=
range
testCases
{
ipt
:=
iptablestest
.
NewFake
()
ipt
:=
iptablestest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
ipvs
:=
ipvstest
.
NewFake
()
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
nil
)
ipset
:=
ipsettest
.
NewFake
()
fp
:=
NewFakeProxier
(
ipt
,
ipvs
,
ipset
,
nil
)
fp
.
hostname
=
nodeName
fp
.
hostname
=
nodeName
// First check that after adding all previous versions of endpoints,
// First check that after adding all previous versions of endpoints,
...
...
pkg/proxy/util/endpoints.go
View file @
fbf8a133
...
@@ -19,6 +19,7 @@ package util
...
@@ -19,6 +19,7 @@ package util
import
(
import
(
"fmt"
"fmt"
"net"
"net"
"strconv"
"github.com/golang/glog"
"github.com/golang/glog"
)
)
...
@@ -40,6 +41,21 @@ func IPPart(s string) string {
...
@@ -40,6 +41,21 @@ func IPPart(s string) string {
return
ip
return
ip
}
}
func
PortPart
(
s
string
)
(
int
,
error
)
{
// Must be IP:port
_
,
port
,
err
:=
net
.
SplitHostPort
(
s
)
if
err
!=
nil
{
glog
.
Errorf
(
"Error parsing '%s': %v"
,
s
,
err
)
return
-
1
,
err
}
portNumber
,
err
:=
strconv
.
Atoi
(
port
)
if
err
!=
nil
{
glog
.
Errorf
(
"Error parsing '%s': %v"
,
port
,
err
)
return
-
1
,
err
}
return
portNumber
,
nil
}
// ToCIDR returns a host address of the form <ip-address>/32 for
// ToCIDR returns a host address of the form <ip-address>/32 for
// IPv4 and <ip-address>/128 for IPv6
// IPv4 and <ip-address>/128 for IPv6
func
ToCIDR
(
ip
net
.
IP
)
string
{
func
ToCIDR
(
ip
net
.
IP
)
string
{
...
...
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