argoproj / applicationset

The ApplicationSet controller manages multiple Argo CD Applications as a single ApplicationSet unit, supporting deployments to large numbers of clusters, deployments of large monorepos, and enabling secure Application self-service.
https://argocd-applicationset.readthedocs.io/
Apache License 2.0
584 stars 278 forks source link

cluster generator: labels with slashes #397

Open hans-d opened 3 years ago

hans-d commented 3 years ago

see:

When using a cluster generator, I want to reference a label that contains a slash in the name, eg argocd.argoproj.io/secret-type, via {{ metadata.labels.argocd.argoproj.io/secret-type }}

Besides the fact it doesnt feel right to provide the key which contains dots without escaping, (eg {{ metadata.label.[argocd.argoproj.io/secret-type] }} like kustomize), it complains about the slash:

2021-10-27T07:47:25.615Z        ERROR   controller-runtime.manager.controller.applicationset    Reconciler error        {"reconciler group": "argoproj.io", "reconciler kind": "ApplicationSet", "name": "test", "namespace": "argocd", "error": "Application.argoproj.io \"test-with-labels\" is invalid: metadata.labels: Invalid value: \"{{ metadata.labels.argocd.argoproj.io/secret-type }}\": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')"}

It does get created initially, but fails to reconcile

spyder007 commented 2 years ago

@hans-d did you ever figure out the appropriate syntax for this?

mvaalexp commented 1 year ago

If anyone is still trying to figure this out, with a lot of guess/checking, looking through code and PRs, seems there is a way to do this now. Documentations for this seems to be missing.

In 2.5.x they added the ability to do "go template" syntax, so you can add

goTemplate: true

and access the slash labels and annotations like this

{{ index .metadata.labels "argocd.argoproj.io/secret-type" }}

edit: found the doc here: https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/GoTemplate/#cluster-generators