Skip to content

Commit ab24452

Browse files
authored
Merge pull request #829 from orange-cloudfoundry/feature-namespace-restricted-option
Add filter functions to event recorder
2 parents f5f608c + 61bc9ed commit ab24452

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

pkg/event/event.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,26 @@ type Recorder interface {
7979
type APIRecorder struct {
8080
kube record.EventRecorder
8181
annotations map[string]string
82+
filterFns []FilterFn
8283
}
8384

85+
// FilterFn is a function used to filter events.
86+
// It should return false when events should not be sent.
87+
type FilterFn func(obj runtime.Object, e Event) bool
88+
8489
// NewAPIRecorder returns an APIRecorder that records Kubernetes events to an
8590
// APIServer using the supplied EventRecorder.
86-
func NewAPIRecorder(r record.EventRecorder) *APIRecorder {
87-
return &APIRecorder{kube: r, annotations: map[string]string{}}
91+
func NewAPIRecorder(r record.EventRecorder, fns ...FilterFn) *APIRecorder {
92+
return &APIRecorder{kube: r, annotations: map[string]string{}, filterFns: fns}
8893
}
8994

9095
// Event records the supplied event.
9196
func (r *APIRecorder) Event(obj runtime.Object, e Event) {
97+
for _, filter := range r.filterFns {
98+
if filter(obj, e) {
99+
return
100+
}
101+
}
92102
r.kube.AnnotatedEventf(obj, r.annotations, string(e.Type), string(e.Reason), "%s", e.Message)
93103
}
94104

0 commit comments

Comments
 (0)