Skip to content

improve: event recorder correctness - #3665

Open
csviri wants to merge 1 commit into
nextfrom
fix/event-recorder-correctness
Open

csviri wants to merge 1 commit into
nextfrom
fix/event-recorder-correctness

Conversation

@csviri

@csviri csviri commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Correctness fixes of the event recorder, found while reviewing the virtual thread support PR (#3664) and extracted from it.

1. Aggregating onto a named event updates its type, reason and action

Events with the same explicit name are aggregated onto the recorded one, but only the count, the last timestamp and the message were updated, so a Warning repeated under the name of a Normal event kept the Normal type and reason. The type, reason and action are updated too now.

The API server treats them as immutable for an event that carries an eventTime. Recording an event that differs in them onto such an event is therefore rejected with an IllegalStateException explaining that distinct event names have to be used, instead of failing on the patch with an API server error.

2. Long supplied names stay distinct

A supplied event name longer than the Kubernetes limit was plainly truncated, so distinct names sharing a long prefix were merged into the same event. They are now shortened with a hash of the full name, as the names the recorder generates itself already are.

3. Events about cluster scoped resources in an overridden namespace are accepted by the API server

The API server only accepts an event without eventTime about a cluster scoped object if it lives in the default namespace. Events about cluster scoped resources in an overridden namespace now carry an eventTime (in the fixed width MicroTime format the API server requires) and an action, which defaults to the reason. Events in the default namespace are unchanged.

Tests

  • EventRecorderRegressionTest:
    • long supplied names sharing a prefix stay distinct
    • the event of a cluster scoped resource in an overridden namespace is accepted by the core API, and unchanged in the default namespace
    • aggregating onto a named event keeps the type and reason of the first occurrence
    • aggregating onto an event with an eventTime rejects changed immutable fields
  • DefaultEventRecorderTest is adapted to the shortened names.

…namespace

- aggregating onto an event with an explicit name also updates type, reason and
  action, and rejects a change of them when the event carries an eventTime, which
  the API server treats as immutable
- supplied names longer than the Kubernetes limit are shortened with a hash of the
  full name instead of plainly truncated, so distinct names stay distinct
- events about cluster scoped resources in an overridden namespace carry an
  eventTime (and an action), as the API server refuses them otherwise
@openshift-ci openshift-ci Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 27, 2026
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bf4983db-cb3d-41b4-8686-33fe73333b80

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@csviri
csviri changed the base branch from main to next October 27, 2026 17:07
@csviri
csviri requested a balanced review from Copilot October 30, 2026 13:40
@csviri
csviri marked this pull request as ready for review October 30, 2026 13:40
@openshift-ci openshift-ci Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 30, 2026
@openshift-ci
openshift-ci Bot requested review from metacosm and xstefank October 30, 2026 13:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Event handling can drop records that differ only by action or retain stale actions, and namespace-override behavior lacks core-API integration coverage.

3 open issues
What changed in this PR

This PR extracts event-recorder correctness fixes from the virtual-thread work in #3664, improving how the SDK names, aggregates, and namespaces Kubernetes events.

Changes:

  • Updates type, reason, and supplied action during aggregation, with checks for immutable fields.
  • Hashes oversized supplied names to keep names with shared prefixes distinct.
  • Adds eventTime and a default action for cluster-scoped events in overridden namespaces, with regression coverage.
File Description
operator-framework-core/​src/​test/​java/​io/​javaoperatorsdk/​operator/​api/​event/​EventRecorderRegressionTest.java Adds regression tests for naming, aggregation, and namespace overrides.
operator-framework-core/​src/​test/​java/​io/​javaoperatorsdk/​operator/​api/​event/​DefaultEventRecorderTest.java Updates shortened-name expectations and tests shared-prefix names.
operator-framework-core/​src/​main/​java/​io/​javaoperatorsdk/​operator/​api/​event/​DefaultEventSink.java Updates aggregated fields and rejects immutable-field conflicts.
operator-framework-core/​src/​main/​java/​io/​javaoperatorsdk/​operator/​api/​event/​DefaultEventRecorder.java Adds hash-based name shortening and conditional event timestamps and actions.

Review effort: Balanced

Comment on lines +269 to +273
if (requiresEventTime(regarding, namespace)) {
builder.withEventTime(new MicroTime(EVENT_TIME_FORMAT.format(Instant.now())));
if (record.action().isEmpty()) {
builder.withAction(record.reason());
}
Comment on lines +64 to +65
if (existing.getEventTime() != null && differsInImmutableFields(existing, event)) {
throw new IllegalStateException(
Comment on lines +78 to +80
if (event.getAction() != null) {
builder.withAction(event.getAction());
}

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants