Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

elementsYaml is not working in nested matrix #16578

Open
3 tasks done
sangcom15 opened this issue Dec 8, 2023 · 2 comments
Open
3 tasks done

elementsYaml is not working in nested matrix #16578

sangcom15 opened this issue Dec 8, 2023 · 2 comments
Labels
bug Something isn't working component:applications-set Bulk application management related

Comments

@sangcom15
Copy link

sangcom15 commented Dec 8, 2023

Checklist:

  • I've searched in the docs and FAQ for my answer: https://bit.ly/argocd-faq.
  • I've included steps to reproduce the bug.
  • I've pasted the output of argocd version.

Describe the bug

I was trying to use 'elementsYaml' of list generator. i referred to https://argo-cd.readthedocs.io/en/release-2.9/operator-manual/applicationset/Generators-List/#dynamically-generated-elements and it worked.
But when i use 'elementsYaml' of list generator in nested matrix, it is not working with the error message below.
failed to get params for second generator in the matrix generator: child generator returned an error on parameter generation: failed to replace parameters in generator: failed to execute go template {{ .app.charts | toJson }}: template: :1:7: executing "" at <.app.charts>: map has no entry for key "app"

To Reproduce

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: s01-env
  namespace: argocd
  annotations:
    argocd.argoproj.io/sync-wave: "0"
  labels:
    appName: s01
spec:
  goTemplate: true
  goTemplateOptions: ["missingkey=error"]
  syncPolicy: {}
  generators:
    - matrix:
        generators:
          - pullRequest:
              github:
                owner: myorg
                repo: dev-env
                api: https://github.mycompany.com/api/v3/
                tokenRef:
                  secretName: argocd-repo-creds-github
                  key: password
                labels:
                - deploy
              requeueAfterSeconds: 30
          - matrix:
              generators:
                - git:
                    repoURL: https://github.mycompany.com/myorg/dev-env.git
                    revision: '{{.head_sha}}'
                    files:
                      - path: configs/config.yaml
                    requeueAfterSeconds: 30
                - list: # charts
                    elements: []
                    elementsYaml: "{{ .app.charts | toJson }}"
  template:
    metadata:
      name: 'app-{{.app.env.project}}-{{.branch_slug}}-{{.number}}-{{.releaseName}}'
      namespace: argocd
      labels:
        app: 'app-{{.app.env.project}}-{{.branch_slug}}-{{.number}}-{{.releaseName}}'
      finalizers:
        - resources-finalizer.argocd.argoproj.io
    spec:
      project: my-dev-envs
      destination:
        namespace: '{{.app.env.cluster.namespace}}'
        server: '{{.app.env.cluster.server}}'
      source:
        repoURL: '{{.app.env.srcRepoURL}}'
        targetRevision: '{{default .app.env.srcTargetRevision .srcTargetRevision}}'
        path: 'apps/{{.type}}-charts/{{.name}}'
        helm:
          releaseName: '{{.releaseName}}'
          values: |
            {{default "" .values}}
          parameters:
            - name: pr_branch
              value: '{{.branch}}'
            - name: pr_branch_slug
              value: '{{.branch_slug}}'
            - name: pr_number
              value: '{{.number}}'
            - name: pr_head_sha
              value: '{{.head_sha}}'
            - name: pr_labels
              value: '{{index .labels 0}}'
      syncPolicy:
        automated:
          allowEmpty: true
          prune: true
          selfHeal: true
        syncOptions:
          - CreateNamespace=true

The configs/config.yaml file:

app:
  env:
    project: "dev"
    name: "s01"
    servicePhase: "dev"
    infra:
      vendor: "aws"
      accountID: "123456789"
    cluster:
      name: "dev-s01"
      region: "ap-northeast-2"
      server: "https://XXXXXXXXXXXXXXXXXXX.xxx.ap-northeast-2.eks.amazonaws.com"
      namespace: "s01"
    srcRepoURL: "https://github.mycompany.com/myorg/dev-env.git"
    srcTargetRevision: "main"

  charts:
    - releaseName: "secrets"
      name: "externalSecrets"
      type: "pre-required"
      srcTargetRevision: "{{.branch}}"
      values: |
        nameOverride: "dev-configs"
    - releaseName: "etcd"
      name: "etcd"
      type: "general"
      srcTargetRevision: "{{.branch}}"
    - releaseName: "dynamodb-local"
      name: "dynamodb-local"
      type: "general"
      srcTargetRevision: "{{.branch}}"
    - releaseName: "redis"
      name: "redis-cluster"
      type: "general"
      srcTargetRevision: "{{.branch}}"
    - releaseName: "rabbitmq"
      name: "rabbitmq"
      type: "general"
      srcTargetRevision: "{{.branch}}"  

Expected behavior

application set will deploy applications when PR is created.

Version

{
    "Version": "v2.9.3+6eba5be",
    "BuildDate": "2023-12-01T23:05:50Z",
    "GitCommit": "6eba5be864b7e031871ed7698f5233336dfe75c7",
    "GitTreeState": "clean",
    "GoVersion": "go1.21.3",
    "Compiler": "gc",
    "Platform": "linux/amd64",
    "KustomizeVersion": "v5.2.1 2023-10-19T20:13:51Z",
    "HelmVersion": "v3.13.2+g2a2fb3b",
    "KubectlVersion": "v0.24.2",
    "JsonnetVersion": "v0.20.0"
}
@sangcom15 sangcom15 added the bug Something isn't working label Dec 8, 2023
@todaywasawesome todaywasawesome added the component:applications-set Bulk application management related label Dec 11, 2023
@Matteo099
Copy link

I'm encountering the same issue. Are there any updates on its status?

@nastacio
Copy link

Thank you for the trick with elements: [], as the instructions don't mention it (probably some pending fix in the code)

I got your example to work with one important change: move the charts element from under app to the top of the YAML file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working component:applications-set Bulk application management related
Projects
None yet
Development

No branches or pull requests

4 participants