argoproj / argo-cd

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

ApplicationSet Fails to Create All Resources When Sourced from Helm Chart with Templates Looping from values.yml #20895

Open ratkokorlevski-rldatix opened 19 hours ago

ratkokorlevski-rldatix commented 19 hours ago

Description and steps to reproduce:

folder structure:

/project-onboarding
|- appset-projects.yaml               # ArgoCD ApplicationSet manifest
|- /projects                            # Helm chart directory
   |- Chart.yaml                      # Helm chart metadata
   |- values.yaml                     # Default Helm values
   |- /templates                      # Helm templates
      |- app-set.yaml                 # Template for ApplicationSet
      |- app-project.yaml             # Template for projects

I have ApplicationSet where the source is fetched from a source helm chart in a Github repostory:

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: projects
  namespace: argocd
  annotations:
    argocd.argoproj.io/sync-wave: "3"
spec:
  generators:
    - git:
        repoURL: https://github.com/myorg/myrepo.git
        revision: main
        directories:
          - path: projects

  template:
    metadata:
      name: projects
    spec:
      project: addons
      source:
        repoURL: https://github.com/myorg/myrepo.git
        targetRevision: main
        path: projects
      destination:
        server: https://kubernetes.default.svc
        namespace: argocd
      syncPolicy:
        automated:
          prune: true
          selfHeal: true

values file:

repositories:
  - url: https://github.com/product1-org/product1.git
    repo_token_ssm_parameter_path: /argocd/auth_password/addons
    name: "product1-repo"
    description: "product1 repo containing test EKS workloads"
  - url: https://github.com/product2-org/product2.git
    repo_token_ssm_parameter_path: /argocd/auth_password/addons
    name: "product2-repo"
    description: "product2 repo containing test EKS workloads"

projects:
  - name: project1
    description: "ArgoCD project for test-multiple-product-project"
    application_sets:
    - name: product1
      gitops_repository: https://github.com/product1-org/product1.git
      revision: develop
      path: examples/test-hybrid/test-gitops/product1
      destination:
        namespace: test
        server: "https://kubernetes.default.svc"
    - name: product2
      gitops_repository: https://github.com/product2-org/product1.git
      revision: develop
      path: examples/test-hybrid/test-gitops/product2
      destination:
        namespace: test
        server: "https://kubernetes.default.svc"

  - name: project2
    description: "ArgoCD project for test-multiple-product-project"
    application_sets:
    - name: product1
      gitops_repository: https://github.com/product1-org/product1.git
      revision: develop
      path: examples/test-hybrid/test-gitops/product1
      destination:
        namespace: test
        server: "https://kubernetes.default.svc"
    - name: product2
      gitops_repository:https://github.com/product1-org/product2.git
      revision: develop
      path: examples/test-hybrid/test-gitops/product2
      destination:
        namespace: test
        server: "https://kubernetes.default.svc"

**TEMPLATES:

app-set.yml**

{{- range .Values.projects }}
  {{- $projectName := .name }}
  {{- range .application_sets }}
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: {{ $projectName }}-{{ .name }}
  namespace: argocd
  annotations:
    argocd.argoproj.io/sync-wave: "{{ .syncWave | default 3 }}"
spec:
  generators:
    - clusters: {}
  template:
    metadata:
      name: {{ $projectName }}-{{ .name }}
    spec:
      project: {{ $projectName }}
      source:
        repoURL: {{ .gitops_repository }}
        targetRevision: {{ .revision | default "main" }}
        path: {{ .path }}
      destination:
        server: {{ .destination.server | default "https://kubernetes.default.svc" }}
        namespace: {{ .destination.namespace }}
{{- end }}
{{- end }}

app-projects.yml

{{- range .Values.projects }}
apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
  name: {{ .name }}
  namespace: argocd
spec:
  description: {{ .description }}
  sourceRepos:
    - '*'
  destinations:
    - namespace: '*'
      server: 'https://kubernetes.default.svc'
  clusterResourceWhitelist:
    - group: '*'
      kind: '*'
  namespaceResourceWhitelist:
    - group: '*'
      kind: '*'
  roles:
    - name: masters-only
      policies:
        - p, proj:{{ .name }}:masters-only, applications, *, allow
      groups:
        - system:master
{{- end }}

So with this setup, my expectations are ArgoCD to create multiple projects and multiple application sets. To be specific

2 Projects: project1 and project2 4 applicationsets: 2 per project

If i run helm template locally, I am getting the desired output.

THE ISSUE: ArgoCD creates only the last item of the loop. So it creates only 1project - project2 and only 1 applicationset - project2.product2

Version 2.10.2