@@ -27,6 +27,7 @@ import (
2727 eventsv1client "k8s.io/client-go/kubernetes/typed/events/v1"
2828 "k8s.io/client-go/rest"
2929 "k8s.io/client-go/tools/events"
30+ "k8s.io/client-go/tools/record"
3031)
3132
3233// EventBroadcasterProducer makes an event broadcaster, returning
@@ -136,6 +137,17 @@ func (p *Provider) GetEventRecorder(name string) events.EventRecorder {
136137 }
137138}
138139
140+ // GetOldEventRecorder returns an event recorder that broadcasts to this provider's
141+ // broadcaster. All events will be associated with a component of the given name.
142+ func (p * Provider ) GetOldEventRecorder (name string ) record.EventRecorder {
143+ return & oldRecorder {
144+ newRecorder : & lazyRecorder {
145+ prov : p ,
146+ name : name ,
147+ },
148+ }
149+ }
150+
139151// lazyRecorder is a recorder that doesn't actually instantiate any underlying
140152// recorder until the first event is emitted.
141153type lazyRecorder struct {
@@ -163,3 +175,22 @@ func (l *lazyRecorder) Eventf(regarding runtime.Object, related runtime.Object,
163175 }
164176 l .prov .lock .RUnlock ()
165177}
178+
179+ // oldRecorder is a wrapper around the events.EventRecorder that implements the old record.EventRecorder API.
180+ // This is a temporary solution to support both the old and new events APIs without duplicating everything.
181+ // Internally it calls the new events API from the old API funcs and no longer supported parameters are ignored (e.g. annotations).
182+ type oldRecorder struct {
183+ newRecorder * lazyRecorder
184+ }
185+
186+ func (l * oldRecorder ) Event (object runtime.Object , eventtype , reason , message string ) {
187+ l .newRecorder .Eventf (object , nil , eventtype , reason , "unsupported" , message )
188+ }
189+
190+ func (l * oldRecorder ) Eventf (object runtime.Object , eventtype , reason , messageFmt string , args ... interface {}) {
191+ l .newRecorder .Eventf (object , nil , eventtype , reason , "unsupported" , messageFmt , args ... )
192+ }
193+
194+ func (l * oldRecorder ) AnnotatedEventf (object runtime.Object , annotations map [string ]string , eventtype , reason , messageFmt string , args ... interface {}) {
195+ l .newRecorder .Eventf (object , nil , eventtype , reason , "unsupported" , messageFmt , args ... )
196+ }
0 commit comments