mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
chore: add error logs in wait for cache sync helper (#6275)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
3541473092
commit
a5eed7834e
3 changed files with 21 additions and 13 deletions
|
@ -155,7 +155,7 @@ func main() {
|
|||
cleanup.Workers,
|
||||
)
|
||||
// start informers and wait for cache sync
|
||||
if !internal.StartInformersAndWaitForCacheSync(ctx, kyvernoInformer, kubeInformer, kubeKyvernoInformer) {
|
||||
if !internal.StartInformersAndWaitForCacheSync(ctx, logger, kyvernoInformer, kubeInformer, kubeKyvernoInformer) {
|
||||
logger.Error(errors.New("failed to wait for cache sync"), "failed to wait for cache sync")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ func main() {
|
|||
polLister := kyvernoInformer.Kyverno().V2alpha1().CleanupPolicies().Lister()
|
||||
nsLister := kubeInformer.Core().V1().Namespaces().Lister()
|
||||
// start informers and wait for cache sync
|
||||
if !internal.StartInformersAndWaitForCacheSync(ctx, kubeKyvernoInformer, kubeInformer, kyvernoInformer) {
|
||||
if !internal.StartInformersAndWaitForCacheSync(ctx, logger, kubeKyvernoInformer, kubeInformer, kyvernoInformer) {
|
||||
os.Exit(1)
|
||||
}
|
||||
// create handlers
|
||||
|
|
|
@ -3,6 +3,8 @@ package internal
|
|||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
)
|
||||
|
||||
type startable interface {
|
||||
|
@ -20,25 +22,31 @@ func StartInformers[T startable](ctx context.Context, informers ...T) {
|
|||
}
|
||||
}
|
||||
|
||||
func WaitForCacheSync(ctx context.Context, informers ...informer) bool {
|
||||
func WaitForCacheSync(ctx context.Context, logger logr.Logger, informers ...informer) bool {
|
||||
ret := true
|
||||
for i := range informers {
|
||||
for _, result := range informers[i].WaitForCacheSync(ctx.Done()) {
|
||||
for t, result := range informers[i].WaitForCacheSync(ctx.Done()) {
|
||||
if !result {
|
||||
logger.Error(nil, "failed to wait for cache sync", "type", t)
|
||||
}
|
||||
ret = ret && result
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func CheckCacheSync[T comparable](status map[T]bool) bool {
|
||||
func CheckCacheSync[T comparable](logger logr.Logger, status map[T]bool) bool {
|
||||
ret := true
|
||||
for _, s := range status {
|
||||
ret = ret && s
|
||||
for t, result := range status {
|
||||
if !result {
|
||||
logger.Error(nil, "failed to wait for cache sync", "type", t)
|
||||
}
|
||||
ret = ret && result
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func StartInformersAndWaitForCacheSync(ctx context.Context, informers ...informer) bool {
|
||||
func StartInformersAndWaitForCacheSync(ctx context.Context, logger logr.Logger, informers ...informer) bool {
|
||||
StartInformers(ctx, informers...)
|
||||
return WaitForCacheSync(ctx, informers...)
|
||||
return WaitForCacheSync(ctx, logger, informers...)
|
||||
}
|
||||
|
|
|
@ -550,7 +550,7 @@ func main() {
|
|||
configMapResolver,
|
||||
)
|
||||
// start informers and wait for cache sync
|
||||
if !internal.StartInformersAndWaitForCacheSync(signalCtx, kyvernoInformer, kubeInformer, kubeKyvernoInformer, cacheInformer) {
|
||||
if !internal.StartInformersAndWaitForCacheSync(signalCtx, logger, kyvernoInformer, kubeInformer, kubeKyvernoInformer, cacheInformer) {
|
||||
logger.Error(errors.New("failed to wait for cache sync"), "failed to wait for cache sync")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
@ -615,12 +615,12 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
// start informers and wait for cache sync
|
||||
if !internal.StartInformersAndWaitForCacheSync(signalCtx, kyvernoInformer, kubeInformer, kubeKyvernoInformer) {
|
||||
if !internal.StartInformersAndWaitForCacheSync(signalCtx, logger, kyvernoInformer, kubeInformer, kubeKyvernoInformer) {
|
||||
logger.Error(errors.New("failed to wait for cache sync"), "failed to wait for cache sync")
|
||||
os.Exit(1)
|
||||
}
|
||||
internal.StartInformers(signalCtx, metadataInformer)
|
||||
if !internal.CheckCacheSync(metadataInformer.WaitForCacheSync(signalCtx.Done())) {
|
||||
if !internal.CheckCacheSync(logger, metadataInformer.WaitForCacheSync(signalCtx.Done())) {
|
||||
// TODO: shall we just exit ?
|
||||
logger.Error(errors.New("failed to wait for cache sync"), "failed to wait for cache sync")
|
||||
}
|
||||
|
@ -719,7 +719,7 @@ func main() {
|
|||
)
|
||||
// start informers and wait for cache sync
|
||||
// we need to call start again because we potentially registered new informers
|
||||
if !internal.StartInformersAndWaitForCacheSync(signalCtx, kyvernoInformer, kubeInformer, kubeKyvernoInformer, cacheInformer) {
|
||||
if !internal.StartInformersAndWaitForCacheSync(signalCtx, logger, kyvernoInformer, kubeInformer, kubeKyvernoInformer, cacheInformer) {
|
||||
logger.Error(errors.New("failed to wait for cache sync"), "failed to wait for cache sync")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue