Skip to content

Commit

Permalink
MINOR: add aditional logging on informers
Browse files Browse the repository at this point in the history
  • Loading branch information
oktalz committed Mar 18, 2024
1 parent 496f4e5 commit a19ada4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/k8s/crs-monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func (k k8s) runCRDefinitionsInformer(eventChan chan GroupKind, stop chan struct

factory := apiextensionsinformers.NewSharedInformerFactoryWithOptions(k.apiExtensionsClient, k.cacheResyncPeriod)
informer := factory.Apiextensions().V1().CustomResourceDefinitions().Informer()
errW := informer.SetWatchErrorHandler(func(r *cache.Reflector, err error) {
go logger.Debug("CRD Definitions informer error: %s", err)
})
logger.Error(errW)
_, err := informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
crd := obj.(*apiextensionsv1.CustomResourceDefinition)
Expand Down
12 changes: 12 additions & 0 deletions pkg/k8s/crs.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ func (c GlobalCR) GetInformer(eventChan chan SyncDataEvent, factory informers.Sh
eventChan <- SyncDataEvent{SyncType: SyncType(c.GetKind()), Namespace: data.GetNamespace(), Name: data.GetName(), Data: data}
}

errW := informer.SetWatchErrorHandler(func(r *cache.Reflector, err error) {
go logger.Debug("Global CR informer error: %s", err)
})
logger.Error(errW)
_, err := informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
sendToChannel(eventChan, obj, store.ADDED)
Expand Down Expand Up @@ -97,6 +101,10 @@ func (c DefaultsCR) GetInformer(eventChan chan SyncDataEvent, factory informers.
eventChan <- SyncDataEvent{SyncType: SyncType(c.GetKind()), Namespace: data.GetNamespace(), Name: data.GetName(), Data: data}
}

errW := informer.SetWatchErrorHandler(func(r *cache.Reflector, err error) {
go logger.Debug("Defaults CR informer error: %s", err)
})
logger.Error(errW)
_, err := informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
sendToChannel(eventChan, obj, store.ADDED)
Expand Down Expand Up @@ -133,6 +141,10 @@ func (c BackendCR) GetInformer(eventChan chan SyncDataEvent, factory informers.S
eventChan <- SyncDataEvent{SyncType: SyncType(c.GetKind()), Namespace: data.GetNamespace(), Name: data.GetName(), Data: data}
}

errW := informer.SetWatchErrorHandler(func(r *cache.Reflector, err error) {
go logger.Debug("Backend CR informer error: %s", err)
})
logger.Error(errW)
_, err := informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
sendToChannel(eventChan, obj, store.ADDED)
Expand Down
32 changes: 32 additions & 0 deletions pkg/k8s/informers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ import (

func (k k8s) getNamespaceInfomer(eventChan chan SyncDataEvent, factory informers.SharedInformerFactory) cache.SharedIndexInformer { //nolint:ireturn
informer := factory.Core().V1().Namespaces().Informer()
errW := informer.SetWatchErrorHandler(func(r *cache.Reflector, err error) {
go logger.Debug("Namespace informer error: %s", err)
})
logger.Error(errW)
_, err := informer.AddEventHandler(
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
Expand Down Expand Up @@ -118,6 +122,10 @@ func (k k8s) getNamespaceInfomer(eventChan chan SyncDataEvent, factory informers

func (k k8s) getServiceInformer(eventChan chan SyncDataEvent, factory informers.SharedInformerFactory) cache.SharedIndexInformer { //nolint:ireturn
informer := factory.Core().V1().Services().Informer()
errW := informer.SetWatchErrorHandler(func(r *cache.Reflector, err error) {
go logger.Debug("Service informer error: %s", err)
})
logger.Error(errW)
_, err := informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
data, ok := obj.(*corev1.Service)
Expand Down Expand Up @@ -244,6 +252,10 @@ func (k k8s) getServiceInformer(eventChan chan SyncDataEvent, factory informers.

func (k k8s) getSecretInformer(eventChan chan SyncDataEvent, factory informers.SharedInformerFactory) cache.SharedIndexInformer { //nolint:ireturn
informer := factory.Core().V1().Secrets().Informer()
errW := informer.SetWatchErrorHandler(func(r *cache.Reflector, err error) {
go logger.Debug("Secret informer error: %s", err)
})
logger.Error(errW)
_, err := informer.AddEventHandler(
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
Expand Down Expand Up @@ -313,6 +325,10 @@ func (k k8s) getSecretInformer(eventChan chan SyncDataEvent, factory informers.S

func (k k8s) getConfigMapInformer(eventChan chan SyncDataEvent, factory informers.SharedInformerFactory) cache.SharedIndexInformer { //nolint:ireturn
informer := factory.Core().V1().ConfigMaps().Informer()
errW := informer.SetWatchErrorHandler(func(r *cache.Reflector, err error) {
go logger.Debug("ConfigMap informer error: %s", err)
})
logger.Error(errW)
_, err := informer.AddEventHandler(
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
Expand Down Expand Up @@ -433,6 +449,10 @@ func (k k8s) getEndpointSliceInformer(eventChan chan SyncDataEvent, factory info

func (k k8s) getEndpointsInformer(eventChan chan SyncDataEvent, factory informers.SharedInformerFactory) cache.SharedIndexInformer { //nolint:ireturn
informer := factory.Core().V1().Endpoints().Informer()
errW := informer.SetWatchErrorHandler(func(r *cache.Reflector, err error) {
go logger.Debug("Endpoints informer error: %s", err)
})
logger.Error(errW)
_, err := informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
item, err := k.convertToEndpoints(obj, store.ADDED)
Expand Down Expand Up @@ -503,6 +523,10 @@ func (k *k8s) getPodInformer(namespace, podPrefix string, resyncPeriod time.Dura
}

func (k k8s) addIngressClassHandlers(eventChan chan SyncDataEvent, informer cache.SharedIndexInformer) {
errW := informer.SetWatchErrorHandler(func(r *cache.Reflector, err error) {
go logger.Debug("IngressClass informer error: %s", err)
})
logger.Error(errW)
_, err := informer.AddEventHandler(
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
Expand Down Expand Up @@ -541,6 +565,10 @@ func (k k8s) addIngressClassHandlers(eventChan chan SyncDataEvent, informer cach
}

func (k k8s) addIngressHandlers(eventChan chan SyncDataEvent, informer cache.SharedIndexInformer) {
errW := informer.SetWatchErrorHandler(func(r *cache.Reflector, err error) {
go logger.Debug("Ingress informer error: %s", err)
})
logger.Error(errW)
_, err := informer.AddEventHandler(
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
Expand Down Expand Up @@ -579,6 +607,10 @@ func (k k8s) addIngressHandlers(eventChan chan SyncDataEvent, informer cache.Sha
}

func (k k8s) addEndpointSliceHandlers(eventChan chan SyncDataEvent, informer cache.SharedIndexInformer) {
errW := informer.SetWatchErrorHandler(func(r *cache.Reflector, err error) {
go logger.Debug("EndpoitSlice informer error: %s", err)
})
logger.Error(errW)
_, err := informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
item, err := k.convertToEndpoints(obj, store.ADDED)
Expand Down

0 comments on commit a19ada4

Please sign in to comment.