Skip to content

Notifications

Configuring notifications

You can use the mrp-controller.argoproj.io/change-revisions (or mrp-controller.argoproj.io/change-revision if you only use single source applications) to build triggers and templates for the Argo CD Notifications controller.

See sample triggers and templates in samples/notifications directory. You may add sample triggers and templates from the samples directory using a command like:

kubectl patch -n argocd cm argocd-notifications-cm --patch-file  samples/notifications/patch.yaml 

The sample trigger

Triggers after Application syncing has succeeded and the Change Revision for the Application has changed.

- description: Application changed
  oncePer: app.metadata.annotations["mrp-controller.argoproj.io/change-revisions"]
  send:
  - app-application-changed
  when:  app.status?.operationState?.phase in ['Succeeded']

The sample template

The sample template uses the mrp-controller.argoproj.io/change-revisions annotation to build a table of all application sources and their last Change Revisions. Assuming that the Git repository is located on GitHub it gives links to the application manifests in git and to the Change Revision commit. For Helm Repository based sources it shows helm repository chart name and its version.

email:
  subject: Application {{.app.metadata.name}} Changed at {{.app.status.operationState.finishedAt}}
message: |
  <html lang="en">
    <head>
      <title>Application {{.app.metadata.name}} Changed at {{.app.status.operationState.finishedAt}}</title>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <style>
        td {
          border: 1px solid;
          padding: 4px 4px;
        }
        table {
          border: 1px solid;
          border-collapse: collapse;
        }
      </style>
    </head>
    <body>
      {{$revs:=index .app.metadata.annotations "mrp-controller.argoproj.io/change-revisions" | fromJson}}
      <p>
      <strong>
      Application <a href="{{.context.argocdUrl}}/applications/{{.app.metadata.name}}">{{.app.metadata.name}}</a> Changed at {{.app.status.operationState.finishedAt}}
      </strong>
      </p>

      <p>Change revisions for sources are:
      <table>
      {{$sources := .app.spec.sources}}
      {{$source := .app.spec.source}}
      {{range $idx, $val := $revs }}
        <tr>
          {{ $src:="" }}
          {{if not $sources  }}
            {{$src = $source}}
          {{else}}
            {{$src = index $sources $idx}}
          {{end}}
          {{$repoUrl := index $src  "repoURL" | trimSuffix ".git"}}
          {{$srcName := default $repoUrl (index $src "name")}}
          <td>{{$idx}}</td>
          {{if not $src.chart}}
          {{$srcURL := print $repoUrl "/tree/" (index $src  "targetRevision")  "/" (index $src  "path")}}
          <td>Git</td>
          <td><a href='{{$srcURL}}'>{{$srcName}}</a></td>
          <td><a href='{{$repoUrl}}/commit/{{$val}}'>{{$val}}</a></td>
          {{else}}
          <td>Helm</td>
          {{$srcURL := print $repoUrl "/" (index $src  "chart") }}
          <td><a href='{{$srcURL}}'>{{$srcName}}</a></td>
          <td><a href='{{$repoUrl}}/{{$src.chart}}:{{$val}}'>{{$src.chart}}:{{$val}}</a></td>
          {{end}}
        </tr>
      {{end}}
      </table>
      </p>
      <p>
      Sync operation details are available at <a href='{{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true'>ArgoCD UI</a>.
      </p>
    </body>
  </html>