Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add event recorder constructor decoupled from runtime Manager #846

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions runtime/events/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,33 @@ func NewRecorder(mgr ctrl.Manager, log logr.Logger, webhook, reportingController
}, nil
}

// NewRecorderForScheme creates an event Recorder with a Kubernetes event recorder and an external event recorder based on the
// given webhook. The recorder performs automatic retries for connection errors and 500-range response codes from the
// external recorder.
func NewRecorderForScheme(scheme *runtime.Scheme,
eventRecorder kuberecorder.EventRecorder,
log logr.Logger, webhook, reportingController string) (*Recorder, error) {
if webhook != "" {
if _, err := url.Parse(webhook); err != nil {
return nil, err
}
}

httpClient := retryablehttp.NewClient()
httpClient.HTTPClient.Timeout = 5 * time.Second
httpClient.CheckRetry = retryablehttp.ErrorPropagatedRetryPolicy
httpClient.Logger = nil

return &Recorder{
Scheme: scheme,
Webhook: webhook,
ReportingController: reportingController,
Client: httpClient,
EventRecorder: eventRecorder,
Log: log,
}, nil
}

// Event records an event in the webhook address.
func (r *Recorder) Event(object runtime.Object, eventtype, reason, message string) {
r.AnnotatedEventf(object, nil, eventtype, reason, message)
Expand Down
Loading