"argocd admin notifications template notify" fails when using "call .repo.getAppDetails" in the template
Checklist:
- [x] I've searched in the docs and FAQ for my answer: https://bit.ly/argocd-faq.
- [x] I've included steps to reproduce the bug.
- [x] I've pasted the output of
argocd version.
Describe the bug
argocd admin notifications template notify throws an error when testing a notification that contains a call to .repo.getAppDetails.
To Reproduce
Setup this notification in the argocd-notifications configmap:
$ cat ./argocd-notifications.preprod-eu.yaml
[...]
template.app-sync-succeeded: |
message: |
{{if eq .serviceType "slack"}}:check_ok:{{end}} Deployment <{{.context.argocdUrl}}applications/{{.app.metadata.name}}|{{.app.metadata.name}}> to `{{.context.environmentName}}-{{.context.region}}` environment succeeded!
repository: `{{.app.spec.source.repoURL}}`
{{if ne (index .app.metadata.annotations "release-values-prefix") nil }}
tag: `{{ (call .repo.GetAppDetails).Helm.GetParameterValueByName (print (index .app.metadata.annotations "release-values-prefix") ".app.image.tag") }}`
executor: `{{ (call .repo.GetAppDetails).Helm.GetParameterValueByName (print (index .app.metadata.annotations "release-values-prefix") ".release.lastAuthor") }}`
{{end}}
[...]
Then call the CLI:
# Current kubecontext targets a live cluster and the 'argocd' namespace, which contains an ArgoCD 2.3.3 deployment
$ ./argocd-2.4.14 admin notifications --config-map ./argocd-notifications.preprod-eu.yaml template notify app-sync-succeeded myapp
failed to notify 'console:stdout': template: app-sync-succeeded:4:10: executing "app-sync-succeeded" at <call .repo.GetAppDetails>: error calling call: runtime error: invalid memory address or nil pointer dereference
Expected behavior
I would expect admin notifications template notify to succeed and return the templated text, with the CLI contacting the server to load dynamic data.
Version
ArgoCD server 2.3.3. Reproduced with any client from 2.3.3 to 2.5.0-rc2.
$ kubectl exec argocd-repo-server-7c946fc856-f2h4x -- argocd version
Defaulted container "repo-server" out of: repo-server, copyutil (init)
argocd: v2.3.3+07ac038
BuildDate: 2022-03-30T00:06:18Z
GitCommit: 07ac038a8f97a93b401e824550f0505400a8c84e
GitTreeState: clean
GoVersion: go1.17.6
Compiler: gc
Platform: linux/amd64
time="2022-10-12T14:45:12Z" level=fatal msg="Argo CD server address unspecified"
command terminated with exit code 1
$ ./argocd-2.4.14 version
argocd: v2.4.14+029be59
BuildDate: 2022-10-05T17:37:30Z
GitCommit: 029be590bfd5003d65ddabb4d4cb8a31bff29c18
GitTreeState: clean
GoVersion: go1.18.6
Compiler: gc
Platform: linux/amd64
FATA[0000] Argo CD server address unspecified
Logs
Client doesn't log anything, didn't find anything related in server logs (I suspect this is entirely client side).
Additional data
- Removing the calls to
.repo.GetAppDetailsfrom the template fixes the calls, but of course prevents testing them. - It does seem like the CLI contacts the server to load the app: passing a non-existent app name fails with the proper error
applications.argoproj.io "myapp2" not found.
Any update of this? I have the exact same issue Server: v2.5.2 CLI: v2.3.4
I've same issue with argocd admin notifications template notify..
- Server: v2.5.5
- CLI: v2.5.5
Same issue on 2.6.0
call of repo function from "argocd admin notifications template notify" {{(call .repo.GetCommitMetadata .app.status.sync.revision).Author}} behaves the same. version: v2.6.1+3f143c9
This is still failing in argocd: v2.12.4+27d1e64 with argocd-server: v2.10.5+335875d: failed to notify 'slack:xxx': template: app-deployed:2:48: executing "app-deployed" at <call .repo.GetCommitMetadata .app.status.sync.revision>: error calling call: runtime error: invalid memory address or nil pointer dereference