mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-15 12:17:56 +00:00
refactor: make server owner of the cleanup chan (#4765)
* refactor: make server owner of the cleanup chan Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com> * gofumpt Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com> Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
This commit is contained in:
parent
9aca37fe9f
commit
ac8f4ba59c
2 changed files with 9 additions and 6 deletions
|
@ -158,7 +158,6 @@ func main() {
|
||||||
signalCtx, signalCancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
signalCtx, signalCancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||||
defer signalCancel()
|
defer signalCancel()
|
||||||
|
|
||||||
cleanUp := make(chan struct{})
|
|
||||||
stopCh := signalCtx.Done()
|
stopCh := signalCtx.Done()
|
||||||
debug := serverIP != ""
|
debug := serverIP != ""
|
||||||
|
|
||||||
|
@ -434,7 +433,6 @@ func main() {
|
||||||
configuration,
|
configuration,
|
||||||
webhookCfg,
|
webhookCfg,
|
||||||
webhookMonitor,
|
webhookMonitor,
|
||||||
cleanUp,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// wrap all controllers that need leaderelection
|
// wrap all controllers that need leaderelection
|
||||||
|
@ -532,7 +530,7 @@ func main() {
|
||||||
|
|
||||||
// resource cleanup
|
// resource cleanup
|
||||||
// remove webhook configurations
|
// remove webhook configurations
|
||||||
<-cleanUp
|
<-server.Cleanup()
|
||||||
logger.V(2).Info("Kyverno shutdown successful")
|
logger.V(2).Info("Kyverno shutdown successful")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,8 @@ type Server interface {
|
||||||
Run(<-chan struct{})
|
Run(<-chan struct{})
|
||||||
// Stop TLS server and returns control after the server is shut down
|
// Stop TLS server and returns control after the server is shut down
|
||||||
Stop(context.Context)
|
Stop(context.Context)
|
||||||
|
// Cleanup returns the chanel used to wait for the server to clean up resources
|
||||||
|
Cleanup() <-chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type PolicyHandlers interface {
|
type PolicyHandlers interface {
|
||||||
|
@ -45,7 +47,7 @@ type ResourceHandlers interface {
|
||||||
type server struct {
|
type server struct {
|
||||||
server *http.Server
|
server *http.Server
|
||||||
webhookRegister *webhookconfig.Register
|
webhookRegister *webhookconfig.Register
|
||||||
cleanUp chan<- struct{}
|
cleanUp chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type TlsProvider func() ([]byte, []byte, error)
|
type TlsProvider func() ([]byte, []byte, error)
|
||||||
|
@ -58,7 +60,6 @@ func NewServer(
|
||||||
configuration config.Configuration,
|
configuration config.Configuration,
|
||||||
register *webhookconfig.Register,
|
register *webhookconfig.Register,
|
||||||
monitor *webhookconfig.Monitor,
|
monitor *webhookconfig.Monitor,
|
||||||
cleanUp chan<- struct{},
|
|
||||||
) Server {
|
) Server {
|
||||||
mux := httprouter.New()
|
mux := httprouter.New()
|
||||||
resourceLogger := logger.WithName("resource")
|
resourceLogger := logger.WithName("resource")
|
||||||
|
@ -94,7 +95,7 @@ func NewServer(
|
||||||
ReadHeaderTimeout: 30 * time.Second,
|
ReadHeaderTimeout: 30 * time.Second,
|
||||||
},
|
},
|
||||||
webhookRegister: register,
|
webhookRegister: register,
|
||||||
cleanUp: cleanUp,
|
cleanUp: make(chan struct{}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,6 +121,10 @@ func (s *server) Stop(ctx context.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *server) Cleanup() <-chan struct{} {
|
||||||
|
return s.cleanUp
|
||||||
|
}
|
||||||
|
|
||||||
func (s *server) cleanup(ctx context.Context) {
|
func (s *server) cleanup(ctx context.Context) {
|
||||||
cleanupKyvernoResource := s.webhookRegister.ShouldCleanupKyvernoResource()
|
cleanupKyvernoResource := s.webhookRegister.ShouldCleanupKyvernoResource()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue