mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-15 17:51:20 +00:00
9b1860a4e5
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
37 lines
785 B
Go
37 lines
785 B
Go
package internal
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
|
|
"github.com/go-logr/logr"
|
|
"github.com/kyverno/kyverno/pkg/controllers"
|
|
)
|
|
|
|
type Controller interface {
|
|
Run(context.Context, logr.Logger, *sync.WaitGroup)
|
|
}
|
|
|
|
type controller struct {
|
|
name string
|
|
controller controllers.Controller
|
|
workers int
|
|
}
|
|
|
|
func NewController(name string, c controllers.Controller, w int) Controller {
|
|
return controller{
|
|
name: name,
|
|
controller: c,
|
|
workers: w,
|
|
}
|
|
}
|
|
|
|
func (c controller) Run(ctx context.Context, logger logr.Logger, wg *sync.WaitGroup) {
|
|
wg.Add(1)
|
|
go func(logger logr.Logger) {
|
|
logger.Info("starting controller", "workers", c.workers)
|
|
defer logger.Info("controller stopped")
|
|
defer wg.Done()
|
|
c.controller.Run(ctx, c.workers)
|
|
}(logger.WithValues("name", c.name))
|
|
}
|