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
f7ed9cf0
Commit
f7ed9cf0
authored
Nov 10, 2017
by
Zihong Zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[kube-proxy] Fix session affinity with local endpoints traffic
parent
113bf256
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
1 deletion
+31
-1
proxier.go
pkg/proxy/iptables/proxier.go
+12
-0
proxier_test.go
pkg/proxy/iptables/proxier_test.go
+17
-0
fake.go
pkg/util/iptables/testing/fake.go
+2
-1
No files found.
pkg/proxy/iptables/proxier.go
View file @
f7ed9cf0
...
@@ -1516,6 +1516,18 @@ func (proxier *Proxier) syncProxyRules() {
...
@@ -1516,6 +1516,18 @@ func (proxier *Proxier) syncProxyRules() {
)
)
writeLine
(
proxier
.
natRules
,
args
...
)
writeLine
(
proxier
.
natRules
,
args
...
)
}
else
{
}
else
{
// First write session affinity rules only over local endpoints, if applicable.
if
svcInfo
.
sessionAffinityType
==
api
.
ServiceAffinityClientIP
{
for
_
,
endpointChain
:=
range
localEndpointChains
{
writeLine
(
proxier
.
natRules
,
"-A"
,
string
(
svcXlbChain
),
"-m"
,
"comment"
,
"--comment"
,
svcNameString
,
"-m"
,
"recent"
,
"--name"
,
string
(
endpointChain
),
"--rcheck"
,
"--seconds"
,
strconv
.
Itoa
(
svcInfo
.
stickyMaxAgeSeconds
),
"--reap"
,
"-j"
,
string
(
endpointChain
))
}
}
// Setup probability filter rules only over local endpoints
// Setup probability filter rules only over local endpoints
for
i
,
endpointChain
:=
range
localEndpointChains
{
for
i
,
endpointChain
:=
range
localEndpointChains
{
// Balancing rules in the per-service chain.
// Balancing rules in the per-service chain.
...
...
pkg/proxy/iptables/proxier_test.go
View file @
f7ed9cf0
...
@@ -325,6 +325,15 @@ func NewFakeProxier(ipt utiliptables.Interface) *Proxier {
...
@@ -325,6 +325,15 @@ func NewFakeProxier(ipt utiliptables.Interface) *Proxier {
return
p
return
p
}
}
func
hasSessionAffinityRule
(
rules
[]
iptablestest
.
Rule
)
bool
{
for
_
,
r
:=
range
rules
{
if
_
,
ok
:=
r
[
iptablestest
.
Recent
];
ok
{
return
true
}
}
return
false
}
func
hasJump
(
rules
[]
iptablestest
.
Rule
,
destChain
,
destIP
string
,
destPort
int
)
bool
{
func
hasJump
(
rules
[]
iptablestest
.
Rule
,
destChain
,
destIP
string
,
destPort
int
)
bool
{
destPortStr
:=
strconv
.
Itoa
(
destPort
)
destPortStr
:=
strconv
.
Itoa
(
destPort
)
match
:=
false
match
:=
false
...
@@ -769,6 +778,7 @@ func TestOnlyLocalLoadBalancing(t *testing.T) {
...
@@ -769,6 +778,7 @@ func TestOnlyLocalLoadBalancing(t *testing.T) {
NamespacedName
:
makeNSN
(
"ns1"
,
"svc1"
),
NamespacedName
:
makeNSN
(
"ns1"
,
"svc1"
),
Port
:
"p80"
,
Port
:
"p80"
,
}
}
svcSessionAffinityTimeout
:=
int32
(
10800
)
makeServiceMap
(
fp
,
makeServiceMap
(
fp
,
makeTestService
(
svcPortName
.
Namespace
,
svcPortName
.
Name
,
func
(
svc
*
api
.
Service
)
{
makeTestService
(
svcPortName
.
Namespace
,
svcPortName
.
Name
,
func
(
svc
*
api
.
Service
)
{
...
@@ -784,6 +794,10 @@ func TestOnlyLocalLoadBalancing(t *testing.T) {
...
@@ -784,6 +794,10 @@ func TestOnlyLocalLoadBalancing(t *testing.T) {
IP
:
svcLBIP
,
IP
:
svcLBIP
,
}}
}}
svc
.
Spec
.
ExternalTrafficPolicy
=
api
.
ServiceExternalTrafficPolicyTypeLocal
svc
.
Spec
.
ExternalTrafficPolicy
=
api
.
ServiceExternalTrafficPolicyTypeLocal
svc
.
Spec
.
SessionAffinity
=
api
.
ServiceAffinityClientIP
svc
.
Spec
.
SessionAffinityConfig
=
&
api
.
SessionAffinityConfig
{
ClientIP
:
&
api
.
ClientIPConfig
{
TimeoutSeconds
:
&
svcSessionAffinityTimeout
},
}
}),
}),
)
)
...
@@ -838,6 +852,9 @@ func TestOnlyLocalLoadBalancing(t *testing.T) {
...
@@ -838,6 +852,9 @@ func TestOnlyLocalLoadBalancing(t *testing.T) {
if
!
hasJump
(
lbRules
,
localEpChain
,
""
,
0
)
{
if
!
hasJump
(
lbRules
,
localEpChain
,
""
,
0
)
{
errorf
(
fmt
.
Sprintf
(
"Didn't find jump from lb chain %v to local ep %v"
,
lbChain
,
epStrNonLocal
),
lbRules
,
t
)
errorf
(
fmt
.
Sprintf
(
"Didn't find jump from lb chain %v to local ep %v"
,
lbChain
,
epStrNonLocal
),
lbRules
,
t
)
}
}
if
!
hasSessionAffinityRule
(
lbRules
)
{
errorf
(
fmt
.
Sprintf
(
"Didn't find session affinity rule from lb chain %v"
,
lbChain
),
lbRules
,
t
)
}
}
}
func
TestOnlyLocalNodePortsNoClusterCIDR
(
t
*
testing
.
T
)
{
func
TestOnlyLocalNodePortsNoClusterCIDR
(
t
*
testing
.
T
)
{
...
...
pkg/util/iptables/testing/fake.go
View file @
f7ed9cf0
...
@@ -32,6 +32,7 @@ const (
...
@@ -32,6 +32,7 @@ const (
Jump
=
"-j "
Jump
=
"-j "
Reject
=
"REJECT"
Reject
=
"REJECT"
ToDest
=
"--to-destination "
ToDest
=
"--to-destination "
Recent
=
"recent "
)
)
type
Rule
map
[
string
]
string
type
Rule
map
[
string
]
string
...
@@ -111,7 +112,7 @@ func (f *FakeIPTables) GetRules(chainName string) (rules []Rule) {
...
@@ -111,7 +112,7 @@ func (f *FakeIPTables) GetRules(chainName string) (rules []Rule) {
for
_
,
l
:=
range
strings
.
Split
(
string
(
f
.
Lines
),
"
\n
"
)
{
for
_
,
l
:=
range
strings
.
Split
(
string
(
f
.
Lines
),
"
\n
"
)
{
if
strings
.
Contains
(
l
,
fmt
.
Sprintf
(
"-A %v"
,
chainName
))
{
if
strings
.
Contains
(
l
,
fmt
.
Sprintf
(
"-A %v"
,
chainName
))
{
newRule
:=
Rule
(
map
[
string
]
string
{})
newRule
:=
Rule
(
map
[
string
]
string
{})
for
_
,
arg
:=
range
[]
string
{
Destination
,
Source
,
DPort
,
Protocol
,
Jump
,
ToDest
}
{
for
_
,
arg
:=
range
[]
string
{
Destination
,
Source
,
DPort
,
Protocol
,
Jump
,
ToDest
,
Recent
}
{
tok
:=
getToken
(
l
,
arg
)
tok
:=
getToken
(
l
,
arg
)
if
tok
!=
""
{
if
tok
!=
""
{
newRule
[
arg
]
=
tok
newRule
[
arg
]
=
tok
...
...
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