88
99 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1010 "k8s.io/apimachinery/pkg/runtime/schema"
11- "k8s.io/client-go/tools/record "
11+ "k8s.io/client-go/tools/events "
1212 controller_runtime "sigs.k8s.io/controller-runtime"
1313 "sigs.k8s.io/controller-runtime/pkg/builder"
1414 "sigs.k8s.io/controller-runtime/pkg/client"
@@ -29,7 +29,7 @@ type LeaseWatcher struct {
2929 client.Client
3030 GVK schema.GroupVersionKind
3131 Tracker * util.NamespaceTracker
32- Recorder record .EventRecorder
32+ Recorder events .EventRecorder
3333 eventChan chan util.NamespaceChangeEvent
3434 Annotations Annotations
3535 Metrics * ometrics.LeaseMetrics
@@ -188,7 +188,7 @@ func (r *LeaseWatcher) cleanupLeaseAnnotations(ctx context.Context, obj *unstruc
188188 obj .SetAnnotations (anns )
189189 _ = r .Patch (ctx , obj , client .MergeFrom (base ))
190190 if r .Recorder != nil {
191- r .Recorder .Event (obj , "Normal" , "LeaseAnnotationsCleaned" , "Removed lease annotations because TTL is missing" )
191+ r .Recorder .Eventf (obj , nil , "Normal" , "LeaseAnnotationsCleaned " , "LeaseAnnotationsCleaned" , "Removed lease annotations because TTL is missing" )
192192 }
193193}
194194
@@ -202,15 +202,15 @@ func (r *LeaseWatcher) ensureLeaseStart(ctx context.Context, obj *unstructured.U
202202 anns [r .Annotations .LeaseStart ] = now .Format (time .RFC3339 )
203203 r .updateAnnotations (ctx , obj , map [string ]string {r .Annotations .LeaseStart : anns [r .Annotations .LeaseStart ]})
204204 if r .Recorder != nil {
205- r .Recorder .Event (obj , "Warning" , "LeaseStartReset" , "Invalid lease-start, reset to now" )
205+ r .Recorder .Eventf (obj , nil , "Warning" , "LeaseStartReset " , "LeaseStartReset" , "Invalid lease-start, reset to now" )
206206 }
207207 return now
208208 }
209209 // missing, set
210210 anns [r .Annotations .LeaseStart ] = now .Format (time .RFC3339 )
211211 r .updateAnnotations (ctx , obj , map [string ]string {r .Annotations .LeaseStart : anns [r .Annotations .LeaseStart ]})
212212 if r .Recorder != nil {
213- r .Recorder .Event (obj , "Normal" , "LeaseStarted" , "Lease started" )
213+ r .Recorder .Eventf (obj , nil , "Normal" , "LeaseStarted " , "LeaseStarted" , "Lease started" )
214214 }
215215 if r .Metrics != nil {
216216 r .Metrics .LeasesStarted .Inc ()
@@ -222,7 +222,7 @@ func (r *LeaseWatcher) markInvalidTTL(ctx context.Context, obj *unstructured.Uns
222222 msg := fmt .Sprintf ("Invalid TTL: %v" , parseErr )
223223 r .updateAnnotations (ctx , obj , map [string ]string {r .Annotations .Status : msg })
224224 if r .Recorder != nil {
225- r .Recorder .Event (obj , "Warning" , "InvalidTTL" , msg )
225+ r .Recorder .Eventf (obj , nil , "Warning" , "InvalidTTL" , "InvalidTTL" , "%s " , msg )
226226 }
227227 if r .Metrics != nil {
228228 r .Metrics .InvalidTTL .Inc ()
@@ -238,7 +238,7 @@ func (r *LeaseWatcher) handleExpired(ctx context.Context, obj *unstructured.Unst
238238 r .Annotations .Status : leaseStatus ,
239239 })
240240 if r .Recorder != nil {
241- r .Recorder .Event (obj , "Normal" , "LeaseExpired" , leaseStatus )
241+ r .Recorder .Eventf (obj , nil , "Normal" , "LeaseExpired" , "LeaseExpired" , "%s " , leaseStatus )
242242 }
243243 if r .Metrics != nil {
244244 r .Metrics .LeasesExpired .Inc ()
@@ -262,14 +262,14 @@ func (r *LeaseWatcher) handleExpired(ctx context.Context, obj *unstructured.Unst
262262 // Invalid configuration - log error, emit event, proceed with deletion
263263 log .Error (err , "Invalid cleanup job configuration" )
264264 if r .Recorder != nil {
265- r .Recorder .Event (obj , "Warning" , "CleanupJobConfigInvalid" , fmt . Sprintf ( " Invalid cleanup job config: %v" , err ) )
265+ r .Recorder .Eventf (obj , nil , "Warning" , "CleanupJobConfigInvalid" , "CleanupJobConfigInvalid" , " Invalid cleanup job config: %v" , err )
266266 }
267267 } else if config != nil {
268268 // Cleanup job is configured - attempt to create and optionally wait
269269 if err := r .executeCleanupJob (ctx , obj , config , expireAt ); err != nil {
270270 log .Error (err , "Cleanup job execution failed" )
271271 if r .Recorder != nil {
272- r .Recorder .Event (obj , "Warning" , "CleanupJobFailed" , fmt . Sprintf ( " Cleanup job failed: %v" , err ) )
272+ r .Recorder .Eventf (obj , nil , "Warning" , "CleanupJobFailed" , "CleanupJobFailed" , " Cleanup job failed: %v" , err )
273273 }
274274 if r .Metrics != nil {
275275 r .Metrics .CleanupJobsFailed .Inc ()
@@ -305,7 +305,7 @@ func (r *LeaseWatcher) executeCleanupJob(ctx context.Context, obj *unstructured.
305305
306306 log .Info ("Cleanup job created" , "job" , job .Name , "namespace" , job .Namespace )
307307 if r .Recorder != nil {
308- r .Recorder .Event (obj , "Normal" , "CleanupJobCreated" , fmt . Sprintf ( " Created cleanup job: %s" , job .Name ) )
308+ r .Recorder .Eventf (obj , nil , "Normal" , "CleanupJobCreated" , "CleanupJobCreated" , " Created cleanup job: %s" , job .Name )
309309 }
310310 if r .Metrics != nil {
311311 r .Metrics .CleanupJobsCreated .Inc ()
@@ -317,15 +317,15 @@ func (r *LeaseWatcher) executeCleanupJob(ctx context.Context, obj *unstructured.
317317 if err := util .WaitForJobCompletion (ctx , r .Client , job , config .Timeout ); err != nil {
318318 // Job failed or timed out
319319 if r .Recorder != nil {
320- r .Recorder .Event (obj , "Warning" , "CleanupJobTimeout" , fmt . Sprintf ( " Cleanup job did not complete: %v" , err ) )
320+ r .Recorder .Eventf (obj , nil , "Warning" , "CleanupJobTimeout" , "CleanupJobTimeout" , " Cleanup job did not complete: %v" , err )
321321 }
322322 return fmt .Errorf ("cleanup job did not complete: %w" , err )
323323 }
324324
325325 // Job completed successfully
326326 log .Info ("Cleanup job completed successfully" , "job" , job .Name )
327327 if r .Recorder != nil {
328- r .Recorder .Event (obj , "Normal" , "CleanupJobCompleted" , fmt . Sprintf ( " Cleanup job completed: %s" , job .Name ) )
328+ r .Recorder .Eventf (obj , nil , "Normal" , "CleanupJobCompleted" , "CleanupJobCompleted" , " Cleanup job completed: %s" , job .Name )
329329 }
330330 if r .Metrics != nil {
331331 r .Metrics .CleanupJobsCompleted .Inc ()
0 commit comments