feat: define interface for event recorder#1985
Open
bakito wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
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
EventRecorderstruct with an exportedEventRecorderinterface and introduced an unexportedeventRecorderimplementation. - Updated
NewEventRecorderto 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, butLabeledEventhas only unexported fields and relies on internal initialization (labels/annotations maps). This makes it effectively impossible for code outside theeventspackage to implementEventRecorderwithout risking nil-map panics inWithLabels/WithAnnotationsor 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 {
Signed-off-by: bakito <github@bakito.ch>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.