@@ -51,9 +51,9 @@ type Provider struct {
51
51
evtClient corev1client.EventInterface
52
52
makeBroadcaster EventBroadcasterProducer
53
53
54
- broadcasterOnce sync.Once
55
- broadcaster events.EventBroadcaster
56
- stopCh chan struct {}
54
+ broadcasterOnce sync.Once
55
+ broadcaster events.EventBroadcaster
56
+ cancelSinkRecordingFunc context. CancelFunc
57
57
// Deprecated: will be removed in a future release. Use the broadcaster above instead.
58
58
deprecatedBroadcaster record.EventBroadcaster
59
59
stopBroadcaster bool
@@ -81,7 +81,7 @@ func (p *Provider) Stop(shutdownCtx context.Context) {
81
81
if p .stopBroadcaster {
82
82
p .lock .Lock ()
83
83
broadcaster .Shutdown ()
84
- close ( p . stopCh )
84
+ p . cancelSinkRecordingFunc ( )
85
85
deprecatedBroadcaster .Shutdown ()
86
86
p .stopped = true
87
87
p .lock .Unlock ()
@@ -115,14 +115,18 @@ func (p *Provider) getBroadcaster() (record.EventBroadcaster, events.EventBroadc
115
115
})
116
116
117
117
// init new broadcaster
118
- p .stopCh = make (chan struct {})
119
- p .broadcaster .StartRecordingToSink (p .stopCh )
120
- _ , _ = p .broadcaster .StartEventWatcher (func (event runtime.Object ) {
118
+ ctx , cancel := context .WithCancel (context .Background ())
119
+ p .cancelSinkRecordingFunc = cancel
120
+ p .broadcaster .StartRecordingToSinkWithContext (ctx )
121
+ _ , err := p .broadcaster .StartEventWatcher (func (event runtime.Object ) {
121
122
e , isEvt := event .(* eventsv1.Event )
122
123
if isEvt {
123
124
p .logger .V (1 ).Info (e .Note , "type" , e .Type , "object" , e .Related , "action" , e .Action , "reason" , e .Reason )
124
125
}
125
126
})
127
+ if err != nil {
128
+ p .logger .Error (err , "error starting event watcher for broadcaster" )
129
+ }
126
130
})
127
131
128
132
return p .deprecatedBroadcaster , p .broadcaster
@@ -190,6 +194,7 @@ func (l *lazyRecorder) Eventf(regarding runtime.Object, related runtime.Object,
190
194
}
191
195
192
196
// deprecatedRecorder implements the old events API during the tranisiton and will be removed in a future release.
197
+ //
193
198
// Deprecated: will be removed in a future release.
194
199
type deprecatedRecorder struct {
195
200
prov * Provider
0 commit comments