FoxuTech

How to Configure Alerts and Event Handling with Argo CD

How to Configure Alerts and Event-Handling with Argo CD

As of today, GitOps is game changing technique which streamline application deployments and automation workflows. In this, Argo CD is a powerful continuous delivery tool and contributes major role. It leverages Git repositories as the single source of truth for application deployments. Argo CD not only provides deployment feature, it also supports for real-time event handling, notifications with Argo Events. In this post, we will see how to configure alerts and event handling with Argo CD.

Prerequisites:

Installing Argo CD Event Sources

Argo CD supports event handling by using Argo Events, a Kubernetes controller that enables the subscription to various GitOps-related events. We will set up Argo Events to listen for events and trigger actions accordingly.

To install the Argo Events run following command,

# kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-events/stable/manifests/install.yaml

Configuring ArgoCD Notifications

In this step, we will create a webhook event source to receive notifications from Argo CD and configure an event listener to handle these notifications.

Create a file named `webhook-event-source.yaml` with the following content:

apiVersion: argoproj.io/v1alpha1
kind: EventSource
metadata:
  name: webhook-event-source
  namespace: argocd
spec:
  service:
    type: Webhook
    port: 12000
  webhook:
    endpoint: /events

Apply the event source using the following command:

# kubectl apply -n argocd -f webhook-event-source.yaml

Next, create an event listener to dispatch notifications to a custom URL. Create a file named `event-listener.yaml` with the following content:

apiVersion: argoproj.io/v1alpha1
kind: EventListener
metadata:
  name: my-event-listener
  namespace: argocd
spec:
  eventSourceName: webhook-event-source
  serviceAccountName: default
  dispatchMechanism: HTTP
  dispatchEndpoint: http://your-notification-service-url

Replace `http://your-notification-service-url` with the actual URL where you want to receive notifications (e.g., Teams, email service, etc.).

Apply the event listener using the following command:

# kubectl apply -n argocd -f event-listener.yaml

Creating Custom Event Types and Triggers

Argo CD allows the creation of custom event types and triggers. Let’s create a trigger to notify when an application is synced successfully:

Create a file named `event-type-trigger.yaml` with the following content:

apiVersion: argoproj.io/v1alpha1
kind: Sensor
metadata:
  name: argo-sync-success-sensor
  namespace: argocd
spec:
  template:
    serviceAccountName: default
    eventProtocol:
      type: HTTP
    eventSourceType: webhook-event-source
    triggers:
      - name: notification
        template:
          src: |
            data: '{"message": "Application synced successfully: {{workflow.parameters.application}}"}'

Apply the trigger using the following command:

# kubectl apply -n argocd -f event-type-trigger.yaml

Testing the Notifications

With all the configurations in place, it’s time to test the notifications.

Sync one of your applications in the Argo CD web UI or using the Argo CD CLI after login to your Argo CD instance.

# argocd app sync my-app

After the sync operation, Argo Events will trigger the custom event type (argo-sync-success-sensor), and the EventListener will dispatch the notification to the specified URL. Check your notification service to confirm the receipt of the notification.

Exit mobile version