applicationset icon indicating copy to clipboard operation
applicationset copied to clipboard

cluster generator: labels with slashes

Open hans-d opened this issue 3 years ago • 2 comments

see:

  • https://argocd-applicationset.readthedocs.io/en/stable/Generators-Cluster/
  • #166

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

hans-d avatar Oct 27 '21 07:10 hans-d

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

spyder007 avatar May 19 '22 17:05 spyder007

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

mvaalexp avatar Dec 14 '22 00:12 mvaalexp