@@ -20,13 +20,14 @@ type EventWatcher struct {
2020 informer cache.SharedInformer
2121 stopper chan struct {}
2222 labelCache * LabelCache
23+ omitLookup bool
2324 annotationCache * AnnotationCache
2425 fn EventHandler
2526 maxEventAgeSeconds time.Duration
2627 metricsStore * metrics.Store
2728}
2829
29- func NewEventWatcher (config * rest.Config , namespace string , MaxEventAgeSeconds int64 , metricsStore * metrics.Store , fn EventHandler ) * EventWatcher {
30+ func NewEventWatcher (config * rest.Config , namespace string , MaxEventAgeSeconds int64 , metricsStore * metrics.Store , fn EventHandler , omitLookup bool ) * EventWatcher {
3031 clientset := kubernetes .NewForConfigOrDie (config )
3132 factory := informers .NewSharedInformerFactoryWithOptions (clientset , 0 , informers .WithNamespace (namespace ))
3233 informer := factory .Core ().V1 ().Events ().Informer ()
@@ -35,6 +36,7 @@ func NewEventWatcher(config *rest.Config, namespace string, MaxEventAgeSeconds i
3536 informer : informer ,
3637 stopper : make (chan struct {}),
3738 labelCache : NewLabelCache (config ),
39+ omitLookup : omitLookup ,
3840 annotationCache : NewAnnotationCache (config ),
3941 fn : fn ,
4042 maxEventAgeSeconds : time .Second * time .Duration (MaxEventAgeSeconds ),
@@ -100,29 +102,33 @@ func (e *EventWatcher) onEvent(event *corev1.Event) {
100102 }
101103 ev .Event .ManagedFields = nil
102104
103- labels , err := e .labelCache .GetLabelsWithCache (& event .InvolvedObject )
104- if err != nil {
105- if ev .InvolvedObject .Kind != "CustomResourceDefinition" {
106- log .Error ().Err (err ).Msg ("Cannot list labels of the object" )
105+ if e .omitLookup {
106+ ev .InvolvedObject .ObjectReference = * event .InvolvedObject .DeepCopy ()
107+ } else {
108+ labels , err := e .labelCache .GetLabelsWithCache (& event .InvolvedObject )
109+ if err != nil {
110+ if ev .InvolvedObject .Kind != "CustomResourceDefinition" {
111+ log .Error ().Err (err ).Msg ("Cannot list labels of the object" )
112+ } else {
113+ log .Debug ().Err (err ).Msg ("Cannot list labels of the object (CRD)" )
114+ }
115+ // Ignoring error, but log it anyways
107116 } else {
108- log .Debug ().Err (err ).Msg ("Cannot list labels of the object (CRD)" )
117+ ev .InvolvedObject .Labels = labels
118+ ev .InvolvedObject .ObjectReference = * event .InvolvedObject .DeepCopy ()
109119 }
110- // Ignoring error, but log it anyways
111- } else {
112- ev .InvolvedObject .Labels = labels
113- ev .InvolvedObject .ObjectReference = * event .InvolvedObject .DeepCopy ()
114- }
115120
116- annotations , err := e .annotationCache .GetAnnotationsWithCache (& event .InvolvedObject )
117- if err != nil {
118- if ev .InvolvedObject .Kind != "CustomResourceDefinition" {
119- log .Error ().Err (err ).Msg ("Cannot list annotations of the object" )
121+ annotations , err := e .annotationCache .GetAnnotationsWithCache (& event .InvolvedObject )
122+ if err != nil {
123+ if ev .InvolvedObject .Kind != "CustomResourceDefinition" {
124+ log .Error ().Err (err ).Msg ("Cannot list annotations of the object" )
125+ } else {
126+ log .Debug ().Err (err ).Msg ("Cannot list annotations of the object (CRD)" )
127+ }
120128 } else {
121- log .Debug ().Err (err ).Msg ("Cannot list annotations of the object (CRD)" )
129+ ev .InvolvedObject .Annotations = annotations
130+ ev .InvolvedObject .ObjectReference = * event .InvolvedObject .DeepCopy ()
122131 }
123- } else {
124- ev .InvolvedObject .Annotations = annotations
125- ev .InvolvedObject .ObjectReference = * event .InvolvedObject .DeepCopy ()
126132 }
127133
128134 e .fn (ev )
0 commit comments