Argo CD Notifications Webhook

本质上,发送 webhook要比 发送 gmail 邮件更简单,这里我们沿用之前的trigger

trigger使用argocd上annotation和service绑定,然后再通过configmap和template绑定

trigger <- argocd annotation -> service

trigger <- configmap setting -> template

context

argocdUrl: "https://192.168.194.213:8000"
service.email.gmail

username: xxxxxxxx@gmail.com
password: xxxxxxxx
host: smtp.gmail.com
port: 465
from: xxxxxxxx@gmail.com
service.webhook.mywebhook

url: http://192.168.194.213:30001/deploy
headers:
- name: Content-Type
  value: application/json
template.app-sync-succeeded

email:
  subject: App Synced New version of an application {{.app.metadata.name}} is up and running.
message: |
  Application {{.app.metadata.name}} is now running new version of deployments manifests.
template.my-json-data

webhook:
  mywebhook:
    method: POST
    body: |
      {
        "name": "helloworld"
      }
trigger.on-sync-succeeded

- description: Test
  oncePer: app.status.operationState.syncResult.revision
  send:
  - app-sync-succeeded
  - my-json-data
  when: app.status.operationState.phase in ['Succeeded'] and app.status.health.status == 'Healthy'
apiVersion: v1
data:
  context: 'argocdUrl: "https://192.168.194.213:8000"'
  service.email.gmail: |-
    username: xxxxxxx@gmail.com
    password: xxxxxxx
    host: smtp.gmail.com
    port: 465
    from: xxxxxxx@gmail.com
  service.webhook.mywebhook: |-
    url: http://192.168.194.213:30001/deploy
    headers:
    - name: Content-Type
      value: application/json
  template.app-sync-succeeded: |-
    email:
      subject: App Synced New version of an application {{.app.metadata.name}} is up and running.
    message: |
      Application {{.app.metadata.name}} is now running new version of deployments manifests.
  template.my-json-data: |-
    webhook:
      mywebhook:
        method: POST
        body: |
          {
            "name": "helloworld"
          }
  trigger.on-sync-succeeded: |-
    - description: Test
      oncePer: app.status.operationState.syncResult.revision
      send:
      - app-sync-succeeded
      - my-json-data
      when: app.status.operationState.phase in ['Succeeded'] and app.status.health.status == 'Healthy'
kind: ConfigMap
metadata:
  annotations:
    meta.helm.sh/release-namespace: argocd
  creationTimestamp: "2021-08-03T06:44:27Z"
  labels:
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: argocd-notifications
    app.kubernetes.io/version: 1.1.1
    helm.sh/chart: argocd-notifications-1.4.1
  name: argocd-notifications-cm
  namespace: argocd

本例中的webhook接口是json的

notifications.argoproj.io/subscribe.on-sync-succeeded.mywebhook
Send a Message