...

Source file src/k8s.io/kube-aggregator/pkg/controllers/cache.go

Documentation: k8s.io/kube-aggregator/pkg/controllers

     1  /*
     2  Copyright 2017 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package controllers
    18  
    19  import (
    20  	"fmt"
    21  
    22  	"k8s.io/klog/v2"
    23  
    24  	utilruntime "k8s.io/apimachinery/pkg/util/runtime"
    25  	"k8s.io/client-go/tools/cache"
    26  )
    27  
    28  // WaitForCacheSync is a wrapper around cache.WaitForCacheSync that generates log messages
    29  // indicating that the controller identified by controllerName is waiting for syncs, followed by
    30  // either a successful or failed sync.
    31  func WaitForCacheSync(controllerName string, stopCh <-chan struct{}, cacheSyncs ...cache.InformerSynced) bool {
    32  	klog.Infof("Waiting for caches to sync for %s controller", controllerName)
    33  
    34  	if !cache.WaitForCacheSync(stopCh, cacheSyncs...) {
    35  		utilruntime.HandleError(fmt.Errorf("Unable to sync caches for %s controller", controllerName))
    36  		return false
    37  	}
    38  
    39  	klog.Infof("Caches are synced for %s controller", controllerName)
    40  	return true
    41  }
    42  

View as plain text