argoproj / argo-cd

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

Helm Parameters does not allow common annotations #8464

Open derrickburns opened 2 years ago

derrickburns commented 2 years ago

I would like to pass an annotation via helm parameters in the Application CRD such as:

annotations:
      configmap.reloader.stakater.com/reload: "foo"

However, this does not work:

  source:
    helm:
      parameters:
      - name: annotations."configmap.reloader.stakater.com/reload"
        value: : "foo"

According to the k8s spec for annotations, the slash and period are allowed:

Valid annotation keys have two segments: an optional prefix and name, separated by a slash (/). The name segment is required and must be 63 characters or less, beginning and ending with an alphanumeric character ([a-z0-9A-Z]) with dashes (-), underscores (_), dots (.), and alphanumerics between. The prefix is optional. If specified, the prefix must be a DNS subdomain: a series of DNS labels separated by dots (.), not longer than 253 characters in total, followed by a slash (/).

On the flattener side, there is a related bug here.

Your flatVal function does not check for the presence of dots in the key. Therefore, the key gets mis-interpreted when flattened.

ishitasequeira commented 2 years ago

I would like to work on this.

zoltan-patchworks commented 2 years ago

Try escaping the dot.

Example:

        - name: controller.podAnnotations."prometheus\.io/scrape"
          value: "true"
        - name: controller.podAnnotations."prometheus\.io/port"
          value: "10254"
avifreege commented 2 years ago

We are facing issues also with service account annotations: - name: controller.serviceAccount.annotations."eks\\.amazonaws\\.com/role-arn" also this: - name: controller.serviceAccount.annotations."eks\.amazonaws\.com\/role-arn" also this: - name: controller.serviceAccount.annotations."eks\.amazonaws\.com/role-arn"

nothing seems to work, can you assist?

k1rk commented 2 years ago

@avifreege try

- name: controller.serviceAccount.annotations.eks\.amazonaws\.com/role-arn
zen commented 1 year ago

Anyone figured out what is a proper way to escape annotations? Example above does not seem to work for me, my case is:

name: argo-workflows.server.ingress.annotations.alb\.ingress\.kubernetes\.io/group.name

None of the variants worked, all attempts end up with actual annotation being like:

alb=map[ingress:map[kubernetes:map[io/group:map[name:some-value]]]]
dmitry-mightydevops commented 1 year ago

argo v2.8.2, worked for me this way:

{{- if and (.Values.ingressNginx) (.Values.ingressNginx.enable) -}}
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: ingress-nginx
  namespace: {{ .Values.argoNamespace | default "argo-cd" }}
  finalizers:
    - resources-finalizer.argocd.argoproj.io
spec:
  project: {{ .Values.argoProject | default "default" }}
  source:
    repoURL: {{ .Values.repoUrl }}
    path: config/addons/ingress-controllers/ingress-nginx
    targetRevision: {{ .Values.targetRevision }}
    helm:
      values: |
        ingress-nginx:
          {{- omit .Values.ingressNginx "destinationNamespace" | toYaml | nindent 10 }}
      parameters:
      - name: ingress-nginx.controller.service.annotations.\external-dns\.alpha\.kubernetes\.io/hostname
        value: {{ .Values.hostname }}
  destination:
    server: {{ .Values.destinationServer | default "https://kubernetes.default.svc" }}
    namespace: {{ .Values.ingressNginx.destinationNamespace }}
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
    syncOptions:
      - ApplyOutOfSyncOnly=true
      - CreateNamespace=true
    retry:
      limit: 1
      backoff:
        duration: 5s
        factor: 2
        maxDuration: 1m
{{- end -}}
jasonwbarnett commented 4 months ago

I originally tried the native helm format, i.e.

        - name: controller.podAnnotations."prometheus\.io/port"
          value: "10254"

That did not work, but it did work after dropping the quotes

        - name: controller.podAnnotations.prometheus\.io/port
          value: "10254"