argoproj / argo-cd

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

Cannot template first child of matrix generator inside first child of merge generator #18430

Open wanddynosios opened 4 months ago

wanddynosios commented 4 months ago

Checklist:

Describe the bug It appears not to be possible to gotemplate anything inside the first child of a matrix generator inside the first element of a merge generator.

To Reproduce

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: test
spec:
  generators:
  - merge:
      mergeKeys:
        - 'clust'
      generators:
        - matrix:
            generators:
                - git:
                    files:
                    - path: argo/v1/*/*/helm-config.yaml
                    repoURL: https://github.com/wanddynosios/argo-test
                    revision: '{{default "main" "main"}}' # <<<<<<<<-----------------------------
                    pathParamPrefix: prefix
                - list:
                    elements:
                    - clust: '{{index .prefix.path.segments 3}}'
                      applicat: '{{index .prefix.path.segments 2}}'
        - matrix:
            generators:
                - pullRequest:
                    github:
                      # The GitHub organization or user.
                      owner: wanddynosios
                      # The Github repository
                      repo: argo-test
                      labels:
                      - preview
                    requeueAfterSeconds: 1800
                - list:
                    elements:
                    - clust: '{{ trimPrefix "cluster=" (regexFind "cluster=([^\\s]+)" (trimAll "[]" (toString .labels))) }}'
                      applicat: '{{ trimPrefix "app=" (regexFind "app=([^\\s]+)" (trimAll "[]" (toString .labels))) }}'
  goTemplate: true
  template:
    metadata:
      name: animalfarm-{{.app.metadata.name}}-{{.prefix.path.basenameNormalized}}
      labels:
        applicat: '{{.applicat}}'
        clust: '{{.clust}}'
    spec:
      destination:
        name: '{{.prefix.path.basenameNormalized}}'
        namespace: default
      project: default
      sources:
      - chart: '{{.app.spec.source.chart}}'
        helm:
          ignoreMissingValueFiles: true
          skipCrds: true
          valueFiles:
          - $values/argo/v1/{{.app.metadata.name}}/{{.prefix.path.basenameNormalized}}/values.yaml
          values: '{{default "" .app.spec.source.helm.values}}'
        repoURL: '{{.app.spec.source.repoURL}}'
        targetRevision: '{{.app.spec.source.targetRevision}}'
      - ref: values
        repoURL: https://github.com/wanddynosios/argo-test
        targetRevision: main

produces an error: Unable to resolve '{{default "main" "main"}}' to a commit SHA

When I switch the git and the list generators in the matrix generator, I get those errors for the list generator, so it appears to always be the first one. However, the error does not appear in the second matrix generator.

I have added a few debug outputs to the applicationset-controller, and the critical section never passes through deeplyReplace. Expected behavior

It should be possible to gotemplate here.

Version

argocd: v2.11.2+25f7504
  BuildDate: 2024-05-23T15:31:09Z
  GitCommit: 25f7504ecc198e7d7fdc055fdb83ae50eee5edd0
  GitTreeState: clean
  GoVersion: go1.22.3
  Compiler: gc
  Platform: darwin/arm64

Logs

error getting param sets from generators: error getting params from generator 1 of 2: child generator returned an error on parameter generation: error failed to get params for first generator in matrix generator: child generator returned an error on parameter generation: error generating params from git: error retrieving Git files: rpc error: code = Internal desc = unable to resolve git revision : Unable to resolve '{{default "main" "main"}}' to a commit SHA

Slack link

steve-todorov commented 3 months ago

We are experiencing a similar problem with the git generator. In our case we want to be able to load additional properties stored in a separate repository. Here's an example:

        generators:
          - matrix:
              generators:
                - scmProvider:
                    cloneProtocol: ssh
                    github:
                      organization: xyz
                      allBranches: true
                      tokenRef:
                        secretName: github-token
                        key: token
                    filters:
                      - repositoryMatch: ^.*$
                        branchMatch: ^scm/([0-9]+).*$
                        pathsExist: [deployment/kubernetes/kustomization.yaml]

                - plugin:
                    configMapRef:
                      name: applicationset-branch-generator-plugin
                    input:
                      parameters:
                        branch: "{{.branch}}"
                    requeueAfterSeconds: 15

          - git:
              repoURL: "git@github.com:{{.organization}}/{{.repository}}.git"
              revision: "{{.branch}}"
              files:
                - path: "deployment/kubernetes/properties/{{.case_number}}.yml"

We've also tried various combinations:

  1. merge generator = [ scmProvider, matrix = [plugin, git] ]
  2. matrix generator = [ scmProvider, git] (just to be sure the custom plugin generator we have isn't the problem)
  3. matrix generator = [ scmProvider, merge = [plugin, git] ]

None of these combos work and it's a big blocker. Any ideas on how to fix this?

borisakov-rapyd commented 1 month ago

Facing the same issue in v2.12.0+ec30a48 version.

error failed to get params for first generator in matrix generator: child generator returned an error on parameter generation:

arturobrzut commented 1 month ago

Facing the same issue in v2.12.0+ec30a48 version. I have App which deploy AppSet which deploy App After deploy App is created correctly and it creates AppSet which also correct creates one App but after 4min (next reconciliation) I get message : error generating params from git: error retrieving Git files: rpc error: code = Internal desc = unable to resolve git revision :


time="2024-09-02T14:27:01Z" level=error msg="error generating params" error="error generating params from git: error retrieving Git files: rpc error: code = Internal desc │
│  = unable to resolve git revision : error creating SSH agent: \"SSH agent requested but SSH_AUTH_SOCK not-specified\"" generator="&{0xc000aa4d40}"                         │
│ time="2024-09-02T14:27:01Z" level=error msg="error generating application from params" applicationset=argocd/wxo error="error generating params from git: error retrieving │
│  Git files: rpc error: code = Internal desc = unable to resolve git revision : error creating SSH agent: \"SSH agent requested but SSH_AUTH_SOCK not-specified\"" generato │
│ r="{nil nil &GitGenerator{RepoURL:ssh://git@github.com/myrepo/edge-infra.git,Directories:[]GitDirectoryGeneratorItem{},Files:[]GitFileGeneratorItem{GitFileGenerator │
│ Item{Path:clusters/qa/**/cluster-config.yaml,},},Revision:HEAD,RequeueAfterSeconds:nil,Template:ApplicationSetTemplate{ApplicationSetTemplateMeta:ApplicationSetTemplateMe │
│ ta{Name:,Namespace:,Labels:map[string]string{},Annotations:map[string]string{},Finalizers:[],},Spec:ApplicationSpec{Source:nil,Destination:ApplicationDestination{Server:, │
│ Namespace:,Name:,},Project:,SyncPolicy:nil,IgnoreDifferences:[]ResourceIgnoreDifferences{},Info:[]Info{},RevisionHistoryLimit:nil,Sources:[]ApplicationSource{},},},PathPa │
│ ramPrefix:,Values:map[string]string{},} nil nil nil nil nil nil nil}" 
```                                                                                                     │
│                                                                          

  generators:
  - git:
      files:
      - path: clusters/qa/**/cluster-config.yaml
      repoURL: ssh://git@github.com/myrepo/edge-infra.git
      revision: master
config