Repository navigation
Description
Bug Report
What did you do?
We attempted to record a Kubernetes event for our primary/main resource from within the reconciliation loop of a sub-resource / secondary controller, following the v5.6 release notes:
https://javaoperatorsdk.io/blog/2026/09/02/version-5.6-released/#kubernetes-event-recorder
According to the release documentation:
"Outside of the reconciliation loop — from a status listener or a background task, or about an object other than the primary — use the unbound form from
RegisteredController#eventRecorder(), which is scoped to the controller rather than to a reconciliation:EventRecorder recorder = registeredController.eventRecorder(); recorder.record(someOtherResource, EventRecord.normal("Noticed", "something happened"));
What did you expect to see?
RegisteredControllerexposes aneventRecorder()method (or equivalent API) to obtain an unboundEventRecorder.EventRecorderprovides a way to record events for an arbitrary target resource (e.g.recorder.record(someOtherResource, EventRecord.normal(...))), allowing a controller reconciling a sub-resource to emit an event on its main/parent resource.
What did you see instead? Under which circumstances?
RegisteredControllerdoes not containeventRecorder(). CallingregisteredController.eventRecorder()fails to compile.- In
Context<P>,eventRecorder()returns aResourceEventRecorderstrictly bound tocontext.getPrimaryResource(). - In
DefaultEventRecorder,toEvent(...)hardcodes the target resource tocontext.getPrimaryResource():var regarding = context.getPrimaryResource(); and EventRecorder#record only accepts (EventRecord event, Context<?> context).
As a result, when reconciling a sub-resource (where context.getPrimaryResource() is the sub-resource), there is no supported way to publish an event targeting the main/parent resource.
Environment
Kubernetes cluster type: any
java-operator-sdk version: 5.6.3
java -version: 17 / 21
kubectl version: 1.30+
Possible Solution
Tracing through the PR history:
- PR feat: Add Event Recorder #3570 (feat: Add Event Recorder) originally introduced RegisteredController#eventRecorder() and supported recording events for arbitrary objects.
- PR refactor: configurable event recorder #3581 (refactor: configurable event recorder) refactored the API to be stateless and removed RegisteredController#eventRecorder(), inadvertently dropping the ability to record events outside a reconciliation context or targeting a resource other than context.getPrimaryResource().
Suggested fixes:
- Re-introduce an unbound EventRecorder accessible via RegisteredController, ConfigurationService, or Operator.
- Allow passing an explicit target HasMetadata targetResource (or via EventRecord / EventRecorder#record(targetResource, ...)), rather than exclusively binding to context.getPrimaryResource().
Additional context
Our use case: We have separate controllers reconciling sub-resources. When state changes or failures occur during the reconciliation of a sub-resource, we need to publish a Kubernetes event targeting the main/parent resource so users inspecting the parent resource (kubectl describe ) have visibility into events triggered by its sub-resources.
Activity
csviri commentedon Nov 10, 2026
Hi @bertdw-1985 , thx for raising this, that is a issue with the blog, attached a PR to fix that. At the end we decided to do it this way, since the event coming from a controller bounded to the primary resource is the behavior that we would normally see, we can take a look and extend this.
csviri commentedon Nov 10, 2026
cc @afalhambra-hivemq
afalhambra-hivemq commentedon Nov 11, 2026
@csviri @bertdw-1985 I'm working on this on top of
next: recording events about any object, not only the primary (so a child controller can record on its parent), and recording outside of a reconciliation through the registered controller. Existingcontext.eventRecorder()usage stays as is. PR soon