argoproj / argo-cd

Declarative Continuous Deployment for Kubernetes
https://argo-cd.readthedocs.io
Apache License 2.0
18.06k stars 5.52k forks source link

Get EOF error while sending notification to MS Teams webhook #20603

Open UranusC opened 1 month ago

UranusC commented 1 month ago

Checklist:

Describe the bug I'm trying to add TEAMS to ArgoCD Notifications, but it isn't sending notification. The application deployment is by using applicationset

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: xxxxxx-applicationset
  namespace: argocd
spec:
  goTemplate: true
  goTemplateOptions: ["missingkey=error"]
  generators:
  - list:
      elements:
      - valuesFile: ../projects/xxxxxx/#{ENVIRONMENT}#/values_frontend.yaml
        name: frontend
      - valuesFile: ../projects/xxxxxx/#{ENVIRONMENT}#/values_backend.yaml
        name: backend
  template: 
    metadata:
      annotations:
        notifications.argoproj.io/subscribe.on-sync-succeeded.teams: dais_teams
      name: xxxxxx-{{.name}}
    spec:
      project: sparkgpt
      source:
        path: dais_app_charts
        repoURL: xxxxxx
        targetRevision: gptingress
        helm:
          releaseName: xxxxxx-applicationset
          valueFiles:
            - '{{.valuesFile}}'
      destination:
        server: "https://kubernetes.default.svc"
        namespace: xxxxxx
      syncPolicy:
        automated:
          prune: true

I followed the step from: https://argocd-notifications.readthedocs.io/en/stable/services/teams/

Here is my config: argocd-notifications-cm:

apiVersion: v1
kind: ConfigMap
metadata:
  name: argocd-notifications-cm
  namespace: argocd
data:
  service.teams: |
    recipientUrls:
      dais_teams: $dais-teams-url
  template.app-sync-succeeded: |
    teams:
      themeColor: "#ce7e00"
      sections: |
        [{
          "facts": [
            {
              "name": "Sync Status",
              "value": "{{.app.status.sync.status}}"
            },
            {
              "name": "Finished at",
              "value": "{{.app.status.operationState.finishedAt}}"
            }
          ]
        }]
      potentialAction: |-
        [{
          "@type":"OpenUri",
          "name":"Operation Details",
          "targets":[{
            "os":"default",
            "uri":"{{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true"
          }]
        }]
      title: "Sync-succeeded: {{.app.metadata.name}}"
      text: Application {{.app.metadata.name}} has been successfully synced at {{.app.status.operationState.finishedAt}}.
  trigger.on-sync-succeeded: |
    - description: Application syncing has succeeded
      send:
      - app-sync-succeeded
      when: app.status.operationState != nil and app.status.operationState.phase in ['Succeeded']

To Reproduce

  1. Open Teams and goto Apps
  2. Find Incoming Webhook microsoft app and click on it
  3. Press Add to a team -> select team and channel -> press Set up a connector
  4. Enter webhook name and upload image (optional)
  5. Press Create then copy webhook url and store it in argocd_notifications-secret in argocd-notifications-cm
  6. in argocd-notifications-cm ConfigMap:
    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: argocd-notifications-cm
    data:
    service.teams: |
    recipientUrls: 
      channelName: $channel-teams-url
  7. Create subscription for your Teams integration:
    apiVersion: argoproj.io/v1alpha1
    kind: Application
    metadata:
    annotations:
    notifications.argoproj.io/subscribe.on-sync-succeeded.teams: channelName

Expected behavior

The Incoming Webhook microsoft app can send notifications.

Logs

time="2024-10-30T22:26:40Z" level=info msg="Trigger on-sync-succeeded result: [{[0].IwKhHw9Hu8IE3z5Y8CQE4vReLYs  [app-sync-succeeded] true}]" resource=argocd/xxxxxx
time="2024-10-30T22:26:40Z" level=info msg="Sending notification about condition 'on-sync-succeeded.[0].IwKhHw9Hu8IE3z5Y8CQE4vReLYs' to '{teams dais_teams}' using the configuration in namespace argocd" resource=argocd/xxxxxx
time="2024-10-30T22:26:40Z" level=error msg="Failed to notify recipient {teams dais_teams} defined in resource argocd/dais-app-networkpolicy-sparkgpt: Post \"https://xxxxxx.webhook.office.com/webhookb2/3d28aac2-03da-42fc-b4c7-fe6d17c9f70c@f6b3cec6-a862-4a40-9ab4-00d6e11e6f0f/IncomingWebhook/f7b5965593d844c6a49edc8af0738275/261a3e97-f00c-4741-81c7-fb889614074b/V2v-QZXBgweGaxAxxTamS7VMA8UkJkL-NeWWld4ih1W-U1\": EOF using the configuration in namespace argocd" resource=argocd/xxxxxxx
time="2024-10-30T22:26:40Z" level=info msg="Processing completed" resource=argocd/xxxxxxx

I have also tried template from https://github.com/argoproj/argo-cd/blob/master/notifications_catalog/install.yaml Here is the argocd-notification-cm:

apiVersion: v1
kind: ConfigMap
metadata:
  name: argocd-notifications-cm
  namespace: argocd
data:
  service.teams: |
    recipientUrls:
      dais_teams: $dais-teams-url
  template.app-sync-succeeded: |
    teams:
      facts: |
        [{
          "name": "Sync Status",
          "value": "{{.app.status.sync.status}}"
        },
        {
          "name": "Synced at",
          "value": "{{.app.status.operationState.finishedAt}}"
        },
        {
          "name": {{- if .app.spec.source }} "Repository" {{- else if .app.spec.sources }} "Repositories" {{- end }},
          "value": {{- if .app.spec.source }} ":arrow_heading_up: {{ .app.spec.source.repoURL }}" {{- else if .app.spec.sources }} "{{- range $index, $source := .app.spec.sources }}{{ if $index }}\n{{ end }}:arrow_heading_up: {{ $source.repoURL }}{{- end }}" {{- end }},
        }
        {{range $index, $c := .app.status.conditions}}
          ,
          {
            "name": "{{$c.type}}",
            "value": "{{$c.message}}"
          }
        {{end}}
        ]
      potentialAction: |
        [{
          "@type":"OpenUri",
          "name":"Operation Details",
          "targets":[{
            "os":"default",
            "uri":"{{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true"
          }]
        },
        {
          "@type":"OpenUri",
          "name":"Open Repository",
          "targets":[{
            "os":"default",
            "uri":{{- if .app.spec.source }} ":arrow_heading_up: {{ .app.spec.source.repoURL }}" {{- else if .app.spec.sources }} "{{- range $index, $source := .app.spec.sources }}{{ if $index }}\n{{ end }}:arrow_heading_up: {{ $source.repoURL }}{{- end }}" {{- end }},
          }]
        }]
      themeColor: '#000080'
      title: Application {{.app.metadata.name}} has been successfully synced
  trigger.on-sync-succeeded: |
    - description: Application syncing has succeeded
      send:
      - app-sync-succeeded
      when: app.status.operationState != nil and app.status.operationState.phase in ['Succeeded']

The Log is:

time="2024-10-30T22:30:40Z" level=info msg="Start processing" resource=argocd/xxxxxxx
time="2024-10-30T22:30:40Z" level=info msg="Trigger on-sync-succeeded result: [{[0].IwKhHw9Hu8IE3z5Y8CQE4vReLYs  [app-sync-succeeded] true}]" resource=argocd/xxxxxxx
time="2024-10-30T22:30:40Z" level=info msg="Sending notification about condition 'on-sync-succeeded.[0].IwKhHw9Hu8IE3z5Y8CQE4vReLYs' to '{teams dais_teams}' using the configuration in namespace argocd" resource=argocd/xxxxxxx
time="2024-10-30T22:30:40Z" level=error msg="Failed to notify recipient {teams dais_teams} defined in resource argocd/dais-app-sparkgpt-frontend: teams facts unmarshalling error invalid character '}' looking for beginning of object key string using the configuration in namespace argocd" resource=argocd/xxxxxxx
time="2024-10-30T22:30:40Z" level=info msg="Processing completed" resource=argocd/xxxxxxx

Can anyone please help me solve this issue?

andrii-korotkov-verkada commented 3 weeks ago

If it's single-source app, try

    teams:
      facts: |
        [{
          "name": "Sync Status",
          "value": "{{.app.status.sync.status}}"
        },
        {
          "name": "Synced at",
          "value": "{{.app.status.operationState.finishedAt}}"
        },
        {
          "name": "Repository",
          "value": "{{.app.spec.source.repoURL}}"
        }
        {{range $index, $c := .app.status.conditions}}
          ,
          {
            "name": "{{$c.type}}",
            "value": "{{$c.message}}"
          }
        {{end}}
        ]
      potentialAction: |-
        [{
          "@type":"OpenUri",
          "name":"Operation Details",
          "targets":[{
            "os":"default",
            "uri":"{{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true"
          }]
        },
        {
          "@type":"OpenUri",
          "name":"Open Repository",
          "targets":[{
            "os":"default",
            "uri":"{{.app.spec.source.repoURL | call .repo.RepoURLToHTTPS}}"
          }]
        }]
      themeColor: '#000080'
      title: Application {{.app.metadata.name}} has been successfully synced

Though I've never tested it, but that's from one of the previous versions of the config that I have.

andrii-korotkov-verkada commented 3 weeks ago

Ah, looks like the format has changed, at least according to the wiki https://argo-cd.readthedocs.io/en/stable/operator-manual/notifications/services/teams/#templates.

andrii-korotkov-verkada commented 3 weeks ago

Btw, what's your ArgoCD version?