Cannot record events outside reconciliation loop or for arbitrary resources (`RegisteredController#eventRecorder` missing)

未关闭
#3,686 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@afalhambra-hivemq 已经在做这个了。

开始于 2026年11月11日。

  • #3689 来自 @csviri —— 已合并

评估

难度
4/5
预计耗时
3-5 天
新手友好度
54/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java

调研方向

Read the v5.6 event recorder release notes and trace the API changes described for PRs #3570 and #3581, then inspect RegisteredController, Context, and DefaultEventRecorder. Confirm how recording is currently scoped to the primary resource and where an unbound recorder or explicit target resource could fit; done means events can be recorded outside reconciliation and targeted at a parent resource from a sub-resource controller.

由索引模型根据 Issue 内容生成。

描述

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?
  1. RegisteredController exposes an eventRecorder() method (or equivalent API) to obtain an unbound EventRecorder.
  2. EventRecorder provides 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?
  1. RegisteredController does not contain eventRecorder(). Calling registeredController.eventRecorder() fails to compile.
  2. In Context<P>, eventRecorder() returns a ResourceEventRecorder strictly bound to context.getPrimaryResource().
  3. In DefaultEventRecorder, toEvent(...) hardcodes the target resource to context.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 #3570 (feat: Add Event Recorder) originally introduced RegisteredController#eventRecorder() and supported recording events for arbitrary objects.
  • PR #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:
  1. Re-introduce an unbound EventRecorder accessible via RegisteredController, ConfigurationService, or Operator.
  2. 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.

主要语言
Java
星标
945
派生
247
平均合并
2 天 10 小时
30 天内合并 PR
27

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

operator-framework/java-operator-sdk 的其他 Issue

查看 operator-framework/java-operator-sdk 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。