argo-cd icon indicating copy to clipboard operation
argo-cd copied to clipboard

Argo CD Notifications Slack: repo.GetCommitMetadata fails to interpret .app.status.sync.revisions

Open northonheld opened this issue 1 year ago • 8 comments

Describe the bug

When I try to run this way {{(call .repo.getCommitMetadata .app.status.sync.revisions).Author}} I get this error <call .repo.GetCommitMetadata .app.status.sync.revisions>: error calling call: arg 0: value has type []interface {}; should be string"

I am using the new feature called "sources".

When I am using this option I notice that all paths within the status where the information is has become a list. Source changed to Soureces and revision changed to revisions. But repo.GetCommitMetadata can't handle lists and now I only have available the status revisions.

My argocd-notifications-cm configuration:

  template.app-deployed: |
    message: |
      {{if eq .serviceType "slack"}}:white_check_mark:{{end}} Application {{.app.metadata.name}} is now running new version of deployments manifests.
    slack:
      attachments: |
        [{
          "title": "{{ .app.metadata.name}}",
          "title_link":"{{.context.argocdUrl}}/applications/{{.app.metadata.name}}",
          "color": "#18be52",
          "fields": [
          {
            "title": "Sync Status",
            "value": "{{.app.status.sync.status}}",
            "short": true
          },
          {
            "title": "Revision",
            "value": "{{.app.status.sync.revisions}}",
            "short": true
          },
          {
              "type": "mrkdwn",
              "text": "*Author:*\n<@{{(call .repo.GetCommitMetadata .app.status.sync.revisions).Author}}>"
          }
          {{range $index, $c := .app.spec.sources}}
          {{if not $index}},{{end}}
          {{if $index}},{{end}}
          {
            "title": "Repository",
            "value": "{{$c.repoURL}}",
            "short": true
          }
          {{end}}
          {{range $index, $c := .app.status.conditions}}
          {{if not $index}},{{end}}
          {{if $index}},{{end}}
          {
            "title": "{{$c.type}}",
            "value": "{{$c.message}}",
            "short": true
          }
          {{end}}
          ]
        }]
      deliveryPolicy: Post
      groupingKey: ""
      notifyBroadcast: false

I found it and tried to configure it as shown in this link, but without success https://github.com/argoproj/argo-cd/discussions/10573

To Reproduce

Just use the Sources functionality in your Application

Expected behavior

I want to be able to pass a list of revisions to .repo.GetCommitMetadata using .app.status.sync.revisions

Screenshots

When I use only the path to revisions:

          {
            "title": "Revision",
            "value": "{{.app.status.sync.revisions}}",
            "short": true
          },

Captura de Tela 2023-04-19 às 00 43 29

New Aplication status: Captura de Tela 2023-04-19 às 00 46 34

Version

argocd: v2.6.3+e05298b.dirty
  BuildDate: 2023-02-27T16:13:38Z
  GitCommit: e05298b9c6ab8610104271fa8491f019fee3c587
  GitTreeState: dirty
  GoVersion: go1.20.1
  Compiler: gc
  Platform: darwin/amd64
argocd-server: v2.6.5+60104ac
  BuildDate: 2023-03-14T14:19:45Z
  GitCommit: 60104aca6faec73d10d57cb38245d47f4fb3146b
  GitTreeState: clean
  GoVersion: go1.18.10
  Compiler: gc
  Platform: linux/amd64
  Kustomize Version: v4.5.7 2022-08-02T16:35:54Z
  Helm Version: v3.10.3+g835b733
  Kubectl Version: v0.24.2
  Jsonnet Version: v0.19.1

Logs

argocd-notifications-controller-76fb8454c5-sbwzz notifications-controller time="2023-04-19T02:35:27Z" level=error msg="Failed to notify recipient {slack dev-staging} defined in resource argocd/httpbin: template: app-deployed:18:17: executing \"app-deployed\" at <call .repo.GetCommitMetadata .app.status.sync.revisions>: error calling call: arg 0: value has type []interface {}; should be string" resource=argocd/httpbin

northonheld avatar Apr 19 '23 03:04 northonheld