Skip to content

feat: define interface for event recorder#1985

Open
bakito wants to merge 1 commit into
projectcapsule:mainfrom
bakito:event-recorder
Open

feat: define interface for event recorder#1985
bakito wants to merge 1 commit into
projectcapsule:mainfrom
bakito:event-recorder

Conversation

@bakito

@bakito bakito commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

This PR introduces an interface for the newly introduced capsule event recorder.

Using the interface helps to hide the implementing struct from the user and allows better testing.

Copilot AI review requested due to automatic review settings June 26, 2026 16:37

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.

Pull request overview

This PR refactors the Capsule runtime event recorder to expose an EventRecorder interface (instead of a concrete struct) and keeps the implementation type unexported, aiming to hide implementation details and improve testability.

Changes:

  • Replaced the exported EventRecorder struct with an exported EventRecorder interface and introduced an unexported eventRecorder implementation.
  • Updated NewEventRecorder to return the interface type and adjusted internal receivers accordingly.
  • Updated controller wiring to pass the returned interface value (removing the previous dereference).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
pkg/runtime/events/recorder.go Introduces the exported EventRecorder interface and unexported eventRecorder implementation; updates constructor and receivers.
pkg/runtime/events/event_types.go Adjusts LabeledEvent to reference the new unexported recorder implementation and updates the LabeledEvent factory receiver.
cmd/controller/main.go Updates webhook.Register call to pass the interface returned by NewEventRecorder (no dereference).
Comments suppressed due to low confidence (1)

pkg/runtime/events/event_types.go:38

  • EventRecorder.LabeledEvent() returns *LabeledEvent, but LabeledEvent has only unexported fields and relies on internal initialization (labels/annotations maps). This makes it effectively impossible for code outside the events package to implement EventRecorder without risking nil-map panics in WithLabels/WithAnnotations or returning a non-functional event, which undermines the stated testing goal.
func (r *eventRecorder) LabeledEvent(
	regarding runtime.Object,
	eventType string,
	reason string,
	action string,
	note string,
) *LabeledEvent {

Comment thread pkg/runtime/events/event_types.go Outdated
Comment thread pkg/runtime/events/recorder.go

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread pkg/runtime/events/event_types.go
Comment thread pkg/runtime/events/recorder.go

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread pkg/runtime/events/event_types.go
Comment thread pkg/runtime/events/event_types.go
Comment thread pkg/runtime/events/recorder.go Outdated
Signed-off-by: bakito <github@bakito.ch>

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread pkg/runtime/events/recorder.go
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