1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-15 17:51:20 +00:00
kyverno/cmd/internal/controller.go
Charles-Edouard Brétéché 9b1860a4e5
refactor: add controller helper to internal package (#5506)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2022-11-30 11:13:57 +00:00

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