argoproj / argo-cd

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

Resource deep links can't read metadata annotations from cluster #18466

Open jamestrousdale opened 1 month ago

jamestrousdale commented 1 month ago

Checklist:

Describe the bug

When attempting to reference cluster annotations via .cluster.metadata.annotations.key in a deep link on a resource, the value isn't retrieved. The same exact usage works from the application level.

I have different logging systems per cluster and I need to tie the base URL for a logging link to the cluster.

I can achieve this via the applicationset templates/generators as well, but it'll require duplicating the logging system base URL to each application where I want to use the deeplink (which is the workaround I'll use for now).

To Reproduce

I've put an annotation on my declarative cluster secret, e.g.

metadata:
    name: my-cluster
    labels:
        argocd.argoproj.io/secret-type: cluster
    annotations:
      deeplinktest: 'deeplinkvalue1'
...

I put a similar annotation on an application via the applicationset template.

  template:
    metadata:
      name: 'my-app-{{cluster}}'
      annotations:
        deeplinktest: 'deeplinkvalue2'
...

I see this annotation show up on the clusters screen in the argo server UI.

I put a links configuration like this in my argocd config map

yaml
  resource.links: |
    - url: https://google.com/{{.cluster.metadata.annotations.deeplinktest}}
      title: Google1
    - url: https://google.com/{{.app.metadata.annotations.deeplinktest}}
      title: Google2

However, only the one on the application level generates the link successfully. See screenshots below, but long story short, the link Google1 attempting to use a cluster annotation directs to https://google.com/<no value>, while the second works correctly and directs to https://google.com/deeplinkvalue2.

Expected behavior

Screenshots

image

image

Version

argocd: v2.9.1+58b04e5
  BuildDate: 2023-11-14T15:08:20Z
  GitCommit: 58b04e5e11d007b0518853029ff7612c24a2eb35
  GitTreeState: clean
  GoVersion: go1.21.3
  Compiler: gc
  Platform: linux/amd64

Logs

I couldn't see any relevant logs generated in the argocd-server container.

agaudreault commented 3 weeks ago

As specified in https://argo-cd.readthedocs.io/en/latest/operator-manual/deep_links/, clusters annotations are not supported. A workaround could be to add the label to each application from the applicationSet, or contribute to the enhancement :)