1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-30 19:35:06 +00:00

split sync cache

This commit is contained in:
shivkumar dudhani 2019-10-25 18:49:26 -05:00
parent 0bb3d74498
commit c119f0d34b
2 changed files with 13 additions and 14 deletions

View file

@ -96,10 +96,8 @@ func main() {
// dyamically load the configuration from configMap
// - resource filters
// if the configMap is update, the configuration will be updated :D
configData, err := config.NewConfigData(clientConfig, kubeInformer.Core().V1().ConfigMaps(), stopCh)
if err != nil {
glog.Fatalf("error loading dynamic configuration: %v", err)
}
configData := config.NewConfigData(kubeClient, kubeInformer.Core().V1().ConfigMaps())
// EVENT GENERATOR
// - generate event with retry mechanism
egen := event.NewEventGenerator(client, pInformer.Kyverno().V1alpha1().ClusterPolicies())
@ -155,6 +153,9 @@ func main() {
// Start the components
pInformer.Start(stopCh)
kubeInformer.Start(stopCh)
if err := configData.Run(kubeInformer.Core().V1().ConfigMaps(), stopCh); err != nil {
glog.Fatalf("Unable loading dynamic configuration: %v\n", err)
}
go pc.Run(1, stopCh)
go pvc.Run(1, stopCh)
go egen.Run(1, stopCh)

View file

@ -13,7 +13,6 @@ import (
v1 "k8s.io/api/core/v1"
informers "k8s.io/client-go/informers/core/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
)
@ -50,18 +49,13 @@ type Interface interface {
}
// NewConfigData ...
func NewConfigData(restconfig *rest.Config, cmInformer informers.ConfigMapInformer, stopCh <-chan struct{}) (*ConfigData, error) {
// get the client
kclient, err := kubernetes.NewForConfig(restconfig)
if err != nil {
return nil, err
}
func NewConfigData(rclient kubernetes.Interface, cmInformer informers.ConfigMapInformer) *ConfigData {
// environment var is read at start only
if cmNameEnv == "" {
glog.Info("ConfigMap name not defined in env:INIT_CONFIG: loading no default configuration")
}
cd := ConfigData{
client: kclient,
client: rclient,
cmName: os.Getenv(cmNameEnv),
}
@ -70,11 +64,15 @@ func NewConfigData(restconfig *rest.Config, cmInformer informers.ConfigMapInform
UpdateFunc: cd.updateCM,
DeleteFunc: cd.deleteCM,
})
return &cd
}
func (cd *ConfigData) Run(cmInformer informers.ConfigMapInformer, stopCh <-chan struct{}) error {
// wait for cache to populate first time
if !cache.WaitForCacheSync(stopCh, cmInformer.Informer().HasSynced) {
return nil, fmt.Errorf("Configuration: Failed to sync informer cache")
return fmt.Errorf("Configuration: Failed to sync informer cache")
}
return &cd, nil
return nil
}
func (cd *ConfigData) addCM(obj interface{}) {