From 0399a296386622425605d69ed27adcc60c519e0f Mon Sep 17 00:00:00 2001 From: Angelo Poerio Date: Tue, 30 Nov 2021 12:57:01 +0100 Subject: [PATCH] avoid logging at the error level the errors involving CRD, but do it anyway at debug level --- pkg/kube/watcher.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/kube/watcher.go b/pkg/kube/watcher.go index 7ef0fc04..7ed8395e 100644 --- a/pkg/kube/watcher.go +++ b/pkg/kube/watcher.go @@ -33,7 +33,7 @@ func NewEventWatcher(config *rest.Config, namespace string, throttlePeriod int64 labelCache: NewLabelCache(config), annotationCache: NewAnnotationCache(config), fn: fn, - throttlePeriod: time.Second*time.Duration(throttlePeriod), + throttlePeriod: time.Second * time.Duration(throttlePeriod), } informer.AddEventHandler(watcher) @@ -72,7 +72,11 @@ func (e *EventWatcher) onEvent(event *corev1.Event) { labels, err := e.labelCache.GetLabelsWithCache(&event.InvolvedObject) if err != nil { - log.Error().Err(err).Msg("Cannot list labels of the object") + if ev.InvolvedObject.Kind != "CustomResourceDefinition" { + log.Error().Err(err).Msg("Cannot list labels of the object") + } else { + log.Debug().Err(err).Msg("Cannot list labels of the object (CRD)") + } // Ignoring error, but log it anyways } else { ev.InvolvedObject.Labels = labels @@ -81,7 +85,11 @@ func (e *EventWatcher) onEvent(event *corev1.Event) { annotations, err := e.annotationCache.GetAnnotationsWithCache(&event.InvolvedObject) if err != nil { - log.Error().Err(err).Msg("Cannot list annotations of the object") + if ev.InvolvedObject.Kind != "CustomResourceDefinition" { + log.Error().Err(err).Msg("Cannot list annotations of the object") + } else { + log.Debug().Err(err).Msg("Cannot list annotations of the object (CRD)") + } } else { ev.InvolvedObject.Annotations = annotations ev.InvolvedObject.ObjectReference = *event.InvolvedObject.DeepCopy()