Skip to content

Commit

Permalink
fix: initialize event recorder in datasource controller
Browse files Browse the repository at this point in the history
  • Loading branch information
pb82 committed Oct 18, 2021
1 parent ceb0588 commit a848388
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
8 changes: 4 additions & 4 deletions controllers/grafanadatasource/datasource_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type GrafanaDatasourceReconciler struct {
Scheme *runtime.Scheme
Context context.Context
Cancel context.CancelFunc
recorder record.EventRecorder
Recorder record.EventRecorder
Logger logr.Logger
}

Expand Down Expand Up @@ -155,7 +155,7 @@ func (r *GrafanaDatasourceReconciler) reconcileDataSources(state *common.DataSou
// finally, update the configmap
err = r.Client.Update(r.Context, state.KnownDataSources)
if err != nil {
r.recorder.Event(state.KnownDataSources, "Warning", "UpdateError", err.Error())
r.Recorder.Event(state.KnownDataSources, "Warning", "UpdateError", err.Error())
} else {
r.manageSuccess(updated)
}
Expand Down Expand Up @@ -194,7 +194,7 @@ func (i *GrafanaDatasourceReconciler) updateHash(known *v1.ConfigMap) (string, e

// Handle error case: update datasource with error message and status
func (r *GrafanaDatasourceReconciler) manageError(datasource *grafanav1alpha1.GrafanaDataSource, issue error) {
r.recorder.Event(datasource, "Warning", "ProcessingError", issue.Error())
r.Recorder.Event(datasource, "Warning", "ProcessingError", issue.Error())

// datasource deleted
if datasource == nil {
Expand Down Expand Up @@ -227,7 +227,7 @@ func (r *GrafanaDatasourceReconciler) manageSuccess(datasources []grafanav1alpha

err := r.Client.Status().Update(r.Context, &datasources[i])
if err != nil {
r.recorder.Event(&datasources[i], "Warning", "UpdateError", err.Error())
r.Recorder.Event(&datasources[i], "Warning", "UpdateError", err.Error())
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,12 @@ func main() { // nolint
os.Exit(1)
}
if err = (&grafanadatasource.GrafanaDatasourceReconciler{
Client: mgr.GetClient(),
Context: ctx,
Cancel: cancel,
Logger: ctrl.Log.WithName("controllers").WithName("GrafanaDatasource"),
Scheme: mgr.GetScheme(),
Client: mgr.GetClient(),
Context: ctx,
Cancel: cancel,
Logger: ctrl.Log.WithName("controllers").WithName("GrafanaDatasource"),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("GrafanaDatasource"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "GrafanaDatasource")
os.Exit(1)
Expand Down

0 comments on commit a848388

Please sign in to comment.