mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
apiserver: add lifecycle signal for preshutdown hook
This commit is contained in:
parent
c79b909de7
commit
b1f7b60515
@ -431,7 +431,7 @@ func (s *GenericAPIServer) PrepareRun() preparedGenericAPIServer {
|
|||||||
// | |
|
// | |
|
||||||
// (ShutdownDelayDuration) (PreShutdownHooks)
|
// (ShutdownDelayDuration) (PreShutdownHooks)
|
||||||
// | |
|
// | |
|
||||||
// AfterShutdownDelayDuration (delayedStopCh) preShutdownHooksHasStoppedCh
|
// AfterShutdownDelayDuration (delayedStopCh) PreShutdownHooksStopped (preShutdownHooksHasStoppedCh)
|
||||||
// | |
|
// | |
|
||||||
// |---------------------------------- |
|
// |---------------------------------- |
|
||||||
// | | |
|
// | | |
|
||||||
@ -504,12 +504,13 @@ func (s preparedGenericAPIServer) Run(stopCh <-chan struct{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// pre-shutdown hooks need to finish before we stop the http server
|
// pre-shutdown hooks need to finish before we stop the http server
|
||||||
preShutdownHooksHasStoppedCh, stopHttpServerCh := make(chan struct{}), make(chan struct{})
|
preShutdownHooksHasStoppedCh := s.lifecycleSignals.PreShutdownHooksStopped
|
||||||
|
stopHttpServerCh := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
defer close(stopHttpServerCh)
|
defer close(stopHttpServerCh)
|
||||||
|
|
||||||
<-delayedStopOrDrainedCh
|
<-delayedStopOrDrainedCh
|
||||||
<-preShutdownHooksHasStoppedCh
|
<-preShutdownHooksHasStoppedCh.Signaled()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
stoppedCh, listenerStoppedCh, err := s.NonBlockingRun(stopHttpServerCh, shutdownTimeout)
|
stoppedCh, listenerStoppedCh, err := s.NonBlockingRun(stopHttpServerCh, shutdownTimeout)
|
||||||
@ -540,7 +541,10 @@ func (s preparedGenericAPIServer) Run(stopCh <-chan struct{}) error {
|
|||||||
// run shutdown hooks directly. This includes deregistering from
|
// run shutdown hooks directly. This includes deregistering from
|
||||||
// the kubernetes endpoint in case of kube-apiserver.
|
// the kubernetes endpoint in case of kube-apiserver.
|
||||||
func() {
|
func() {
|
||||||
defer close(preShutdownHooksHasStoppedCh)
|
defer func() {
|
||||||
|
preShutdownHooksHasStoppedCh.Signal()
|
||||||
|
klog.V(1).InfoS("[graceful-termination] pre-shutdown hooks completed", "name", preShutdownHooksHasStoppedCh.Name())
|
||||||
|
}()
|
||||||
err = s.RunPreShutdownHooks()
|
err = s.RunPreShutdownHooks()
|
||||||
}()
|
}()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -120,6 +120,10 @@ type lifecycleSignals struct {
|
|||||||
// ShutdownDelayDuration allows the apiserver to delay shutdown for some time.
|
// ShutdownDelayDuration allows the apiserver to delay shutdown for some time.
|
||||||
AfterShutdownDelayDuration lifecycleSignal
|
AfterShutdownDelayDuration lifecycleSignal
|
||||||
|
|
||||||
|
// PreShutdownHooksStopped event is signaled when all registered
|
||||||
|
// preshutdown hook(s) have finished running.
|
||||||
|
PreShutdownHooksStopped lifecycleSignal
|
||||||
|
|
||||||
// InFlightRequestsDrained event is signaled when the existing requests
|
// InFlightRequestsDrained event is signaled when the existing requests
|
||||||
// in flight have completed. This is used as signal to shut down the audit backends
|
// in flight have completed. This is used as signal to shut down the audit backends
|
||||||
InFlightRequestsDrained lifecycleSignal
|
InFlightRequestsDrained lifecycleSignal
|
||||||
@ -143,6 +147,7 @@ func newLifecycleSignals() lifecycleSignals {
|
|||||||
return lifecycleSignals{
|
return lifecycleSignals{
|
||||||
ShutdownInitiated: newNamedChannelWrapper("ShutdownInitiated"),
|
ShutdownInitiated: newNamedChannelWrapper("ShutdownInitiated"),
|
||||||
AfterShutdownDelayDuration: newNamedChannelWrapper("AfterShutdownDelayDuration"),
|
AfterShutdownDelayDuration: newNamedChannelWrapper("AfterShutdownDelayDuration"),
|
||||||
|
PreShutdownHooksStopped: newNamedChannelWrapper("PreShutdownHooksStopped"),
|
||||||
InFlightRequestsDrained: newNamedChannelWrapper("InFlightRequestsDrained"),
|
InFlightRequestsDrained: newNamedChannelWrapper("InFlightRequestsDrained"),
|
||||||
HTTPServerStoppedListening: newNamedChannelWrapper("HTTPServerStoppedListening"),
|
HTTPServerStoppedListening: newNamedChannelWrapper("HTTPServerStoppedListening"),
|
||||||
HasBeenReady: newNamedChannelWrapper("HasBeenReady"),
|
HasBeenReady: newNamedChannelWrapper("HasBeenReady"),
|
||||||
|
Loading…
Reference in New Issue
Block a user