Skip to content

Commit

Permalink
PR review
Browse files Browse the repository at this point in the history
Signed-off-by: Giovanni Liva <[email protected]>
  • Loading branch information
thisthat committed Aug 9, 2023
1 parent 1ad8775 commit 80d1112
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 8 additions & 1 deletion lifecycle-operator/controllers/common/eventsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 4 additions & 2 deletions lifecycle-operator/controllers/common/eventsender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 80d1112

Please sign in to comment.