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
a0b8d1cb
Unverified
Commit
a0b8d1cb
authored
Apr 27, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Apr 27, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #76732 from JieJhih/proxy/server
os exit when option is true
parents
e5dd4521
94731c5d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
14 deletions
+32
-14
server.go
cmd/kube-proxy/app/server.go
+19
-11
server_others.go
cmd/kube-proxy/app/server_others.go
+0
-1
server_test.go
cmd/kube-proxy/app/server_test.go
+11
-1
server_windows.go
cmd/kube-proxy/app/server_windows.go
+2
-1
No files found.
cmd/kube-proxy/app/server.go
View file @
a0b8d1cb
...
@@ -92,6 +92,7 @@ const (
...
@@ -92,6 +92,7 @@ const (
// proxyRun defines the interface to run a specified ProxyServer
// proxyRun defines the interface to run a specified ProxyServer
type
proxyRun
interface
{
type
proxyRun
interface
{
Run
()
error
Run
()
error
CleanupAndExit
()
error
}
}
// Options contains everything necessary to create and run a proxy server.
// Options contains everything necessary to create and run a proxy server.
...
@@ -308,6 +309,11 @@ func (o *Options) Run() error {
...
@@ -308,6 +309,11 @@ func (o *Options) Run() error {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
o
.
CleanupAndExit
{
return
proxyServer
.
CleanupAndExit
()
}
o
.
proxyServer
=
proxyServer
o
.
proxyServer
=
proxyServer
return
o
.
runLoop
()
return
o
.
runLoop
()
}
}
...
@@ -475,7 +481,6 @@ type ProxyServer struct {
...
@@ -475,7 +481,6 @@ type ProxyServer struct {
Conntracker
Conntracker
// if nil, ignored
Conntracker
Conntracker
// if nil, ignored
ProxyMode
string
ProxyMode
string
NodeRef
*
v1
.
ObjectReference
NodeRef
*
v1
.
ObjectReference
CleanupAndExit
bool
CleanupIPVS
bool
CleanupIPVS
bool
MetricsBindAddress
string
MetricsBindAddress
string
EnableProfiling
bool
EnableProfiling
bool
...
@@ -524,19 +529,10 @@ func createClients(config componentbaseconfig.ClientConnectionConfiguration, mas
...
@@ -524,19 +529,10 @@ func createClients(config componentbaseconfig.ClientConnectionConfiguration, mas
}
}
// Run runs the specified ProxyServer. This should never exit (unless CleanupAndExit is set).
// Run runs the specified ProxyServer. This should never exit (unless CleanupAndExit is set).
// TODO: At the moment, Run() cannot return a nil error, otherwise it's caller will never exit. Update callers of Run to handle nil errors.
func
(
s
*
ProxyServer
)
Run
()
error
{
func
(
s
*
ProxyServer
)
Run
()
error
{
// To help debugging, immediately log version
// To help debugging, immediately log version
klog
.
Infof
(
"Version: %+v"
,
version
.
Get
())
klog
.
Infof
(
"Version: %+v"
,
version
.
Get
())
// remove iptables rules and exit
if
s
.
CleanupAndExit
{
encounteredError
:=
userspace
.
CleanupLeftovers
(
s
.
IptInterface
)
encounteredError
=
iptables
.
CleanupLeftovers
(
s
.
IptInterface
)
||
encounteredError
encounteredError
=
ipvs
.
CleanupLeftovers
(
s
.
IpvsInterface
,
s
.
IptInterface
,
s
.
IpsetInterface
,
s
.
CleanupIPVS
)
||
encounteredError
if
encounteredError
{
return
errors
.
New
(
"encountered an error while tearing down rules"
)
}
return
nil
}
// TODO(vmarmol): Use container config for this.
// TODO(vmarmol): Use container config for this.
var
oomAdjuster
*
oom
.
OOMAdjuster
var
oomAdjuster
*
oom
.
OOMAdjuster
...
@@ -682,3 +678,15 @@ func getConntrackMax(config kubeproxyconfig.KubeProxyConntrackConfiguration) (in
...
@@ -682,3 +678,15 @@ func getConntrackMax(config kubeproxyconfig.KubeProxyConntrackConfiguration) (in
}
}
return
0
,
nil
return
0
,
nil
}
}
// CleanupAndExit remove iptables rules and exit if success return nil
func
(
s
*
ProxyServer
)
CleanupAndExit
()
error
{
encounteredError
:=
userspace
.
CleanupLeftovers
(
s
.
IptInterface
)
encounteredError
=
iptables
.
CleanupLeftovers
(
s
.
IptInterface
)
||
encounteredError
encounteredError
=
ipvs
.
CleanupLeftovers
(
s
.
IpvsInterface
,
s
.
IptInterface
,
s
.
IpsetInterface
,
s
.
CleanupIPVS
)
||
encounteredError
if
encounteredError
{
return
errors
.
New
(
"encountered an error while tearing down rules"
)
}
return
nil
}
cmd/kube-proxy/app/server_others.go
View file @
a0b8d1cb
...
@@ -102,7 +102,6 @@ func newProxyServer(
...
@@ -102,7 +102,6 @@ func newProxyServer(
IptInterface
:
iptInterface
,
IptInterface
:
iptInterface
,
IpvsInterface
:
ipvsInterface
,
IpvsInterface
:
ipvsInterface
,
IpsetInterface
:
ipsetInterface
,
IpsetInterface
:
ipsetInterface
,
CleanupAndExit
:
cleanupAndExit
,
},
nil
},
nil
}
}
...
...
cmd/kube-proxy/app/server_test.go
View file @
a0b8d1cb
...
@@ -17,6 +17,7 @@ limitations under the License.
...
@@ -17,6 +17,7 @@ limitations under the License.
package
app
package
app
import
(
import
(
"errors"
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"os"
"os"
...
@@ -108,7 +109,6 @@ func TestProxyServerWithCleanupAndExit(t *testing.T) {
...
@@ -108,7 +109,6 @@ func TestProxyServerWithCleanupAndExit(t *testing.T) {
assert
.
Nil
(
t
,
err
,
"unexpected error in NewProxyServer, addr: %s"
,
addr
)
assert
.
Nil
(
t
,
err
,
"unexpected error in NewProxyServer, addr: %s"
,
addr
)
assert
.
NotNil
(
t
,
proxyserver
,
"nil proxy server obj, addr: %s"
,
addr
)
assert
.
NotNil
(
t
,
proxyserver
,
"nil proxy server obj, addr: %s"
,
addr
)
assert
.
NotNil
(
t
,
proxyserver
.
IptInterface
,
"nil iptables intf, addr: %s"
,
addr
)
assert
.
NotNil
(
t
,
proxyserver
.
IptInterface
,
"nil iptables intf, addr: %s"
,
addr
)
assert
.
True
(
t
,
proxyserver
.
CleanupAndExit
,
"false CleanupAndExit, addr: %s"
,
addr
)
// Clean up config for next test case
// Clean up config for next test case
configz
.
Delete
(
kubeproxyconfig
.
GroupName
)
configz
.
Delete
(
kubeproxyconfig
.
GroupName
)
...
@@ -540,6 +540,11 @@ func (s *fakeProxyServerLongRun) Run() error {
...
@@ -540,6 +540,11 @@ func (s *fakeProxyServerLongRun) Run() error {
}
}
}
}
// CleanupAndExit runs in the specified ProxyServer.
func
(
s
*
fakeProxyServerLongRun
)
CleanupAndExit
()
error
{
return
nil
}
type
fakeProxyServerError
struct
{}
type
fakeProxyServerError
struct
{}
// Run runs the specified ProxyServer.
// Run runs the specified ProxyServer.
...
@@ -550,6 +555,11 @@ func (s *fakeProxyServerError) Run() error {
...
@@ -550,6 +555,11 @@ func (s *fakeProxyServerError) Run() error {
}
}
}
}
// CleanupAndExit runs in the specified ProxyServer.
func
(
s
*
fakeProxyServerError
)
CleanupAndExit
()
error
{
return
errors
.
New
(
"mocking error from ProxyServer.CleanupAndExit()"
)
}
func
TestAddressFromDeprecatedFlags
(
t
*
testing
.
T
)
{
func
TestAddressFromDeprecatedFlags
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
testCases
:=
[]
struct
{
name
string
name
string
...
...
cmd/kube-proxy/app/server_windows.go
View file @
a0b8d1cb
...
@@ -24,6 +24,7 @@ import (
...
@@ -24,6 +24,7 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"net"
"net"
// Enable pprof HTTP handlers.
// Enable pprof HTTP handlers.
_
"net/http/pprof"
_
"net/http/pprof"
...
@@ -63,7 +64,7 @@ func newProxyServer(config *proxyconfigapi.KubeProxyConfiguration, cleanupAndExi
...
@@ -63,7 +64,7 @@ func newProxyServer(config *proxyconfigapi.KubeProxyConfiguration, cleanupAndExi
// 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
{
return
&
ProxyServer
{
CleanupAndExit
:
cleanupAndExit
},
nil
return
&
ProxyServer
{},
nil
}
}
client
,
eventClient
,
err
:=
createClients
(
config
.
ClientConnection
,
master
)
client
,
eventClient
,
err
:=
createClients
(
config
.
ClientConnection
,
master
)
...
...
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