From facda8b42297403b8623530183edce213924af8d Mon Sep 17 00:00:00 2001 From: Paulo Gomes Date: Tue, 21 Dec 2021 21:10:43 +0000 Subject: [PATCH] Check EventRecorder is not nil Signed-off-by: Paulo Gomes --- controllers/kustomization_controller.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/controllers/kustomization_controller.go b/controllers/kustomization_controller.go index b8766cfe..74060115 100644 --- a/controllers/kustomization_controller.go +++ b/controllers/kustomization_controller.go @@ -904,16 +904,18 @@ func (r *KustomizationReconciler) finalize(ctx context.Context, kustomization ku func (r *KustomizationReconciler) event(ctx context.Context, kustomization kustomizev1.Kustomization, revision, severity, msg string, metadata map[string]string) { log := logr.FromContext(ctx) - annotations := map[string]string{ - kustomizev1.GroupVersion.Group + "/revision": revision, - } + if r.EventRecorder != nil { + annotations := map[string]string{ + kustomizev1.GroupVersion.Group + "/revision": revision, + } - eventtype := "Normal" - if severity == events.EventSeverityError { - eventtype = "Warning" - } + eventtype := "Normal" + if severity == events.EventSeverityError { + eventtype = "Warning" + } - r.EventRecorder.AnnotatedEventf(&kustomization, annotations, eventtype, severity, msg) + r.EventRecorder.AnnotatedEventf(&kustomization, annotations, eventtype, severity, msg) + } if r.ExternalEventRecorder != nil { objRef, err := reference.GetReference(r.Scheme, &kustomization)