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
bdf3d248
Unverified
Commit
bdf3d248
authored
May 31, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
May 31, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #77523 from andrewsykim/fix-xlb-from-local
iptables proxier: route local traffic to LB IPs to service chain
parents
6feea43b
8dfd4def
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
8 deletions
+26
-8
proxier.go
pkg/proxy/iptables/proxier.go
+10
-0
proxier_test.go
pkg/proxy/iptables/proxier_test.go
+14
-7
fake.go
pkg/util/iptables/testing/fake.go
+2
-1
No files found.
pkg/proxy/iptables/proxier.go
View file @
bdf3d248
...
@@ -1220,6 +1220,16 @@ func (proxier *Proxier) syncProxyRules() {
...
@@ -1220,6 +1220,16 @@ func (proxier *Proxier) syncProxyRules() {
continue
continue
}
}
// For LBs with externalTrafficPolicy=Local, we need to re-route any local traffic to the service chain masqueraded.
// Masqueraded traffic in this scenario is okay since source IP preservation only applies to external traffic anyways.
args
=
append
(
args
[
:
0
],
"-A"
,
string
(
svcXlbChain
))
writeLine
(
proxier
.
natRules
,
append
(
args
,
"-m"
,
"comment"
,
"--comment"
,
fmt
.
Sprintf
(
`"masquerade LOCAL traffic for %s LB IP"`
,
svcNameString
),
"-m"
,
"addrtype"
,
"--src-type"
,
"LOCAL"
,
"-j"
,
string
(
KubeMarkMasqChain
))
...
)
writeLine
(
proxier
.
natRules
,
append
(
args
,
"-m"
,
"comment"
,
"--comment"
,
fmt
.
Sprintf
(
`"route LOCAL traffic for %s LB IP to service chain"`
,
svcNameString
),
"-m"
,
"addrtype"
,
"--src-type"
,
"LOCAL"
,
"-j"
,
string
(
svcChain
))
...
)
// First rule in the chain redirects all pod -> external VIP traffic to the
// First rule in the chain redirects all pod -> external VIP traffic to the
// Service's ClusterIP instead. This happens whether or not we have local
// Service's ClusterIP instead. This happens whether or not we have local
// endpoints; only if clusterCIDR is specified
// endpoints; only if clusterCIDR is specified
...
...
pkg/proxy/iptables/proxier_test.go
View file @
bdf3d248
...
@@ -424,6 +424,18 @@ func hasJump(rules []iptablestest.Rule, destChain, destIP string, destPort int)
...
@@ -424,6 +424,18 @@ func hasJump(rules []iptablestest.Rule, destChain, destIP string, destPort int)
return
match
return
match
}
}
func
hasSrcType
(
rules
[]
iptablestest
.
Rule
,
srcType
string
)
bool
{
for
_
,
r
:=
range
rules
{
if
r
[
iptablestest
.
SrcType
]
!=
srcType
{
continue
}
return
true
}
return
false
}
func
TestHasJump
(
t
*
testing
.
T
)
{
func
TestHasJump
(
t
*
testing
.
T
)
{
testCases
:=
map
[
string
]
struct
{
testCases
:=
map
[
string
]
struct
{
rules
[]
iptablestest
.
Rule
rules
[]
iptablestest
.
Rule
...
@@ -942,7 +954,6 @@ func TestOnlyLocalNodePorts(t *testing.T) {
...
@@ -942,7 +954,6 @@ func TestOnlyLocalNodePorts(t *testing.T) {
}
}
func
onlyLocalNodePorts
(
t
*
testing
.
T
,
fp
*
Proxier
,
ipt
*
iptablestest
.
FakeIPTables
)
{
func
onlyLocalNodePorts
(
t
*
testing
.
T
,
fp
*
Proxier
,
ipt
*
iptablestest
.
FakeIPTables
)
{
shouldLBTOSVCRuleExist
:=
len
(
fp
.
clusterCIDR
)
>
0
svcIP
:=
"10.20.30.41"
svcIP
:=
"10.20.30.41"
svcPort
:=
80
svcPort
:=
80
svcNodePort
:=
3001
svcNodePort
:=
3001
...
@@ -1018,12 +1029,8 @@ func onlyLocalNodePorts(t *testing.T, fp *Proxier, ipt *iptablestest.FakeIPTable
...
@@ -1018,12 +1029,8 @@ func onlyLocalNodePorts(t *testing.T, fp *Proxier, ipt *iptablestest.FakeIPTable
if
hasJump
(
lbRules
,
nonLocalEpChain
,
""
,
0
)
{
if
hasJump
(
lbRules
,
nonLocalEpChain
,
""
,
0
)
{
errorf
(
fmt
.
Sprintf
(
"Found jump from lb chain %v to non-local ep %v"
,
lbChain
,
epStrLocal
),
lbRules
,
t
)
errorf
(
fmt
.
Sprintf
(
"Found jump from lb chain %v to non-local ep %v"
,
lbChain
,
epStrLocal
),
lbRules
,
t
)
}
}
if
hasJump
(
lbRules
,
svcChain
,
""
,
0
)
!=
shouldLBTOSVCRuleExist
{
if
!
hasJump
(
lbRules
,
svcChain
,
""
,
0
)
||
!
hasSrcType
(
lbRules
,
"LOCAL"
)
{
prefix
:=
"Did not find "
errorf
(
fmt
.
Sprintf
(
"Did not find jump from lb chain %v to svc %v with src-type LOCAL"
,
lbChain
,
svcChain
),
lbRules
,
t
)
if
!
shouldLBTOSVCRuleExist
{
prefix
=
"Found "
}
errorf
(
fmt
.
Sprintf
(
"%s jump from lb chain %v to svc %v"
,
prefix
,
lbChain
,
svcChain
),
lbRules
,
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
,
epStrLocal
),
lbRules
,
t
)
errorf
(
fmt
.
Sprintf
(
"Didn't find jump from lb chain %v to local ep %v"
,
lbChain
,
epStrLocal
),
lbRules
,
t
)
...
...
pkg/util/iptables/testing/fake.go
View file @
bdf3d248
...
@@ -34,6 +34,7 @@ const (
...
@@ -34,6 +34,7 @@ const (
ToDest
=
"--to-destination "
ToDest
=
"--to-destination "
Recent
=
"recent "
Recent
=
"recent "
MatchSet
=
"--match-set "
MatchSet
=
"--match-set "
SrcType
=
"--src-type "
)
)
type
Rule
map
[
string
]
string
type
Rule
map
[
string
]
string
...
@@ -113,7 +114,7 @@ func (f *FakeIPTables) GetRules(chainName string) (rules []Rule) {
...
@@ -113,7 +114,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
,
Recent
,
MatchSet
}
{
for
_
,
arg
:=
range
[]
string
{
Destination
,
Source
,
DPort
,
Protocol
,
Jump
,
ToDest
,
Recent
,
MatchSet
,
SrcType
}
{
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