Skip to content

⚠️ Migration to the new events API #3262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

clebs
Copy link
Contributor

@clebs clebs commented Jul 22, 2025

This Pull Request migrates from the old events API (k8s.io/client-go/tools/record) to the new API (k8s.io/client-go/tools/events).

Closes #2141

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 22, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: clebs
Once this PR has been reviewed and has the lgtm label, please assign joelanford for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 22, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @clebs. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 22, 2025
@clebs
Copy link
Contributor Author

clebs commented Jul 22, 2025

Open Items:

  • StartRecordingToSink: manage the context/channel in the provider on ensureRecording and Stop.
  • StartWatcher: see if this is still needed and how to adapt it if it is.
  • Leader election: resourcelock.ResourceLockConfig is still using the old API.
    This has now been solved by adding an adapter that turns old API calls into new API calls (albeit pretty simplistic). So that way on the backend we have only the new API and places that require the old can use the adapter.
  • Update unit tests.

@clebs clebs changed the title ⚠ Migration to the new events API ⚠️ Migration to the new events API Jul 22, 2025
@alvaroaleman
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 22, 2025
@k8s-ci-robot
Copy link
Contributor

@clebs: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-controller-runtime-test 54f66ac link true /test pull-controller-runtime-test
pull-controller-runtime-apidiff 54f66ac link false /test pull-controller-runtime-apidiff

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Copy link
Member

@alvaroaleman alvaroaleman left a comment

Choose a reason for hiding this comment

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

two questions

"k8s.io/client-go/tools/record"
)

// Provider knows how to generate new event recorders with given name.
type Provider interface {
// NewRecorder returns an EventRecorder with given name.
GetEventRecorderFor(name string) record.EventRecorder
GetEventRecorder(name string) events.EventRecorder
Copy link
Member

Choose a reason for hiding this comment

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

Why rename this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was suggested by Stefan here #2141 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

I think that suggestion was to aid in making this a non-breaking change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I interpreted it as a general suggestion, my bad. I will revert that change.

Copy link
Member

Choose a reason for hiding this comment

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

Ah yeah. I only meant if we introduce another func, might as well improve the name

GetEventRecorder(name string) events.EventRecorder
// GetOldEventRecorder returns an EventRecorder for the old events API.
// The old API is not 100% supported anymore, use the new one whenever possible.
GetOldEventRecorder(name string) record.EventRecorder
Copy link
Member

Choose a reason for hiding this comment

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

Rather than extending the interface here, would it be possible to build a wrapper that makes a record.EventRecorder out of a events.EventRecorder?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is already built as a wrapper under the hood in intrec. I added it here with the idea to support both APIs for some time. If it is not what we are going for, having the wrapper only where it is needed is better.

Copy link
Member

@alvaroaleman alvaroaleman Jul 23, 2025

Choose a reason for hiding this comment

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

I think there are two main ways we could go about this:

  1. We make this a non-breaking change by keeping the existing GetEventRecorderFor with the existing signature and add a new GetEventRecorder with the new events.EventRecorder as return but mark the GetEventRecorderFor as // deprecated. At some point in a future release we will then remove GetEventRecorderFor
  2. We make this a breaking change by changing the signature of the existing GetEventRecorderFor to return an events.EventRecorder and we provide an adapter somewhere to go from events.EventRecorder to a record.EventRecorder for places like the leader election

My vote if this is possible would be to do 1) as this is the least disruptive for c-r users but its possible I've missed something and it isn't possible

Copy link
Contributor Author

@clebs clebs Jul 24, 2025

Choose a reason for hiding this comment

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

Option 1 is doable, but I have to see if the wrapper approach is good enough. Reason being, that the wrapper calls the new API under the hood and both APIs are quite different. The old API has AnnotatedEventf while the new one does not and the new one has things like relatedObject and action.

Otherwise, the other way to support both is having 2 distinct implementations in separate packages and duplicate the broadcaster, provider, interfaces and injection at the manager and cluster levels.
Finally also duplicate the tests so both versions are covered.

I will test if the wrapper is viable, present the results and then we can make an informed decision.

clebs added 2 commits July 24, 2025 15:14
The StartEventWatcher call is no longer needed since calling
StartRecordingToSink already sets up a watcher and manages it via its context.

Signed-off-by: Borja Clemente <[email protected]>
Signed-off-by: Borja Clemente <[email protected]>
}
l.prov.lock.RUnlock()
func (l *oldRecorder) Event(object runtime.Object, eventtype, reason, message string) {
l.newRecorder.Eventf(object, nil, eventtype, reason, "unsupported", message)
Copy link
Contributor

@valdar valdar Jul 25, 2025

Choose a reason for hiding this comment

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

I think here a less "intimidating" wording could be used? like "no action" instead of "unsupported" maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to me, will change it.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 29, 2025
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch to use events.EventRecorder instead of record.EventRecorder
5 participants