Skip to content

ArgoCD and Helm Integration Fix: ApplicationSet Deployment #12646

@tomerle03

Description

@tomerle03

Output of helm version: v3.13.3

Output of kubectl version: 1.27.3

Cloud Provider/Platform (AKS, GKE, Minikube etc.): self-hosted

I utilize ArgoCD with an "app of apps" setup. For this purpose, I deploy my ApplicationSet using a Helm chart. The template appears as follows:

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: guestbook
spec:
  generators:
  - list:
      elements:
      - cluster: dev-cluster
        url: https://1.2.3.4
      - cluster: prod-cluster
        url: https://2.4.6.8
      - cluster: preprod-cluster
        url: https://9.8.7.6
  template:
    metadata:
      name: '{{cluster}}-guestbook'
    spec:
      project: default
      source:
        repoURL: https://github.com/argoproj/argo-cd.git
        targetRevision: HEAD
        path: "."
      destination:
        server: '{{url}}'
        namespace: guestbook

However, upon running helm template HELM_REPO, I encounter this error:
Error: parse error at (argocd-helm/templates/not-working.yaml:17): function "cluster" not defined

I discovered that deploying a YAML file with {{ }} as plain text causes issues because the Golang code attempts to evaluate its content.

how to overcome this problem:

I realized that both Helm and Argo utilities use Go templating. We actually want ArgoCD to interpret the {{cluster}} and not Helm.
To resolve this issue, we can employ Go templating within Helm by using:
'{{ printf "{{cluster}}" }}'. This "tricks" Helm into ignoring the initial curly braces and allows ArgoCD to interpret them correctly.

The revised ArgoCD ApplicationSet appears as follows:

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: guestbook
spec:
  generators:
  - list:
      elements:
      - cluster: dev-cluster
        url: https://1.2.3.4
      - cluster: prod-cluster
        url: https://2.4.6.8
      - cluster: preprod-cluster
        url: https://9.8.7.6
  template:
    metadata:
      name: '{{ printf "{{cluster}}" }}-guestbook'
    spec:
      project: default
      source:
        repoURL: https://github.com/argoproj/argo-cd.git
        targetRevision: HEAD
        path: "."
      destination:
        server: '{{ printf "{{url}}" }}'
        namespace: guestbook

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions