argoproj / argo-cd

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

Deep links do not honor annotation names using - or / characters #14988

Open dan-vystrcil opened 10 months ago

dan-vystrcil commented 10 months ago

Checklist:

Describe the bug

When adding a deep link and using: {{.application.metadata.annotations.some/name}} or {{.application.metadata.annotations.some-name}}

The link will not appear and parsing errors will be logged on the server.

time="2023-08-08T22:06:49Z" level=error msg="errorList while evaluating application deep links, failed to parse link template 'https://github.gapinc.com/{{.metadata.annotations.chartis/chartis-file}}', error=template: deep-link:1: bad character U+002F '/'"

time="2023-08-08T22:09:29Z" level=error msg="errorList while evaluating application deep links, failed to parse link template 'https://github.gapinc.com/{{.application.metadata.annotations.chartis-file}}', error=template: deep-link:1: bad character U+002D '-'"

The annotations themselves are valid and will be presented on the application details page.

To Reproduce

Expected behavior

Valid annotations should be honored.

Screenshots

Version

argocd: v2.8.0+804d4b8.dirty
  BuildDate: 2023-08-07T15:15:45Z
  GitCommit: 804d4b8ca6bc4c2cf02c5c971aa923ec5b8623f0
  GitTreeState: dirty
  GoVersion: go1.20.7
  Compiler: gc
  Platform: linux/amd64
argocd-server: v2.7.8+92949f6.dirty
  BuildDate: 2023-07-19T15:18:54Z
  GitCommit: 92949f6033080f2fba9a9654f46592fb71982770
  GitTreeState: dirty
  GoVersion: go1.19.10
  Compiler: gc
  Platform: linux/amd64
  Kustomize Version: v5.0.1 2023-03-14T01:32:48Z
  Helm Version: v3.11.2+g912ebc1
  Kubectl Version: v0.24.2
  Jsonnet Version: v0.19.1

Logs

time="2023-08-08T22:06:49Z" level=error msg="errorList while evaluating application deep links, failed to parse link template 'https://github.gapinc.com/{{.metadata.annotations.chartis/chartis-file}}', error=template: deep-link:1: bad character U+002F '/'"

time="2023-08-08T22:09:29Z" level=error msg="errorList while evaluating application deep links, failed to parse link template 'https://github.gapinc.com/{{.application.metadata.annotations.chartis-file}}', error=template: deep-link:1: bad character U+002D '-'"
crenshaw-dev commented 10 months ago

This is a limitation of the language used to evaluate the template expression. Try this:

.application.metadata.annotations["chartis-file"]
dvystrcil commented 5 months ago

This is a limitation of the language used to evaluate the template expression. Try this:

.application.metadata.annotations["chartis-file"]

It's been a while, but now I am trying to use this for another annotation and unfortunately, your suggestion is not working.

The new error is: Unable to load data: failed to read application deep links from configmap: error unmarshalling deep links error converting YAML to JSON: yaml: did not find expected ',' or '}'

I can't debug further at the moment, so I will fall back on changing the annotation to camelCase since I have control over it.

frans-otogone commented 5 months ago

I've had the exact same issue and found a solution. Try this:

  application.links: |
    - url: "{{index .application.metadata.annotations \"my.annotations/test-deep-link\"}}"
      title: Deep link
      if: application.metadata.annotations["my.annotations/test-deep-link"] != ""
briceburg commented 1 month ago

Related? I tried using index in notifications template and it blows things up, e.g.

kind: Application
metadata:
  name: foo
  annotations:
    foo.io/vcs-url: https://github.com/acme/foo
spec:
  sources:
  - repoURL: https://github.com/acme/foo-config

---

kind: ConfigMap
metadata:
  name: argocd-notifications-cm
data:
  ...
  template.app-deployed: |
    message: |
      Application {{ .app.metadata.name }} is now running new version of deployments manifests.
    github:
      repoURLPath: "{{ "defaultValue" | or (index .app.metadata.annotations "foo.io/vcs-url") }}"

which results in a marshalling error no matter what permutation I try to reference the "foo.io/vcs-url" annotation.

ERRO[0000] error getting api from namespace: argocd error: failed to unmarshal template app-deployed: error converting YAML to JSON: yaml: line 3: did not find expected key
failed to get api: errors getting apis: [failed to unmarshal template app-deployed: error converting YAML to JSON: yaml: line 3: did not find expected key]
argocd@argocd-notifications-controller-64bbdf5ffd-vp5ln:/app$ argocd admin notifications template get
ERRO[0000] error getting api from namespace: argocd error: failed