argoproj/argo-events

filter.fields of EventSource of K8S resource not working as expected

lauralhm opened this issue · 1 comments

Describe the bug
filter.fields of EventSource of K8S resource not working as expected. If I want to monitoring event happened on 2 applications each named as prod-eu-opf-test and prod-eu-opf-test-advance with filter involvedObject.name, then the event happened on application prod-eu-opf-test-advance will been pushed twice: from the event name for prod-eu-opf-test but also for prod-eu-opf-test-advance


**To Reproduce**
Steps to reproduce the behavior:
1. create two applications named as **prod-eu-opf-test** and **prod-eu-opf-test-advance**
2. have following eventsource definition for monitoring the events happened on argocd applications:

apiVersion: argoproj.io/v1alpha1
kind: EventSource
metadata:
  name: eventsource-for-ssp-apps
  namespace: argo-events
spec:
  resource:
    prod-eu-opf-test-updated:
      eventTypes:
        - ADD
      filter:
        afterStart: true
        fields:
          - key: involvedObject.name
            operation: '=='
            value: prod-eu-opf-test
          - key: involvedObject.kind
            operation: '=='
            value: Application
          - key: reason
            operation: '=='
            value: OperationCompleted
          - key: type
            operation: '=='
            value: Normal
      group: ''
      namespace: argocd
      resource: events
      version: v1
    prod-eu-opf-test-advance-updated:
      eventTypes:
        - ADD
      filter:
        afterStart: true
        fields:
          - key: involvedObject.name
            operation: '=='
            value:  prod-eu-opf-test-advance
          - key: involvedObject.kind
            operation: '=='
            value: Application
          - key: reason
            operation: '=='
            value: OperationCompleted
          - key: type
            operation: '=='
            value: Normal
      group: ''
      namespace: argocd
      resource: events
      version: v1

3. trigger the synchronization for app **prod-eu-opf-test-advance**, then watch the eventsource deployment log and found event source will publish two events:

{"level":"info","ts":1721186403.7188642,"logger":"argo-events.eventsource","caller":"eventsources/eventing.go:591","msg":"Succeeded to publish an event","eventSourceName":"eventsource-for-ssp-apps","eventName":"prod-eu-opf-test-updated","eventSourceType":"resource","eventID":"64326563353864362d373436612d346139622d623363362d383739356561383534613565"}
{"level":"info","ts":1721186407.6625366,"logger":"argo-events.eventsource","caller":"eventsources/eventing.go:591","msg":"Succeeded to publish an event","eventSourceName":"eventsource-for-ssp-apps","eventName":"prod-eu-opf-test-advance-updated","eventSourceType":"resource","eventID":"38376361643061632d666230632d346363342d386337642d393434356632333032666532"}


**Expected behavior**
Only the event for app **prod-eu-opf-test-advance** need to be pulished by eventsource. 
Btw, I have checked the source code, I think it's might be this line did the trick: https://github.com/argoproj/argo-events/blob/master/eventsources/sources/resource/start.go#L328

**Environment (please complete the following information):**
 - Kubernetes: v1.27.10
 - Argo: v2.8.5
 - Argo Events: v1.9.2

**Additional context**
Add any other context about the problem here.

---
<!-- Issue Author: Don't delete this message to encourage other users to support your issue! -->
**Message from the maintainers**:

If you wish to see this enhancement implemented please add a 👍 reaction to this issue! We often sort issues this way to know what to prioritize.

This issue has been automatically marked as stale because it has not had
any activity in the last 60 days. It will be closed if no further activity
occurs. Thank you for your contributions.