Skip to content

⚠️ Add AnnotatedEventRecorderProvider interface - #3509

Merged
kubernetes-prow[bot] merged 2 commits into
kubernetes-sigs:mainfrom
adri1197:annotations-event-recorder
Jun 26, 2026
Merged

kubernetes-prow[bot] merged 2 commits into
kubernetes-sigs:mainfrom
adri1197:annotations-event-recorder

Conversation

@adri1197

Copy link
Copy Markdown
Contributor

Adds support for creating event recorders that can attach custom annotations to events,
mirroring the AnnotatedEventf capability recently added to client-go/tools/events
(see kubernetes/kubernetes#138103).

This introduces a new AnnotatedEventRecorderProvider interface in pkg/recorder rather
than adding a method to the existing Provider interface, so this is a backwards-compatible
change. Consumers can type-assert the manager/cluster to access the new functionality:

if p, ok := mgr.(recorder.AnnotatedEventRecorderProvider); ok {
    rec := p.GetAnnotatedEventRecorder("my-controller")
    rec.AnnotatedEventf(obj, nil, map[string]string{"key": "value"}, corev1.EventTypeNormal, "Reason", "Action", "Note")
}

Changes:

  • Added AnnotatedEventRecorderProvider interface in pkg/recorder
  • Implemented GetAnnotatedEventRecorder on the internal recorder Provider
  • Implemented AnnotatedEventf on lazyRecorder
  • Added GetAnnotatedEventRecorder on cluster and controllerManager (concrete types only, no interface changes)
  • Added unit and integration tests

@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 Apr 27, 2026
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

Welcome @adri1197!

It looks like this is your first PR to kubernetes-sigs/controller-runtime 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/controller-runtime has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 27, 2026
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

Hi @adri1197. 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.

Details

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 size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 27, 2026
@adri1197
adri1197 force-pushed the annotations-event-recorder branch from 2e5cff1 to 56f611b Compare May 9, 2026 12:26

@matheuscscp matheuscscp left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM 🙌

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

@matheuscscp: changing LGTM is restricted to collaborators

Details

In response to this:

LGTM 🙌

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

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

Details 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

@sbueringer

Copy link
Copy Markdown
Member

@adri1197 We just bumped to v1.37 alpha, so I think this PR can be rebased and moved out of draft

@sbueringer

Copy link
Copy Markdown
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 Jun 13, 2026
@adri1197
adri1197 force-pushed the annotations-event-recorder branch from 56f611b to 4a38bfc Compare June 13, 2026 09:04
@adri1197

Copy link
Copy Markdown
Contributor Author

@adri1197 We just bumped to v1.37 alpha, so I think this PR can be rebased and moved out of draft

@sbueringer since you mentioned this can be rebased and moved out of draft now that we're on v1.37 alpha — would it be acceptable to add the method directly to the Provider interface as a breaking change for the next minor (given controller-runtime's v0.x semver policy allows breaking changes between minors)? Or should we stick with the separate? interface approach from the PR description to keep it non-breaking?

@adri1197
adri1197 marked this pull request as ready for review June 13, 2026 09:18
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 13, 2026
Comment thread pkg/cluster/internal.go Outdated
return c.recorderProvider.GetEventRecorder(name)
}

func (c *cluster) GetAnnotatedEventRecorder(name string) events.AnnotatedEventRecorder {

@sbueringer sbueringer Jun 18, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm wondering if we should really have an additional Get*EventRecorder method instead of just combining both "new" event recorder in an interface in controller-runtime.

I think this is an acceptable breaking change either way

I assume it's easier to use if we just have one method / one recorder. Because folks then don't have to get and pass around two different recorders if they want to use both methods.

@alvaroaleman Do you have an opinion on this?

Context: The old upstream EventRecorder had Event / Eventf / AnnotatedEventf methods. The new API has one interface each for Eventf / AnnotatedEventf

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Agreed!

@adri1197 adri1197 Jun 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Friendly ping @sbueringer @alvaroaleman 👋 — the rework combining both into a single recorder.EventRecorder interface (per @sbueringer's suggestion) has been pushed.

Would you have a chance to take another look?

Thanks! 😃

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thx! I'll try to take a look soon, probably tomorrow

@sbueringer

sbueringer commented Jun 18, 2026 •

Copy link
Copy Markdown
Member

@adri1197 We just bumped to v1.37 alpha, so I think this PR can be rebased and moved out of draft

@sbueringer since you mentioned this can be rebased and moved out of draft now that we're on v1.37 alpha — would it be acceptable to add the method directly to the Provider interface as a breaking change for the next minor (given controller-runtime's v0.x semver policy allows breaking changes between minors)? Or should we stick with the separate? interface approach from the PR description to keep it non-breaking?

Sorry just saw this message now. This is the same point I'm bringing up #3509 (comment), right?

EDIT: Ah I think it's a slightly different point

@adri1197

adri1197 commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor Author

@adri1197 We just bumped to v1.37 alpha, so I think this PR can be rebased and moved out of draft

@sbueringer since you mentioned this can be rebased and moved out of draft now that we're on v1.37 alpha — would it be acceptable to add the method directly to the Provider interface as a breaking change for the next minor (given controller-runtime's v0.x semver policy allows breaking changes between minors)? Or should we stick with the separate? interface approach from the PR description to keep it non-breaking?

Sorry just saw this message now. This is the same point I'm bringing up #3509 (comment), right?

EDIT: Ah I think it's a slightly different point

No really, it's exactly the answer that I wanted to get 😃. I had some doubts about having different Recorders (well, Providers) per interface.

I've reworked this to combine both into a single recorder.EventRecorder interface that embeds events.EventRecorder + events.AnnotatedEventRecorder. So now GetEventRecorder returns one recorder that does both - no separate method needed. Will push shortly 😄.

adri1197 added 2 commits June 19, 2026 13:39
Add the missing AnnotatedEventf as
a new interface AnnotatedEventRecorder
under cluster, manager, and recorder provider

Signed-off-by: Adrian Fernandez De La Torre <adri1197@gmail.com>
…face

Replace separate GetEventRecorder and GetAnnotatedEventRecorder methods
with a single GetEventRecorder that returns a combined recorder.EventRecorder
interface embedding both events.EventRecorder and events.AnnotatedEventRecorder.

This lets callers use one recorder for both Eventf and AnnotatedEventf
without needing to obtain and pass around two separate recorders.

Signed-off-by: Adrian Fernandez De La Torre <adri1197@gmail.com>
@adri1197
adri1197 force-pushed the annotations-event-recorder branch from a4c69c4 to 588f17a Compare June 19, 2026 11:43
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

@adri1197: The following test 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-apidiff 588f17a 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.

Details

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.

@adri1197
adri1197 requested a review from sbueringer June 22, 2026 14:29
@sbueringer sbueringer added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Jun 26, 2026
@sbueringer

Copy link
Copy Markdown
Member

Thank you very much!!

/lgtm

/assign @alvaroaleman

@kubernetes-prow kubernetes-prow Bot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 26, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

LGTM label has been added.

DetailsGit tree hash: 1d5558c23aedb563ba9492e9b704027b644c5d8f

@alvaroaleman alvaroaleman changed the title ✨ Add AnnotatedEventRecorderProvider interface :warn: Add AnnotatedEventRecorderProvider interface Jun 26, 2026
@alvaroaleman alvaroaleman changed the title :warn: Add AnnotatedEventRecorderProvider interface ⚠️ Add AnnotatedEventRecorderProvider interface Jun 26, 2026
@alvaroaleman

Copy link
Copy Markdown
Member

Marked the change as breaking since it changes the interface, but otherwise lgtm, thank you
/hold cancel

@alvaroaleman

Copy link
Copy Markdown
Member

/approve

@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adri1197, alvaroaleman, matheuscscp

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

The pull request process is described here

Details 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

@kubernetes-prow kubernetes-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 26, 2026
@kubernetes-prow
kubernetes-prow Bot merged commit b2719fd into kubernetes-sigs:main Jun 26, 2026
17 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants