From 7ee6383729a69cb350b8b44c2a42c96a353b5eca Mon Sep 17 00:00:00 2001 From: Yassine TIJANI Date: Fri, 16 Aug 2019 21:15:53 +0200 Subject: [PATCH] move WaitForCacheSync to the sharedInformer package Signed-off-by: Yassine TIJANI Kubernetes-commit: 7e4c3096fe71afc6a23c273b3309ed5db7289d8c --- examples/workqueue/main.go | 2 +- tools/cache/shared_informer.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/examples/workqueue/main.go b/examples/workqueue/main.go index c306aaae..6cfa4ecd 100644 --- a/examples/workqueue/main.go +++ b/examples/workqueue/main.go @@ -23,7 +23,7 @@ import ( "k8s.io/klog" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/util/runtime" diff --git a/tools/cache/shared_informer.go b/tools/cache/shared_informer.go index 351c85b9..c37423b6 100644 --- a/tools/cache/shared_informer.go +++ b/tools/cache/shared_informer.go @@ -190,8 +190,24 @@ const ( initialBufferSize = 1024 ) +// WaitForNamedCacheSync is a wrapper around WaitForCacheSync that generates log messages +// indicating that the caller identified by name is waiting for syncs, followed by +// either a successful or failed sync. +func WaitForNamedCacheSync(controllerName string, stopCh <-chan struct{}, cacheSyncs ...InformerSynced) bool { + klog.Infof("Waiting for caches to sync for %s", controllerName) + + if !WaitForCacheSync(stopCh, cacheSyncs...) { + utilruntime.HandleError(fmt.Errorf("unable to sync caches for %s", controllerName)) + return false + } + + klog.Infof("Caches are synced for %s ", controllerName) + return true +} + // WaitForCacheSync waits for caches to populate. It returns true if it was successful, false // if the controller should shutdown +// callers should prefer WaitForNamedCacheSync() func WaitForCacheSync(stopCh <-chan struct{}, cacheSyncs ...InformerSynced) bool { err := wait.PollUntil(syncedPollPeriod, func() (bool, error) {