Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.

avoid logging at the error level the errors involving CRD #168

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions pkg/kube/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down