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
shuting fb9c66f455
feat(perf): add new linter prealloc to enforce slice declarations best practice (#10250)
* feat(perf): add new linter prealloc to enforce slice declarations best practice

Signed-off-by: ShutingZhao <shuting@nirmata.com>

* fix(linter): prealloac slices

Signed-off-by: ShutingZhao <shuting@nirmata.com>

---------

Signed-off-by: ShutingZhao <shuting@nirmata.com>
2024-05-20 14:46:35 +05:30

33 lines
890 B
Go

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 {
cacheSyncs := make([]cache.InformerSynced, 0, len(informers))
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...)
}