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
e661a23d
Commit
e661a23d
authored
Nov 13, 2017
by
Lion-Wei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix todo in 'ipvs/proxier.go'
parent
f3024879
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
39 deletions
+21
-39
proxier.go
pkg/proxy/ipvs/proxier.go
+21
-39
No files found.
pkg/proxy/ipvs/proxier.go
View file @
e661a23d
...
@@ -81,6 +81,15 @@ const (
...
@@ -81,6 +81,15 @@ const (
DefaultDummyDevice
=
"kube-ipvs0"
DefaultDummyDevice
=
"kube-ipvs0"
)
)
// tableChainsWithJumpService is the iptables chains ipvs proxy mode used.
var
tableChainsWithJumpService
=
[]
struct
{
table
utiliptables
.
Table
chain
utiliptables
.
Chain
}{
{
utiliptables
.
TableNAT
,
utiliptables
.
ChainOutput
},
{
utiliptables
.
TableNAT
,
utiliptables
.
ChainPrerouting
},
}
var
ipvsModules
=
[]
string
{
var
ipvsModules
=
[]
string
{
"ip_vs"
,
"ip_vs"
,
"ip_vs_rr"
,
"ip_vs_rr"
,
...
@@ -775,7 +784,6 @@ func CanUseIPVSProxier(handle KernelHandler, ipsetver IPSetVersioner) (bool, err
...
@@ -775,7 +784,6 @@ func CanUseIPVSProxier(handle KernelHandler, ipsetver IPSetVersioner) (bool, err
return
true
,
nil
return
true
,
nil
}
}
// TODO: make it simpler.
// CleanupIptablesLeftovers removes all iptables rules and chains created by the Proxier
// CleanupIptablesLeftovers removes all iptables rules and chains created by the Proxier
// It returns true if an error was encountered. Errors are logged.
// It returns true if an error was encountered. Errors are logged.
func
cleanupIptablesLeftovers
(
ipt
utiliptables
.
Interface
)
(
encounteredError
bool
)
{
func
cleanupIptablesLeftovers
(
ipt
utiliptables
.
Interface
)
(
encounteredError
bool
)
{
...
@@ -784,14 +792,7 @@ func cleanupIptablesLeftovers(ipt utiliptables.Interface) (encounteredError bool
...
@@ -784,14 +792,7 @@ func cleanupIptablesLeftovers(ipt utiliptables.Interface) (encounteredError bool
"-m"
,
"comment"
,
"--comment"
,
"kubernetes service portals"
,
"-m"
,
"comment"
,
"--comment"
,
"kubernetes service portals"
,
"-j"
,
string
(
kubeServicesChain
),
"-j"
,
string
(
kubeServicesChain
),
}
}
tableChainsWithJumpServices
:=
[]
struct
{
for
_
,
tc
:=
range
tableChainsWithJumpService
{
table
utiliptables
.
Table
chain
utiliptables
.
Chain
}{
{
utiliptables
.
TableNAT
,
utiliptables
.
ChainOutput
},
{
utiliptables
.
TableNAT
,
utiliptables
.
ChainPrerouting
},
}
for
_
,
tc
:=
range
tableChainsWithJumpServices
{
if
err
:=
ipt
.
DeleteRule
(
tc
.
table
,
tc
.
chain
,
args
...
);
err
!=
nil
{
if
err
:=
ipt
.
DeleteRule
(
tc
.
table
,
tc
.
chain
,
args
...
);
err
!=
nil
{
if
!
utiliptables
.
IsNotFoundError
(
err
)
{
if
!
utiliptables
.
IsNotFoundError
(
err
)
{
glog
.
Errorf
(
"Error removing pure-iptables proxy rule: %v"
,
err
)
glog
.
Errorf
(
"Error removing pure-iptables proxy rule: %v"
,
err
)
...
@@ -813,30 +814,18 @@ func cleanupIptablesLeftovers(ipt utiliptables.Interface) (encounteredError bool
...
@@ -813,30 +814,18 @@ func cleanupIptablesLeftovers(ipt utiliptables.Interface) (encounteredError bool
}
}
// Flush and remove all of our chains.
// Flush and remove all of our chains.
iptablesData
:=
bytes
.
NewBuffer
(
nil
)
for
_
,
chain
:=
range
[]
utiliptables
.
Chain
{
kubeServicesChain
,
kubePostroutingChain
}
{
if
err
:=
ipt
.
SaveInto
(
utiliptables
.
TableNAT
,
iptablesData
);
err
!=
nil
{
if
err
:=
ipt
.
FlushChain
(
utiliptables
.
TableNAT
,
chain
);
err
!=
nil
{
glog
.
Errorf
(
"Failed to execute iptables-save for %s: %v"
,
utiliptables
.
TableNAT
,
err
)
if
!
utiliptables
.
IsNotFoundError
(
err
)
{
encounteredError
=
true
glog
.
Errorf
(
"Error removing ipvs Proxier iptables rule: %v"
,
err
)
}
else
{
encounteredError
=
true
existingNATChains
:=
utiliptables
.
GetChainLines
(
utiliptables
.
TableNAT
,
iptablesData
.
Bytes
())
natChains
:=
bytes
.
NewBuffer
(
nil
)
natRules
:=
bytes
.
NewBuffer
(
nil
)
writeLine
(
natChains
,
"*nat"
)
// Start with chains we know we need to remove.
for
_
,
chain
:=
range
[]
utiliptables
.
Chain
{
kubeServicesChain
,
kubePostroutingChain
,
KubeMarkMasqChain
,
KubeServiceIPSetsChain
}
{
if
_
,
found
:=
existingNATChains
[
chain
];
found
{
chainString
:=
string
(
chain
)
writeLine
(
natChains
,
existingNATChains
[
chain
])
// flush
writeLine
(
natRules
,
"-X"
,
chainString
)
// delete
}
}
}
}
writeLine
(
natRules
,
"COMMIT"
)
if
err
:=
ipt
.
DeleteChain
(
utiliptables
.
TableNAT
,
chain
);
err
!=
nil
{
natLines
:=
append
(
natChains
.
Bytes
(),
natRules
.
Bytes
()
...
)
if
!
utiliptables
.
IsNotFoundError
(
err
)
{
// Write it.
glog
.
Errorf
(
"Error removing ipvs Proxier iptables rule: %v"
,
err
)
err
=
ipt
.
Restore
(
utiliptables
.
TableNAT
,
natLines
,
utiliptables
.
NoFlushTables
,
utiliptables
.
RestoreCounters
)
encounteredError
=
true
if
err
!=
nil
{
}
glog
.
Errorf
(
"Failed to execute iptables-restore for %s: %v"
,
utiliptables
.
TableNAT
,
err
)
encounteredError
=
true
}
}
}
}
return
encounteredError
return
encounteredError
...
@@ -1723,16 +1712,9 @@ func (proxier *Proxier) linkKubeServiceChain(existingNATChains map[utiliptables.
...
@@ -1723,16 +1712,9 @@ func (proxier *Proxier) linkKubeServiceChain(existingNATChains map[utiliptables.
if
_
,
err
:=
proxier
.
iptables
.
EnsureChain
(
utiliptables
.
TableNAT
,
kubeServicesChain
);
err
!=
nil
{
if
_
,
err
:=
proxier
.
iptables
.
EnsureChain
(
utiliptables
.
TableNAT
,
kubeServicesChain
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed to ensure that %s chain %s exists: %v"
,
utiliptables
.
TableNAT
,
kubeServicesChain
,
err
)
return
fmt
.
Errorf
(
"Failed to ensure that %s chain %s exists: %v"
,
utiliptables
.
TableNAT
,
kubeServicesChain
,
err
)
}
}
tableChainsNeedJumpServices
:=
[]
struct
{
table
utiliptables
.
Table
chain
utiliptables
.
Chain
}{
{
utiliptables
.
TableNAT
,
utiliptables
.
ChainOutput
},
{
utiliptables
.
TableNAT
,
utiliptables
.
ChainPrerouting
},
}
comment
:=
"kubernetes service portals"
comment
:=
"kubernetes service portals"
args
:=
[]
string
{
"-m"
,
"comment"
,
"--comment"
,
comment
,
"-j"
,
string
(
kubeServicesChain
)}
args
:=
[]
string
{
"-m"
,
"comment"
,
"--comment"
,
comment
,
"-j"
,
string
(
kubeServicesChain
)}
for
_
,
tc
:=
range
tableChains
NeedJumpServices
{
for
_
,
tc
:=
range
tableChains
WithJumpService
{
if
_
,
err
:=
proxier
.
iptables
.
EnsureRule
(
utiliptables
.
Prepend
,
tc
.
table
,
tc
.
chain
,
args
...
);
err
!=
nil
{
if
_
,
err
:=
proxier
.
iptables
.
EnsureRule
(
utiliptables
.
Prepend
,
tc
.
table
,
tc
.
chain
,
args
...
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed to ensure that %s chain %s jumps to %s: %v"
,
tc
.
table
,
tc
.
chain
,
kubeServicesChain
,
err
)
return
fmt
.
Errorf
(
"Failed to ensure that %s chain %s jumps to %s: %v"
,
tc
.
table
,
tc
.
chain
,
kubeServicesChain
,
err
)
}
}
...
...
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