mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +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)
|
||||
defer signalCancel()
|
||||
|
||||
cleanUp := make(chan struct{})
|
||||
stopCh := signalCtx.Done()
|
||||
debug := serverIP != ""
|
||||
|
||||
|
@ -434,7 +433,6 @@ func main() {
|
|||
configuration,
|
||||
webhookCfg,
|
||||
webhookMonitor,
|
||||
cleanUp,
|
||||
)
|
||||
|
||||
// wrap all controllers that need leaderelection
|
||||
|
@ -532,7 +530,7 @@ func main() {
|
|||
|
||||
// resource cleanup
|
||||
// remove webhook configurations
|
||||
<-cleanUp
|
||||
<-server.Cleanup()
|
||||
logger.V(2).Info("Kyverno shutdown successful")
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@ type Server interface {
|
|||
Run(<-chan struct{})
|
||||
// Stop TLS server and returns control after the server is shut down
|
||||
Stop(context.Context)
|
||||
// Cleanup returns the chanel used to wait for the server to clean up resources
|
||||
Cleanup() <-chan struct{}
|
||||
}
|
||||
|
||||
type PolicyHandlers interface {
|
||||
|
@ -45,7 +47,7 @@ type ResourceHandlers interface {
|
|||
type server struct {
|
||||
server *http.Server
|
||||
webhookRegister *webhookconfig.Register
|
||||
cleanUp chan<- struct{}
|
||||
cleanUp chan struct{}
|
||||
}
|
||||
|
||||
type TlsProvider func() ([]byte, []byte, error)
|
||||
|
@ -58,7 +60,6 @@ func NewServer(
|
|||
configuration config.Configuration,
|
||||
register *webhookconfig.Register,
|
||||
monitor *webhookconfig.Monitor,
|
||||
cleanUp chan<- struct{},
|
||||
) Server {
|
||||
mux := httprouter.New()
|
||||
resourceLogger := logger.WithName("resource")
|
||||
|
@ -94,7 +95,7 @@ func NewServer(
|
|||
ReadHeaderTimeout: 30 * time.Second,
|
||||
},
|
||||
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) {
|
||||
cleanupKyvernoResource := s.webhookRegister.ShouldCleanupKyvernoResource()
|
||||
|
||||
|
|
Loading…
Reference in a new issue