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
03c255d7
Commit
03c255d7
authored
May 24, 2017
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Store chain names to avoid recomputing them multiple times
parent
c4d51f12
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
22 deletions
+33
-22
proxier.go
pkg/proxy/iptables/proxier.go
+17
-6
proxier_test.go
pkg/proxy/iptables/proxier_test.go
+16
-16
No files found.
pkg/proxy/iptables/proxier.go
View file @
03c255d7
...
@@ -148,6 +148,11 @@ type serviceInfo struct {
...
@@ -148,6 +148,11 @@ type serviceInfo struct {
loadBalancerSourceRanges
[]
string
loadBalancerSourceRanges
[]
string
onlyNodeLocalEndpoints
bool
onlyNodeLocalEndpoints
bool
healthCheckNodePort
int
healthCheckNodePort
int
// The following fields are computed and stored for performance reasons.
serviceNameString
string
servicePortChainName
utiliptables
.
Chain
serviceFirewallChainName
utiliptables
.
Chain
serviceLBChainName
utiliptables
.
Chain
}
}
// internal struct for endpoints information
// internal struct for endpoints information
...
@@ -214,6 +219,13 @@ func newServiceInfo(svcPortName proxy.ServicePortName, port *api.ServicePort, se
...
@@ -214,6 +219,13 @@ func newServiceInfo(svcPortName proxy.ServicePortName, port *api.ServicePort, se
}
}
}
}
// Store the following for performance reasons.
protocol
:=
strings
.
ToLower
(
string
(
info
.
protocol
))
info
.
serviceNameString
=
svcPortName
.
String
()
info
.
servicePortChainName
=
servicePortChainName
(
info
.
serviceNameString
,
protocol
)
info
.
serviceFirewallChainName
=
serviceFirewallChainName
(
info
.
serviceNameString
,
protocol
)
info
.
serviceLBChainName
=
serviceLBChainName
(
info
.
serviceNameString
,
protocol
)
return
info
return
info
}
}
...
@@ -1124,14 +1136,13 @@ func (proxier *Proxier) syncProxyRules() {
...
@@ -1124,14 +1136,13 @@ func (proxier *Proxier) syncProxyRules() {
args
:=
make
([]
string
,
64
)
args
:=
make
([]
string
,
64
)
// Build rules for each service.
// Build rules for each service.
var
svcNameString
string
for
svcName
,
svcInfo
:=
range
proxier
.
serviceMap
{
for
svcName
,
svcInfo
:=
range
proxier
.
serviceMap
{
protocol
:=
strings
.
ToLower
(
string
(
svcInfo
.
protocol
))
protocol
:=
strings
.
ToLower
(
string
(
svcInfo
.
protocol
))
// Precompute svcNameString; with many services the many calls
svcNameString
=
svcInfo
.
serviceNameString
// to ServicePortName.String() show up in CPU profiles.
svcNameString
:=
svcName
.
String
()
// Create the per-service chain, retaining counters if possible.
// Create the per-service chain, retaining counters if possible.
svcChain
:=
s
ervicePortChainName
(
svcNameString
,
protocol
)
svcChain
:=
s
vcInfo
.
servicePortChainName
if
chain
,
ok
:=
existingNATChains
[
svcChain
];
ok
{
if
chain
,
ok
:=
existingNATChains
[
svcChain
];
ok
{
writeLine
(
proxier
.
natChains
,
chain
)
writeLine
(
proxier
.
natChains
,
chain
)
}
else
{
}
else
{
...
@@ -1139,7 +1150,7 @@ func (proxier *Proxier) syncProxyRules() {
...
@@ -1139,7 +1150,7 @@ func (proxier *Proxier) syncProxyRules() {
}
}
activeNATChains
[
svcChain
]
=
true
activeNATChains
[
svcChain
]
=
true
svcXlbChain
:=
s
erviceLBChainName
(
svcNameString
,
protocol
)
svcXlbChain
:=
s
vcInfo
.
serviceLBChainName
if
svcInfo
.
onlyNodeLocalEndpoints
{
if
svcInfo
.
onlyNodeLocalEndpoints
{
// Only for services request OnlyLocal traffic
// Only for services request OnlyLocal traffic
// create the per-service LB chain, retaining counters if possible.
// create the per-service LB chain, retaining counters if possible.
...
@@ -1243,10 +1254,10 @@ func (proxier *Proxier) syncProxyRules() {
...
@@ -1243,10 +1254,10 @@ func (proxier *Proxier) syncProxyRules() {
}
}
// Capture load-balancer ingress.
// Capture load-balancer ingress.
fwChain
:=
svcInfo
.
serviceFirewallChainName
for
_
,
ingress
:=
range
svcInfo
.
loadBalancerStatus
.
Ingress
{
for
_
,
ingress
:=
range
svcInfo
.
loadBalancerStatus
.
Ingress
{
if
ingress
.
IP
!=
""
{
if
ingress
.
IP
!=
""
{
// create service firewall chain
// create service firewall chain
fwChain
:=
serviceFirewallChainName
(
svcNameString
,
protocol
)
if
chain
,
ok
:=
existingNATChains
[
fwChain
];
ok
{
if
chain
,
ok
:=
existingNATChains
[
fwChain
];
ok
{
writeLine
(
proxier
.
natChains
,
chain
)
writeLine
(
proxier
.
natChains
,
chain
)
}
else
{
}
else
{
...
...
pkg/proxy/iptables/proxier_test.go
View file @
03c255d7
...
@@ -386,23 +386,23 @@ func NewFakeProxier(ipt utiliptables.Interface) *Proxier {
...
@@ -386,23 +386,23 @@ func NewFakeProxier(ipt utiliptables.Interface) *Proxier {
// TODO: Call NewProxier after refactoring out the goroutine
// TODO: Call NewProxier after refactoring out the goroutine
// invocation into a Run() method.
// invocation into a Run() method.
p
:=
&
Proxier
{
p
:=
&
Proxier
{
exec
:
&
exec
.
FakeExec
{},
exec
:
&
exec
.
FakeExec
{},
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
,
clusterCIDR
:
"10.0.0.0/24"
,
clusterCIDR
:
"10.0.0.0/24"
,
hostname
:
testHostname
,
hostname
:
testHostname
,
portsMap
:
make
(
map
[
localPort
]
closeable
),
portsMap
:
make
(
map
[
localPort
]
closeable
),
portMapper
:
&
fakePortOpener
{[]
*
localPort
{}},
portMapper
:
&
fakePortOpener
{[]
*
localPort
{}},
healthChecker
:
newFakeHealthChecker
(),
healthChecker
:
newFakeHealthChecker
(),
precomputedProbabilities
:
make
([]
string
,
0
,
1001
),
precomputedProbabilities
:
make
([]
string
,
0
,
1001
),
iptablesData
:
bytes
.
NewBuffer
(
nil
),
iptablesData
:
bytes
.
NewBuffer
(
nil
),
filterChains
:
bytes
.
NewBuffer
(
nil
),
filterChains
:
bytes
.
NewBuffer
(
nil
),
filterRules
:
bytes
.
NewBuffer
(
nil
),
filterRules
:
bytes
.
NewBuffer
(
nil
),
natChains
:
bytes
.
NewBuffer
(
nil
),
natChains
:
bytes
.
NewBuffer
(
nil
),
natRules
:
bytes
.
NewBuffer
(
nil
),
natRules
:
bytes
.
NewBuffer
(
nil
),
}
}
p
.
syncRunner
=
async
.
NewBoundedFrequencyRunner
(
"test-sync-runner"
,
p
.
syncProxyRules
,
0
,
time
.
Minute
,
1
)
p
.
syncRunner
=
async
.
NewBoundedFrequencyRunner
(
"test-sync-runner"
,
p
.
syncProxyRules
,
0
,
time
.
Minute
,
1
)
return
p
return
p
...
...
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