Skip to content

Commit

Permalink
feat: better check on composition id (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasepe authored Jul 30, 2024
1 parent 887fa4d commit 932e071
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# EventRouter

This service serves as an active watcher of event resource in the kubernetes system, which takes those events and pushes them to a user specified _HTTP hook_ (called _Registration_).
This service serves as an active watcher of event resource in the kubernetes system, which:

this service will POST to the specified _endpoint_ a JSON containing the event info.
- consider only events related to _involvedObjects_ with a composition identifier
- takes those events and pushes them to a user specified _HTTP hook_ (called _Registration_)

The service will POST to the specified _endpoint_ a JSON containing the event info.

Here a sample event info:

Expand Down
7 changes: 5 additions & 2 deletions internal/router/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,16 @@ func createPatchData(labels map[string]string) ([]byte, error) {
return json.Marshal(patch)
}

func wasPatchedByKrateo(obj *corev1.Event) bool {
func hasCompositionId(obj *corev1.Event) bool {
labels := obj.GetLabels()
if len(labels) == 0 {
return false
}

_, ok := labels[keyPatchedBy]
val, ok := labels[keyCompositionID]
if len(val) == 0 {
return false
}
return ok
}

Expand Down
19 changes: 12 additions & 7 deletions internal/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,18 @@ func (er *EventRouter) OnDelete(obj interface{}) {
}

func (er *EventRouter) onEvent(event *corev1.Event) {
if wasPatchedByKrateo(event) {
klog.V(4).InfoS("Received event",
"msg", event.Message,
"namespace", event.Namespace,
"reason", event.Reason,
"involvedObject", event.InvolvedObject.Name)

if hasCompositionId(event) {
klog.V(4).InfoS("CompositionID already present",
"msg", event.Message,
"namespace", event.Namespace,
"reason", event.Reason,
"involvedObject", event.InvolvedObject.Name)
return
}

Expand All @@ -112,11 +123,5 @@ func (er *EventRouter) onEvent(event *corev1.Event) {
// return
// }

klog.V(4).InfoS("Received event",
"msg", event.Message,
"namespace", event.Namespace,
"reason", event.Reason,
"involvedObject", event.InvolvedObject.Name)

er.handler.Handle(*event.DeepCopy())
}

0 comments on commit 932e071

Please sign in to comment.