mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 22:17:14 +00:00
audit backend run before http server start and register presShutdown hook
This commit is contained in:
parent
6f06408eea
commit
b96613722f
@ -266,6 +266,14 @@ func (s *GenericAPIServer) PrepareRun() preparedGenericAPIServer {
|
|||||||
// Run spawns the secure http server. It only returns if stopCh is closed
|
// Run spawns the secure http server. It only returns if stopCh is closed
|
||||||
// or the secure port cannot be listened on initially.
|
// or the secure port cannot be listened on initially.
|
||||||
func (s preparedGenericAPIServer) Run(stopCh <-chan struct{}) error {
|
func (s preparedGenericAPIServer) Run(stopCh <-chan struct{}) error {
|
||||||
|
// Register audit backend preShutdownHook.
|
||||||
|
if s.AuditBackend != nil {
|
||||||
|
s.AddPreShutdownHook("audit-backend", func() error {
|
||||||
|
s.AuditBackend.Shutdown()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
err := s.NonBlockingRun(stopCh)
|
err := s.NonBlockingRun(stopCh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -273,16 +281,20 @@ func (s preparedGenericAPIServer) Run(stopCh <-chan struct{}) error {
|
|||||||
|
|
||||||
<-stopCh
|
<-stopCh
|
||||||
|
|
||||||
if s.GenericAPIServer.AuditBackend != nil {
|
|
||||||
s.GenericAPIServer.AuditBackend.Shutdown()
|
|
||||||
}
|
|
||||||
|
|
||||||
return s.RunPreShutdownHooks()
|
return s.RunPreShutdownHooks()
|
||||||
}
|
}
|
||||||
|
|
||||||
// NonBlockingRun spawns the secure http server. An error is
|
// NonBlockingRun spawns the secure http server. An error is
|
||||||
// returned if the secure port cannot be listened on.
|
// returned if the secure port cannot be listened on.
|
||||||
func (s preparedGenericAPIServer) NonBlockingRun(stopCh <-chan struct{}) error {
|
func (s preparedGenericAPIServer) NonBlockingRun(stopCh <-chan struct{}) error {
|
||||||
|
// Start the audit backend before any request comes in. This means we must call Backend.Run
|
||||||
|
// before http server start serving. Otherwise the Backend.ProcessEvents call might block.
|
||||||
|
if s.AuditBackend != nil {
|
||||||
|
if err := s.AuditBackend.Run(stopCh); err != nil {
|
||||||
|
return fmt.Errorf("failed to run the audit backend: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 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{})
|
||||||
|
|
||||||
@ -301,14 +313,6 @@ func (s preparedGenericAPIServer) NonBlockingRun(stopCh <-chan struct{}) error {
|
|||||||
close(internalStopCh)
|
close(internalStopCh)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Start the audit backend before any request comes in. This means we cannot turn it into a
|
|
||||||
// post start hook because without calling Backend.Run the Backend.ProcessEvents call might block.
|
|
||||||
if s.AuditBackend != nil {
|
|
||||||
if err := s.AuditBackend.Run(stopCh); err != nil {
|
|
||||||
return fmt.Errorf("failed to run the audit backend: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
s.RunPostStartHooks(stopCh)
|
s.RunPostStartHooks(stopCh)
|
||||||
|
|
||||||
if _, err := systemd.SdNotify(true, "READY=1\n"); err != nil {
|
if _, err := systemd.SdNotify(true, "READY=1\n"); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user