Skip to content

Migrate events generation to new interface#4678

Merged
weyfonk merged 3 commits into
rancher:mainfrom
weyfonk:migrate-events
Mar 11, 2026
Merged

Migrate events generation to new interface#4678
weyfonk merged 3 commits into
rancher:mainfrom
weyfonk:migrate-events

Conversation

@weyfonk
Copy link
Copy Markdown
Contributor

@weyfonk weyfonk commented Feb 19, 2026

With GetEentRecorderFor being deprecated, controllers now use the new GetEventRecorder method, returning an events.EventRecorder instead of a record.EventRecorder interface.

Fixes linter failures such as these.

Refers to: #4765

Copilot AI review requested due to automatic review settings February 19, 2026 09:33
@weyfonk weyfonk requested a review from a team as a code owner February 19, 2026 09:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(...) to mgr.GetEventRecorder(...) and update reconciler Recorder fields to events.EventRecorder.
  • Update controller code paths that emit events to use the events.EventRecorder.Eventf(...) signature (including the new action parameter).
  • Regenerate/update mocks and adjust unit/integration tests to use tools/events fake 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.

Comment thread internal/cmd/controller/gitops/reconciler/gitjob_controller.go Outdated
Comment thread internal/cmd/controller/helmops/reconciler/polling_job.go Outdated
Comment thread internal/cmd/controller/helmops/reconciler/polling_job.go
Comment thread internal/cmd/controller/gitops/reconciler/polling_job.go Outdated
Comment thread internal/cmd/controller/gitops/reconciler/polling_job.go
@kkaempf kkaempf added this to Fleet Feb 19, 2026
@kkaempf kkaempf moved this to 👀 In review in Fleet Feb 19, 2026
@kkaempf kkaempf added this to the v2.14.0 milestone Feb 19, 2026
@weyfonk weyfonk force-pushed the migrate-events branch 2 times, most recently from 56afc4d to c3a3b4a Compare February 19, 2026 14:56
@weyfonk weyfonk modified the milestones: v2.14.0, v2.14.1 Mar 6, 2026
weyfonk added 3 commits March 11, 2026 17:37
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 weyfonk merged commit 9e62cd7 into rancher:main Mar 11, 2026
22 checks passed
@github-project-automation github-project-automation Bot moved this from 👀 In review to ✅ Done in Fleet Mar 11, 2026
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
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants