Closed9

Argo CD Notifications x slackで複数チャンネルで異なるメッセージを送りたい

omihirofumiomihirofumi

templateはこう作れる。

apiVersion: v1
kind: ConfigMapKind:configMap
metadata:
  name: argocd-notifications-cm
data:
  template.my-custom-template-slack-template: |
    message: |
      Application {{.app.metadata.name}} sync is {{.app.status.sync.status}}.
      Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}.
omihirofumiomihirofumi

triggerも作れる
sendのところにtemplateを指定すれば自作したtemplateが使えそう

apiVersion: v1
kind: ConfigMap
metadata:
  name: argocd-notifications-cm
data:
  trigger.on-sync-status-unknown: |
    - when: app.status.sync.status == 'Unknown'     # trigger condition
      send: [app-sync-status, github-commit-status] # template names
omihirofumiomihirofumi

triggerフィールドに自作したトリガーを指定すれば良さそう
https://argo-cd.readthedocs.io/en/stable/operator-manual/notifications/services/slack/

  apiVersion: argoproj.io/v1alpha1
  kind: Application
  metadata:
    annotations:
      notifications.argoproj.io/subscriptions: |
        - trigger: [on-scaling-replica-set, on-rollout-updated, on-rollout-step-completed]
          destinations:
            - service: slack
              recipients: [my-channel-1, my-channel-2]
            - service: email
              recipients: [recipient-1, recipient-2, recipient-3 ]
        - trigger: [on-rollout-aborted, on-analysis-run-failed, on-analysis-run-error]
          destinations:
            - service: slack
              recipients: [my-channel-21, my-channel-22]
omihirofumiomihirofumi

最初↓こうしたけど、oncePerの設定で片方しか通知が来なかったので別でトリガーを作成

  trigger.on-sync-succeeded: |
    - description: Application syncing has succeeded and health
      send:
      - app-sync-succeeded
      - my-custom-template-slack-template
      when: app.status.operationState.phase in ['Succeeded']  and app.status.health.status == 'Healthy'
      oncePer: app.status.sync.revision
omihirofumiomihirofumi
  trigger.on-sync-succeeded: |
    - description: Application syncing has succeeded and health
      send:
      - app-sync-succeeded
      when: app.status.operationState.phase in ['Succeeded']  and app.status.health.status == 'Healthy'
      oncePer: app.status.sync.revision
  trigger.on-sync-succeeded2: |
    - description: Application syncing has succeeded and health
      send:
      - my-custom-template-slack-template
      when: app.status.operationState.phase in ['Succeeded']  and app.status.health.status == 'Healthy'
      oncePer: app.status.sync.revision
omihirofumiomihirofumi

annotationsにはこうやって設定した。

  apiVersion: argoproj.io/v1alpha1
  kind: Application
  metadata:
    annotations:
      notifications.argoproj.io/subscribe.on-sync-succeeded.slack: test
      notifications.argoproj.io/subscribe.on-sync-succeeded2.slack: test2
このスクラップは4ヶ月前にクローズされました