Skip to content

Commit

Permalink
Merge pull request #846 from fluxcd/recorder-for-scheme
Browse files Browse the repository at this point in the history
Add event recorder constructor decoupled from runtime Manager
  • Loading branch information
stefanprodan authored Dec 20, 2024
2 parents 6f26195 + 07d36f3 commit 8c4af78
Showing 1 changed file with 27 additions and 0 deletions.
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

0 comments on commit 8c4af78

Please sign in to comment.