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
26d58d37
Unverified
Commit
26d58d37
authored
Jan 18, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Jan 18, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #72970 from sttts/sttts-wait-for-http-server-finished-shutdown
apiserver: sync with http server shutdown to flush existing connections
parents
44419ce3
5b47f991
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
34 additions
and
19 deletions
+34
-19
controllermanager.go
cmd/cloud-controller-manager/app/controllermanager.go
+2
-1
controllermanager.go
cmd/kube-controller-manager/app/controllermanager.go
+2
-1
server.go
cmd/kube-scheduler/app/server.go
+2
-1
deprecated_insecure_serving.go
...8s.io/apiserver/pkg/server/deprecated_insecure_serving.go
+3
-1
genericapiserver.go
staging/src/k8s.io/apiserver/pkg/server/genericapiserver.go
+7
-2
genericapiserver_test.go
.../src/k8s.io/apiserver/pkg/server/genericapiserver_test.go
+3
-2
secure_serving.go
staging/src/k8s.io/apiserver/pkg/server/secure_serving.go
+15
-11
No files found.
cmd/cloud-controller-manager/app/controllermanager.go
View file @
26d58d37
...
@@ -145,7 +145,8 @@ func Run(c *cloudcontrollerconfig.CompletedConfig, stopCh <-chan struct{}) error
...
@@ -145,7 +145,8 @@ func Run(c *cloudcontrollerconfig.CompletedConfig, stopCh <-chan struct{}) error
if
c
.
SecureServing
!=
nil
{
if
c
.
SecureServing
!=
nil
{
unsecuredMux
:=
genericcontrollermanager
.
NewBaseHandler
(
&
c
.
ComponentConfig
.
Generic
.
Debugging
,
checks
...
)
unsecuredMux
:=
genericcontrollermanager
.
NewBaseHandler
(
&
c
.
ComponentConfig
.
Generic
.
Debugging
,
checks
...
)
handler
:=
genericcontrollermanager
.
BuildHandlerChain
(
unsecuredMux
,
&
c
.
Authorization
,
&
c
.
Authentication
)
handler
:=
genericcontrollermanager
.
BuildHandlerChain
(
unsecuredMux
,
&
c
.
Authorization
,
&
c
.
Authentication
)
if
err
:=
c
.
SecureServing
.
Serve
(
handler
,
0
,
stopCh
);
err
!=
nil
{
// TODO: handle stoppedCh returned by c.SecureServing.Serve
if
_
,
err
:=
c
.
SecureServing
.
Serve
(
handler
,
0
,
stopCh
);
err
!=
nil
{
return
err
return
err
}
}
}
}
...
...
cmd/kube-controller-manager/app/controllermanager.go
View file @
26d58d37
...
@@ -170,7 +170,8 @@ func Run(c *config.CompletedConfig, stopCh <-chan struct{}) error {
...
@@ -170,7 +170,8 @@ func Run(c *config.CompletedConfig, stopCh <-chan struct{}) error {
if
c
.
SecureServing
!=
nil
{
if
c
.
SecureServing
!=
nil
{
unsecuredMux
=
genericcontrollermanager
.
NewBaseHandler
(
&
c
.
ComponentConfig
.
Generic
.
Debugging
,
checks
...
)
unsecuredMux
=
genericcontrollermanager
.
NewBaseHandler
(
&
c
.
ComponentConfig
.
Generic
.
Debugging
,
checks
...
)
handler
:=
genericcontrollermanager
.
BuildHandlerChain
(
unsecuredMux
,
&
c
.
Authorization
,
&
c
.
Authentication
)
handler
:=
genericcontrollermanager
.
BuildHandlerChain
(
unsecuredMux
,
&
c
.
Authorization
,
&
c
.
Authentication
)
if
err
:=
c
.
SecureServing
.
Serve
(
handler
,
0
,
stopCh
);
err
!=
nil
{
// TODO: handle stoppedCh returned by c.SecureServing.Serve
if
_
,
err
:=
c
.
SecureServing
.
Serve
(
handler
,
0
,
stopCh
);
err
!=
nil
{
return
err
return
err
}
}
}
}
...
...
cmd/kube-scheduler/app/server.go
View file @
26d58d37
...
@@ -208,7 +208,8 @@ func Run(cc schedulerserverconfig.CompletedConfig, stopCh <-chan struct{}) error
...
@@ -208,7 +208,8 @@ func Run(cc schedulerserverconfig.CompletedConfig, stopCh <-chan struct{}) error
}
}
if
cc
.
SecureServing
!=
nil
{
if
cc
.
SecureServing
!=
nil
{
handler
:=
buildHandlerChain
(
newHealthzHandler
(
&
cc
.
ComponentConfig
,
false
,
checks
...
),
cc
.
Authentication
.
Authenticator
,
cc
.
Authorization
.
Authorizer
)
handler
:=
buildHandlerChain
(
newHealthzHandler
(
&
cc
.
ComponentConfig
,
false
,
checks
...
),
cc
.
Authentication
.
Authenticator
,
cc
.
Authorization
.
Authorizer
)
if
err
:=
cc
.
SecureServing
.
Serve
(
handler
,
0
,
stopCh
);
err
!=
nil
{
// TODO: handle stoppedCh returned by c.SecureServing.Serve
if
_
,
err
:=
cc
.
SecureServing
.
Serve
(
handler
,
0
,
stopCh
);
err
!=
nil
{
// fail early for secure handlers, removing the old error loop from above
// fail early for secure handlers, removing the old error loop from above
return
fmt
.
Errorf
(
"failed to start healthz server: %v"
,
err
)
return
fmt
.
Errorf
(
"failed to start healthz server: %v"
,
err
)
}
}
...
...
staging/src/k8s.io/apiserver/pkg/server/deprecated_insecure_serving.go
View file @
26d58d37
...
@@ -50,7 +50,9 @@ func (s *DeprecatedInsecureServingInfo) Serve(handler http.Handler, shutdownTime
...
@@ -50,7 +50,9 @@ func (s *DeprecatedInsecureServingInfo) Serve(handler http.Handler, shutdownTime
}
else
{
}
else
{
klog
.
Infof
(
"Serving insecurely on %s"
,
s
.
Listener
.
Addr
())
klog
.
Infof
(
"Serving insecurely on %s"
,
s
.
Listener
.
Addr
())
}
}
return
RunServer
(
insecureServer
,
s
.
Listener
,
shutdownTimeout
,
stopCh
)
_
,
err
:=
RunServer
(
insecureServer
,
s
.
Listener
,
shutdownTimeout
,
stopCh
)
// NOTE: we do not handle stoppedCh returned by RunServer for graceful termination here
return
err
}
}
func
(
s
*
DeprecatedInsecureServingInfo
)
NewLoopbackClientConfig
()
(
*
rest
.
Config
,
error
)
{
func
(
s
*
DeprecatedInsecureServingInfo
)
NewLoopbackClientConfig
()
(
*
rest
.
Config
,
error
)
{
...
...
staging/src/k8s.io/apiserver/pkg/server/genericapiserver.go
View file @
26d58d37
...
@@ -291,9 +291,11 @@ func (s preparedGenericAPIServer) NonBlockingRun(stopCh <-chan struct{}) error {
...
@@ -291,9 +291,11 @@ func (s preparedGenericAPIServer) NonBlockingRun(stopCh <-chan struct{}) error {
// Use an internal stop channel to allow cleanup of the listeners on error.
// Use an internal stop channel to allow cleanup of the listeners on error.
internalStopCh
:=
make
(
chan
struct
{})
internalStopCh
:=
make
(
chan
struct
{})
var
stoppedCh
<-
chan
struct
{}
if
s
.
SecureServingInfo
!=
nil
&&
s
.
Handler
!=
nil
{
if
s
.
SecureServingInfo
!=
nil
&&
s
.
Handler
!=
nil
{
if
err
:=
s
.
SecureServingInfo
.
Serve
(
s
.
Handler
,
s
.
ShutdownTimeout
,
internalStopCh
);
err
!=
nil
{
var
err
error
stoppedCh
,
err
=
s
.
SecureServingInfo
.
Serve
(
s
.
Handler
,
s
.
ShutdownTimeout
,
internalStopCh
)
if
err
!=
nil
{
close
(
internalStopCh
)
close
(
internalStopCh
)
return
err
return
err
}
}
...
@@ -305,6 +307,9 @@ func (s preparedGenericAPIServer) NonBlockingRun(stopCh <-chan struct{}) error {
...
@@ -305,6 +307,9 @@ func (s preparedGenericAPIServer) NonBlockingRun(stopCh <-chan struct{}) error {
go
func
()
{
go
func
()
{
<-
stopCh
<-
stopCh
close
(
internalStopCh
)
close
(
internalStopCh
)
if
stoppedCh
!=
nil
{
<-
stoppedCh
}
s
.
HandlerChainWaitGroup
.
Wait
()
s
.
HandlerChainWaitGroup
.
Wait
()
close
(
auditStopCh
)
close
(
auditStopCh
)
}()
}()
...
...
staging/src/k8s.io/apiserver/pkg/server/genericapiserver_test.go
View file @
26d58d37
...
@@ -539,9 +539,9 @@ func TestGracefulShutdown(t *testing.T) {
...
@@ -539,9 +539,9 @@ func TestGracefulShutdown(t *testing.T) {
// get port
// get port
serverPort
:=
ln
.
Addr
()
.
(
*
net
.
TCPAddr
)
.
Port
serverPort
:=
ln
.
Addr
()
.
(
*
net
.
TCPAddr
)
.
Port
err
=
RunServer
(
insecureServer
,
ln
,
10
*
time
.
Second
,
stopCh
)
stoppedCh
,
err
:
=
RunServer
(
insecureServer
,
ln
,
10
*
time
.
Second
,
stopCh
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Error
f
(
"RunServer err: %v"
,
err
)
t
.
Fatal
f
(
"RunServer err: %v"
,
err
)
}
}
graceCh
:=
make
(
chan
struct
{})
graceCh
:=
make
(
chan
struct
{})
...
@@ -568,6 +568,7 @@ func TestGracefulShutdown(t *testing.T) {
...
@@ -568,6 +568,7 @@ func TestGracefulShutdown(t *testing.T) {
// wait for wait group handler finish
// wait for wait group handler finish
s
.
HandlerChainWaitGroup
.
Wait
()
s
.
HandlerChainWaitGroup
.
Wait
()
<-
stoppedCh
// check server all handlers finished.
// check server all handlers finished.
if
!
graceShutdown
{
if
!
graceShutdown
{
...
...
staging/src/k8s.io/apiserver/pkg/server/secure_serving.go
View file @
26d58d37
...
@@ -37,12 +37,12 @@ const (
...
@@ -37,12 +37,12 @@ const (
defaultKeepAlivePeriod
=
3
*
time
.
Minute
defaultKeepAlivePeriod
=
3
*
time
.
Minute
)
)
//
serveSecurely runs the secure http server. It fails only if certificates cannot
//
Serve runs the secure http server. It fails only if certificates cannot be loaded or the initial listen call fails.
//
be loaded or the initial listen call fails. The actual server loop (stoppable by closing
//
The actual server loop (stoppable by closing stopCh) runs in a go routine, i.e. Serve does not block.
//
stopCh) runs in a go routine, i.e. serveSecurely does not block
.
//
It returns a stoppedCh that is closed when all non-hijacked active requests have been processed
.
func
(
s
*
SecureServingInfo
)
Serve
(
handler
http
.
Handler
,
shutdownTimeout
time
.
Duration
,
stopCh
<-
chan
struct
{})
error
{
func
(
s
*
SecureServingInfo
)
Serve
(
handler
http
.
Handler
,
shutdownTimeout
time
.
Duration
,
stopCh
<-
chan
struct
{})
(
<-
chan
struct
{},
error
)
{
if
s
.
Listener
==
nil
{
if
s
.
Listener
==
nil
{
return
fmt
.
Errorf
(
"listener must not be nil"
)
return
nil
,
fmt
.
Errorf
(
"listener must not be nil"
)
}
}
secureServer
:=
&
http
.
Server
{
secureServer
:=
&
http
.
Server
{
...
@@ -110,7 +110,7 @@ func (s *SecureServingInfo) Serve(handler http.Handler, shutdownTimeout time.Dur
...
@@ -110,7 +110,7 @@ func (s *SecureServingInfo) Serve(handler http.Handler, shutdownTimeout time.Dur
// apply settings to the server
// apply settings to the server
if
err
:=
http2
.
ConfigureServer
(
secureServer
,
http2Options
);
err
!=
nil
{
if
err
:=
http2
.
ConfigureServer
(
secureServer
,
http2Options
);
err
!=
nil
{
return
fmt
.
Errorf
(
"error configuring http2: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"error configuring http2: %v"
,
err
)
}
}
klog
.
Infof
(
"Serving securely on %s"
,
secureServer
.
Addr
)
klog
.
Infof
(
"Serving securely on %s"
,
secureServer
.
Addr
)
...
@@ -118,21 +118,25 @@ func (s *SecureServingInfo) Serve(handler http.Handler, shutdownTimeout time.Dur
...
@@ -118,21 +118,25 @@ func (s *SecureServingInfo) Serve(handler http.Handler, shutdownTimeout time.Dur
}
}
// RunServer listens on the given port if listener is not given,
// RunServer listens on the given port if listener is not given,
// then spawns a go-routine continuously serving
// then spawns a go-routine continuously serving until the stopCh is closed.
// until the stopCh is closed. This function does not block.
// It returns a stoppedCh that is closed when all non-hijacked active requests
// have been processed.
// This function does not block
// TODO: make private when insecure serving is gone from the kube-apiserver
// TODO: make private when insecure serving is gone from the kube-apiserver
func
RunServer
(
func
RunServer
(
server
*
http
.
Server
,
server
*
http
.
Server
,
ln
net
.
Listener
,
ln
net
.
Listener
,
shutDownTimeout
time
.
Duration
,
shutDownTimeout
time
.
Duration
,
stopCh
<-
chan
struct
{},
stopCh
<-
chan
struct
{},
)
error
{
)
(
<-
chan
struct
{},
error
)
{
if
ln
==
nil
{
if
ln
==
nil
{
return
fmt
.
Errorf
(
"listener must not be nil"
)
return
nil
,
fmt
.
Errorf
(
"listener must not be nil"
)
}
}
// Shutdown server gracefully.
// Shutdown server gracefully.
stoppedCh
:=
make
(
chan
struct
{})
go
func
()
{
go
func
()
{
defer
close
(
stoppedCh
)
<-
stopCh
<-
stopCh
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
shutDownTimeout
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
shutDownTimeout
)
server
.
Shutdown
(
ctx
)
server
.
Shutdown
(
ctx
)
...
@@ -159,7 +163,7 @@ func RunServer(
...
@@ -159,7 +163,7 @@ func RunServer(
}
}
}()
}()
return
nil
return
stoppedCh
,
nil
}
}
type
NamedTLSCert
struct
{
type
NamedTLSCert
struct
{
...
...
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