argoproj / argo-cd

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

ApplicationSet: Cannot use a list generator with Go templating in a matrix with git generator #16857

Open mihaigalos opened 8 months ago

mihaigalos commented 8 months ago

Checklist:

Describe the bug

It appears the list generator for ApplicationSet is broken when I try to use it directly in a matrix with a git generator. Putting it in another matrix generator with a dummy list generator works. Not putting it yields an ArgoCD error.

To Reproduce helm-appset.yaml:

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: "helm-appset"
  namespace: proj-argocd
spec:
  goTemplate: true
  goTemplateOptions: ["missingkey=error"]
  generators:
    - matrix:
        generators:
          - git:
              files:
                - path: core/*/component_helm.yaml
              repoURL: 'https://do.main/orga/proj-mono.git'
              requeueAfterSeconds: 300
              revision: HEAD
          - matrix:                  # 
              generators:            #
                - list:              # This block is necessary, cannot put the next list generator directly on the same level as the git generator.
                    elements:        #
                      - dummy: dummy #
                - list:
                    elementsYaml: |
                      {{- range $k, $v := .clusters }}
                      {{- range $stage := $v.stages }}
                      - appName: {{ $v.name }}-{{ $k }}-{{ $stage.name }}
                        appNamespace: {{ $v.namespace }}-{{ $k }}-{{ $stage.name }}
                        appRepoURL: {{ $v.repoURL }}
                        appTargetRevision: {{ $v.targetRevision }}
                        appStage: {{ $stage.name }}
                        clusterType: {{ $k }}
                      {{- end }}
                      {{- end }}
  template:
    metadata:
      name: '{{.appName}}'
    spec:
      project: 'proj'
      sources:
        - repoURL: '{{.appRepoURL}}'
          targetRevision: '{{.appTargetRevision}}'
          path: deployment
          helm:
            ignoreMissingValueFiles: true
            valueFiles:
              - $values/all/accounts/proj1.yaml
              - $values/{{index .path.segments 0}}/{{index .path.segments 1}}/values.yaml
              - $values/{{index .path.segments 0}}/{{index .path.segments 1}}/clusters/{{.clusterType}}.yaml
              - $values/{{index .path.segments 0}}/{{index .path.segments 1}}/stages/{{.clusterType}}-{{.appStage}}.yaml
        - repoURL: 'https://do.main/orga/proj-mono.git'
          targetRevision: HEAD
          ref: values
      destination:
        server: https://kubernetes.default.svc
        namespace: '{{.appNamespace}}'

component_helm.yaml:

clusters:
  dev:
    name: proj-dex
    namespace: proj-dex
    targetRevision: 2023.51.1
    repoURL: https://do.main/orga/proj-dex-manifest.git
    stages:
    - name: dev1
      nextCluster: dev
      nextStage: test1
    - name: test1
      nextCluster: test
      nextStage: dev1
  test:
    name: proj-dex
    namespace: proj-dex
    targetRevision: 2023.50.1
    repoURL: https://do.main/orga/proj-dex-manifest.git
    stages:
    - name: dev1
      nextCluster: test
      nextStage: test1
    - name: test1
      nextCluster: prod
      nextStage: prod1

Expected behavior

No need for a dummy list generator, generation of Apps. Screenshots

Version

v2.9.3

Logs

ArgoCD says:

ApplicationSet.argoproj.io "helm-appset" is invalid: spec.generators[0].matrix.generators[1].list.elements: Required value
sanggeepark-trustay commented 6 months ago

hey, me also have this error. Did you fix it?

gmauleon commented 6 months ago

Same, generating a list from a complex structure in a file would be handy.

mihaigalos commented 6 months ago

I did not fix it, I decided to not use it this way. I think the easiest way is to just use a plugin generator and write a Golang or Python backend as described in the docs.