@@ -27,6 +27,7 @@ import (
27
27
eventsv1client "k8s.io/client-go/kubernetes/typed/events/v1"
28
28
"k8s.io/client-go/rest"
29
29
"k8s.io/client-go/tools/events"
30
+ "k8s.io/client-go/tools/record"
30
31
)
31
32
32
33
// EventBroadcasterProducer makes an event broadcaster, returning
@@ -136,6 +137,17 @@ func (p *Provider) GetEventRecorder(name string) events.EventRecorder {
136
137
}
137
138
}
138
139
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
+
139
151
// lazyRecorder is a recorder that doesn't actually instantiate any underlying
140
152
// recorder until the first event is emitted.
141
153
type lazyRecorder struct {
@@ -163,3 +175,22 @@ func (l *lazyRecorder) Eventf(regarding runtime.Object, related runtime.Object,
163
175
}
164
176
l .prov .lock .RUnlock ()
165
177
}
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