1
0
Fork 0
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:
Charles-Edouard Brétéché 2022-09-30 16:13:29 +02:00 committed by GitHub
parent 9aca37fe9f
commit ac8f4ba59c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View file

@ -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")
}

View file

@ -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()