Skip to content

Adds GitOps Toolkit EventRecorder to ArtifactGenerator reconciler#310

Open
renatovassaomb wants to merge 1 commit intofluxcd:mainfrom
renatovassaomb:rv/gotk-event-recorder
Open

Adds GitOps Toolkit EventRecorder to ArtifactGenerator reconciler#310
renatovassaomb wants to merge 1 commit intofluxcd:mainfrom
renatovassaomb:rv/gotk-event-recorder

Conversation

@renatovassaomb
Copy link

Summary

Adding GitOps Toolkit EventRecorder to ArtifactGenerator Reconciler.

This will make generated events to be forwarded to the specified events address, which usually is the notifications controller.

Fixes #307.

Testing

  1. Create kind cluster, build docker image and load it
kind create cluster
docker build -t fluxcd/source-watcher:latest .
kind load docker-image fluxcd/source-watcher:latest
  1. Deploy notifications controller
flux install --components="notification-controller"
  1. Set --events-addr flag in source-watcher Deployment and deploy it
pushd config/manager
kustomize edit add patch  --patch '[{"op": "add", "path": "/spec/template/spec/containers/0/args/-", "value": "--events-addr=http://notification-controller.flux-system.svc.cluster.local."}]' --name source-watcher --kind Deployment
popd
make dev-deploy
  1. Create GitRepo and ArtifactGenerator
---
apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
  name: podinfo
  namespace: default
spec:
  interval: 5m0s
  url: https://github.com/stefanprodan/podinfo
  ref:
    branch: master
---
apiVersion: source.extensions.fluxcd.io/v1beta1
kind: ArtifactGenerator
metadata:
  name: my-app
spec:
  sources:
    - alias: podinfo
      kind: GitRepository
      name: podinfo
  artifacts:
    - name: my-app-composite
      copy:
        - from: "@podinfo/**"
          to: "@artifact/my-app/"
  1. Check for discarted event logs in notification-controller since it is still not handled properly.
k logs -n flux-system deploy/notification-controller | tail
{"level":"info","ts":"2026-02-03T20:59:59.286Z","msg":"Starting EventSource","controller":"alert","controllerGroup":"notification.toolkit.fluxcd.io","controllerKind":"Alert","source":"kind source: *v1beta3.Alert"}
{"level":"info","ts":"2026-02-03T20:59:59.388Z","msg":"Starting Controller","controller":"provider","controllerGroup":"notification.toolkit.fluxcd.io","controllerKind":"Provider"}
{"level":"info","ts":"2026-02-03T20:59:59.388Z","msg":"Starting workers","controller":"provider","controllerGroup":"notification.toolkit.fluxcd.io","controllerKind":"Provider","worker count":4}
{"level":"info","ts":"2026-02-03T20:59:59.388Z","msg":"Starting Controller","controller":"receiver","controllerGroup":"notification.toolkit.fluxcd.io","controllerKind":"Receiver"}
{"level":"info","ts":"2026-02-03T20:59:59.388Z","msg":"Starting workers","controller":"receiver","controllerGroup":"notification.toolkit.fluxcd.io","controllerKind":"Receiver","worker count":4}
{"level":"info","ts":"2026-02-03T20:59:59.388Z","msg":"Starting Controller","controller":"alert","controllerGroup":"notification.toolkit.fluxcd.io","controllerKind":"Alert"}
{"level":"info","ts":"2026-02-03T20:59:59.388Z","msg":"Starting workers","controller":"alert","controllerGroup":"notification.toolkit.fluxcd.io","controllerKind":"Alert","worker count":4}
{"level":"info","ts":"2026-02-03T21:13:10.077Z","logger":"event-server","msg":"discarding event, no alerts found for the involved object","eventInvolvedObject":{"kind":"ArtifactGenerator","namespace":"default","name":"my-app","uid":"cfe3e526-f58a-4a35-8e65-c6823d9351c4","apiVersion":"source.extensions.fluxcd.io/v1beta1","resourceVersion":"3011"}}
{"level":"info","ts":"2026-02-03T21:13:11.529Z","logger":"event-server","msg":"discarding event, no alerts found for the involved object","eventInvolvedObject":{"kind":"ArtifactGenerator","namespace":"default","name":"my-app","uid":"cfe3e526-f58a-4a35-8e65-c6823d9351c4","apiVersion":"source.extensions.fluxcd.io/v1beta1","resourceVersion":"3013"}}
{"level":"info","ts":"2026-02-03T21:13:11.529Z","logger":"event-server","msg":"discarding event, no alerts found for the involved object","eventInvolvedObject":{"kind":"ArtifactGenerator","namespace":"default","name":"my-app","uid":"cfe3e526-f58a-4a35-8e65-c6823d9351c4","apiVersion":"source.extensions.fluxcd.io/v1beta1","resourceVersion":"3013"}}

Signed-off-by: Renato Vassão <renato.vassao@mindbodyonline.com>
@matheuscscp
Copy link
Member

matheuscscp commented Feb 4, 2026

Hi @renatovassaomb! Thanks for this PR 🙏

If you use your other account @renatovassao you will be able to use the CI without us allowing it to run.

Also, I think we discussed in the dev meeting, this PR should not simply replace the current event recorder with the notification-controller one because the events that are currently sent are too much, it will be a lot of noise. We need to selectively send events to notification-controller for the most important ones, e.g. errors (make them aggregated i.e. do not send one error per source or per artifact), and an event when an artifact digest changes (should also be a single event for all artifacts whose digest changed).

@renatovassaomb
Copy link
Author

Hi @renatovassaomb! Thanks for this PR 🙏

If you use your other account @renatovassao you will be able to use the CI without us allowing it to run.

Also, I think we discussed in the dev meeting, this PR should not simply replace the current event recorder with the notification-controller one because the events that are currently sent are too much, it will be a lot of noise. We need to selectively send events to notification-controller for the most important ones, e.g. errors (make them aggregated i.e. do not send one error per source or per artifact), and an event when an artifact digest changes (should also be a single event for all artifacts whose digest changed).

Sounds good, thanks for the insights @matheuscscp. I wanted to get this open to make sure I was on the right track, I'll keep working on it to meet these requirements.

Comment on lines -193 to +197
EventRecorder: mgr.GetEventRecorderFor(controllerName),
EventRecorder: eventRecorder,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

potentially here on the ArtifactGeneratorReconciler{}, we could have an additional NotificationEventRecorder.

This would give us granularity within the Reconcile to decide which events are intentionally desirable for notification-controller vs. internal controller usage for status

wdyt @stefanprodan ?
cc @matheuscscp

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this, we can set the events we don't want to reach NC to trace. See https://github.com/fluxcd/pkg/blob/40ae93e513e71a2398a487990bff1108b1ececab/runtime/events/recorder.go#L204

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, much better!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support ArtifactGenerator notifications

4 participants