1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00
kyverno/pkg/informers/helpers.go

34 lines
866 B
Go
Raw Normal View History

package informers
import (
"context"
"github.com/go-logr/logr"
"k8s.io/client-go/tools/cache"
)
type informer interface {
Informer() cache.SharedIndexInformer
}
func StartInformers(ctx context.Context, informers ...informer) {
for i := range informers {
go func(informer cache.SharedIndexInformer) {
informer.Run(ctx.Done())
}(informers[i].Informer())
}
}
func WaitForCacheSync(ctx context.Context, logger logr.Logger, informers ...informer) bool {
var cacheSyncs []cache.InformerSynced
for i := range informers {
cacheSyncs = append(cacheSyncs, informers[i].Informer().HasSynced)
}
return cache.WaitForCacheSync(ctx.Done(), cacheSyncs...)
}
func StartInformersAndWaitForCacheSync(ctx context.Context, logger logr.Logger, informers ...informer) bool {
StartInformers(ctx, informers...)
return WaitForCacheSync(ctx, logger, informers...)
}