From 80d11125f93c33eeea863d4939f069330d6953b7 Mon Sep 17 00:00:00 2001 From: Giovanni Liva Date: Wed, 9 Aug 2023 11:40:53 +0200 Subject: [PATCH] PR review Signed-off-by: Giovanni Liva --- lifecycle-operator/controllers/common/eventsender.go | 9 ++++++++- .../controllers/common/eventsender_test.go | 6 ++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lifecycle-operator/controllers/common/eventsender.go b/lifecycle-operator/controllers/common/eventsender.go index 623d420de3..7550e15676 100644 --- a/lifecycle-operator/controllers/common/eventsender.go +++ b/lifecycle-operator/controllers/common/eventsender.go @@ -76,10 +76,17 @@ func (e *cloudEvent) Emit(phase apicommon.KeptnPhaseType, eventType string, reco event.SetType(fmt.Sprintf("%s.%s", phase.LongName, status)) msg := setEventMessage(phase, reconcileObject, message, version) - err := event.SetData(ce.ApplicationJSON, map[string]string{ + err := event.SetData(ce.ApplicationJSON, map[string]interface{}{ "message": msg, "type": eventType, "version": version, + "resource": map[string]string{ + "group": reconcileObject.GetObjectKind().GroupVersionKind().Group, + "kind": reconcileObject.GetObjectKind().GroupVersionKind().Kind, + "version": reconcileObject.GetObjectKind().GroupVersionKind().Version, + "name": reconcileObject.GetName(), + "namespace": reconcileObject.GetNamespace(), + }, }) if err != nil { e.logger.V(5).Info(fmt.Sprintf("Failed to set data for CloudEvent: %v", err)) diff --git a/lifecycle-operator/controllers/common/eventsender_test.go b/lifecycle-operator/controllers/common/eventsender_test.go index 0c66822fb5..714ebe76a1 100644 --- a/lifecycle-operator/controllers/common/eventsender_test.go +++ b/lifecycle-operator/controllers/common/eventsender_test.go @@ -53,10 +53,12 @@ func TestEventSender_SendCloudEvent(t *testing.T) { require.Equal(t, "POST", r.Method) require.Equal(t, "/", r.URL.Path) require.Equal(t, 1, len(r.Header["Ce-Id"])) + require.Equal(t, 1, len(r.Header["Ce-Time"])) + require.Equal(t, 1, len(r.Header["Ce-Type"])) data, err := io.ReadAll(r.Body) require.Nil(t, err) - expected := fmt.Sprintf("{\"message\":\"%s: %s / Namespace: %s, Name: %s, Version: %s\",\"type\":\"%s\",\"version\":\"%s\"}", - phase.LongName, msg, ns, name, version, eventType, version) + expected := fmt.Sprintf("{\"message\":\"%s: %s / Namespace: %s, Name: %s, Version: %s\",\"resource\":{\"group\":\"\",\"kind\":\"\",\"name\":\"%s\",\"namespace\":\"%s\",\"version\":\"\"},\"type\":\"%s\",\"version\":\"%s\"}", + phase.LongName, msg, ns, name, version, name, ns, eventType, version) require.Equal(t, expected, string(data)) w.WriteHeader(http.StatusOK)