Migrate events generation to new interface#4678
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR migrates controller event generation away from the deprecated GetEventRecorderFor/tools/record interface to the newer GetEventRecorder API, using k8s.io/client-go/tools/events.EventRecorder, to address linter/deprecation issues in controller-runtime.
Changes:
- Switch controller wiring from
mgr.GetEventRecorderFor(...)tomgr.GetEventRecorder(...)and update reconcilerRecorderfields toevents.EventRecorder. - Update controller code paths that emit events to use the
events.EventRecorder.Eventf(...)signature (including the newactionparameter). - Regenerate/update mocks and adjust unit/integration tests to use
tools/eventsfake recorder + new mock interface.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/mocks/eventrecorder_mock.go | Regenerated mock to match tools/events.EventRecorder (Eventf-only interface). |
| internal/cmd/controller/reconciler/schedule_controller_test.go | Uses events.NewFakeRecorder instead of record.NewFakeRecorder. |
| internal/cmd/controller/reconciler/schedule_controller.go | Reconciler Recorder field switched to events.EventRecorder. |
| internal/cmd/controller/reconciler/bundle_controller.go | Migrates event emission to Recorder.Eventf(...) with new signature. |
| internal/cmd/controller/operator.go | Uses mgr.GetEventRecorder(...) when constructing reconcilers. |
| internal/cmd/controller/helmops/reconciler/polling_job.go | Migrates to events.EventRecorder and updates event emission to Eventf(...). |
| internal/cmd/controller/helmops/reconciler/helmop_controller.go | Reconciler Recorder field switched to events.EventRecorder. |
| internal/cmd/controller/helmops/operator.go | Uses mgr.GetEventRecorder(...). |
| internal/cmd/controller/gitops/reconciler/polling_job_test.go | Updates tests to use tools/events fake recorder type. |
| internal/cmd/controller/gitops/reconciler/polling_job.go | Migrates to events.EventRecorder and updates event emission to Eventf(...). |
| internal/cmd/controller/gitops/reconciler/gitjob_test.go | Updates mock expectations to Eventf(...) and adds mockgen directive for new interface. |
| internal/cmd/controller/gitops/reconciler/gitjob_controller.go | Migrates event emission sites to Eventf(...) with action/note. |
| internal/cmd/controller/gitops/reconciler/gitjob.go | Migrates “Created” event to Eventf(...). |
| internal/cmd/controller/gitops/operator.go | Uses mgr.GetEventRecorder(...). |
| integrationtests/helmops/controller/suite_test.go | Uses mgr.GetEventRecorder(...). |
| integrationtests/gitjob/controller/suite_test.go | Uses mgr.GetEventRecorder(...). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
56afc4d to
c3a3b4a
Compare
p-se
approved these changes
Mar 11, 2026
With `GetEentRecorderFor` being deprecated, controllers now use the new `GetEventRecorder` method, returning an `events.EventRecorder` instead of a `record.EventRecorder` interface.
When using the new event recorder interface, the recorder does not populate the source component anymore; instead, the emitter can be checked through `ReportingController`. Besides, job creation and deletion actually happen _twice_ when re-creating a job.
This should prevent events from containing malformed messages, should error messages ever contain `%` symbols.
weyfonk
added a commit
to weyfonk/fleet
that referenced
this pull request
Mar 11, 2026
* Migrate events generation to new interface With `GetEentRecorderFor` being deprecated, controllers now use the new `GetEventRecorder` method, returning an `events.EventRecorder` instead of a `record.EventRecorder` interface. * Fix expectations on source component When using the new event recorder interface, the recorder does not populate the source component anymore; instead, the emitter can be checked through `ReportingController`. Besides, job creation and deletion actually happen _twice_ when re-creating a job. * Use formatting placeholders for errors in events This should prevent events from containing malformed messages, if error messages ever contain `%` symbols.
thardeck
added a commit
that referenced
this pull request
Mar 12, 2026
Combine our CA bundle pre-fetch logic with main's event interface migration: - Get bundle first to extract stored CA bundle (implement_3845) - Pass CA bundle to getChartVersion as 4th parameter (implement_3845) - Adopt new Eventf interface with corev1.EventTypeWarning (#4678) - Update fail() to take eventAction parameter (#4678)
weyfonk
added a commit
that referenced
this pull request
Mar 12, 2026
* Migrate events generation to new interface With `GetEentRecorderFor` being deprecated, controllers now use the new `GetEventRecorder` method, returning an `events.EventRecorder` instead of a `record.EventRecorder` interface. * Fix expectations on source component When using the new event recorder interface, the recorder does not populate the source component anymore; instead, the emitter can be checked through `ReportingController`. Besides, job creation and deletion actually happen _twice_ when re-creating a job. * Use formatting placeholders for errors in events This should prevent events from containing malformed messages, if error messages ever contain `%` symbols.
thardeck
added a commit
that referenced
this pull request
Mar 19, 2026
0xavi0
pushed a commit
to 0xavi0/fleet
that referenced
this pull request
Apr 14, 2026
* Migrate events generation to new interface With `GetEentRecorderFor` being deprecated, controllers now use the new `GetEventRecorder` method, returning an `events.EventRecorder` instead of a `record.EventRecorder` interface. * Fix expectations on source component When using the new event recorder interface, the recorder does not populate the source component anymore; instead, the emitter can be checked through `ReportingController`. Besides, job creation and deletion actually happen _twice_ when re-creating a job. * Use formatting placeholders for errors in events This should prevent events from containing malformed messages, if error messages ever contain `%` symbols.
0xavi0
added a commit
that referenced
this pull request
Apr 15, 2026
* Fix event recorder interface migration (#4896) * Fix event recorder interface migration The migration from `controller-runtime`'s `record.EventRecorder` to `events.EventRecorder` seems to have changed the type of events generated, which led to permissions errors when recording events. This commit updates Fleet's gitOps RBAC to take that new event type into account. * Add regression end-to-end test for event generation Single-cluster end-to-end tests for GitRepo deployments now validate that `GotNewCommit` events are generated, which should help catch future event recording-related issues. * Migrate events generation to new interface (#4678) * Migrate events generation to new interface With `GetEentRecorderFor` being deprecated, controllers now use the new `GetEventRecorder` method, returning an `events.EventRecorder` instead of a `record.EventRecorder` interface. * Fix expectations on source component When using the new event recorder interface, the recorder does not populate the source component anymore; instead, the emitter can be checked through `ReportingController`. Besides, job creation and deletion actually happen _twice_ when re-creating a job. * Use formatting placeholders for errors in events This should prevent events from containing malformed messages, if error messages ever contain `%` symbols. --------- Co-authored-by: Corentin Néau <tan.neau@suse.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
GetEentRecorderForbeing deprecated, controllers now use the newGetEventRecordermethod, returning anevents.EventRecorderinstead of arecord.EventRecorderinterface.Fixes linter failures such as these.
Refers to: #4765