diff --git a/pkg/internal/recorder/recorder.go b/pkg/internal/recorder/recorder.go index 21f0146ba3..4efbd46d99 100644 --- a/pkg/internal/recorder/recorder.go +++ b/pkg/internal/recorder/recorder.go @@ -152,30 +152,29 @@ func (l *lazyRecorder) ensureRecording() { }) } -func (l *lazyRecorder) Event(object runtime.Object, eventtype, reason, message string) { +func (l *lazyRecorder) executeWithLock(eventF func()) { l.ensureRecording() - l.prov.lock.RLock() + defer l.prov.lock.RUnlock() if !l.prov.stopped { - l.rec.Event(object, eventtype, reason, message) + eventF() } - l.prov.lock.RUnlock() } -func (l *lazyRecorder) Eventf(object runtime.Object, eventtype, reason, messageFmt string, args ...interface{}) { - l.ensureRecording() - l.prov.lock.RLock() - if !l.prov.stopped { +func (l *lazyRecorder) Event(object runtime.Object, eventtype, reason, message string) { + l.executeWithLock(func() { + l.rec.Event(object, eventtype, reason, message) + }) +} + +func (l *lazyRecorder) Eventf(object runtime.Object, eventtype, reason, messageFmt string, args ...interface{}) { + l.executeWithLock(func() { l.rec.Eventf(object, eventtype, reason, messageFmt, args...) - } - l.prov.lock.RUnlock() + }) } -func (l *lazyRecorder) AnnotatedEventf(object runtime.Object, annotations map[string]string, eventtype, reason, messageFmt string, args ...interface{}) { - l.ensureRecording() - l.prov.lock.RLock() - if !l.prov.stopped { +func (l *lazyRecorder) AnnotatedEventf(object runtime.Object, annotations map[string]string, eventtype, reason, messageFmt string, args ...interface{}) { + l.executeWithLock(func() { l.rec.AnnotatedEventf(object, annotations, eventtype, reason, messageFmt, args...) - } - l.prov.lock.RUnlock() + }) }