github.com/argoproj/argo-cd/v2@v2.10.9/docs/operator-manual/applicationset/Generators-List.md (about) 1 # List Generator 2 3 The List generator generates parameters based on an arbitrary list of key/value pairs (as long as the values are string values). In this example, we're targeting a local cluster named `engineering-dev`: 4 ```yaml 5 apiVersion: argoproj.io/v1alpha1 6 kind: ApplicationSet 7 metadata: 8 name: guestbook 9 namespace: argocd 10 spec: 11 goTemplate: true 12 goTemplateOptions: ["missingkey=error"] 13 generators: 14 - list: 15 elements: 16 - cluster: engineering-dev 17 url: https://kubernetes.default.svc 18 - cluster: engineering-prod 19 url: https://kubernetes.default.svc 20 template: 21 metadata: 22 name: '{{.cluster}}-guestbook' 23 spec: 24 project: "my-project" 25 source: 26 repoURL: https://github.com/argoproj/argo-cd.git 27 targetRevision: HEAD 28 path: applicationset/examples/list-generator/guestbook/{{.cluster}} 29 destination: 30 server: '{{.url}}' 31 namespace: guestbook 32 ``` 33 (*The full example can be found [here](https://github.com/argoproj/argo-cd/tree/master/applicationset/examples/list-generator).*) 34 35 In this example, the List generator passes the `url` and `cluster` fields as parameters into the template. If we wanted to add a second environment, we could uncomment the second element and the ApplicationSet controller would automatically target it with the defined application. 36 37 With the ApplicationSet v0.1.0 release, one could *only* specify `url` and `cluster` element fields (plus arbitrary `values`). As of ApplicationSet v0.2.0, any key/value `element` pair is supported (which is also fully backwards compatible with the v0.1.0 form): 38 ```yaml 39 spec: 40 generators: 41 - list: 42 elements: 43 # v0.1.0 form - requires cluster/url keys: 44 - cluster: engineering-dev 45 url: https://kubernetes.default.svc 46 values: 47 additional: value 48 # v0.2.0+ form - does not require cluster/URL keys 49 # (but they are still supported). 50 - staging: "true" 51 gitRepo: https://kubernetes.default.svc 52 # (...) 53 ``` 54 55 !!! note "Clusters must be predefined in Argo CD" 56 These clusters *must* already be defined within Argo CD, in order to generate applications for these values. The ApplicationSet controller does not create clusters within Argo CD (for instance, it does not have the credentials to do so). 57 58 ## Dynamically generated elements 59 The List generator can also dynamically generate its elements based on a yaml/json it gets from a previous generator like git by combining the two with a matrix generator. In this example we are using the matrix generator with a git followed by a list generator and pass the content of a file in git as input to the `elementsYaml` field of the list generator: 60 ```yaml 61 apiVersion: argoproj.io/v1alpha1 62 kind: ApplicationSet 63 metadata: 64 name: elementsYaml 65 namespace: argocd 66 spec: 67 goTemplate: true 68 goTemplateOptions: ["missingkey=error"] 69 generators: 70 - matrix: 71 generators: 72 - git: 73 repoURL: https://github.com/argoproj/argo-cd.git 74 revision: HEAD 75 files: 76 - path: applicationset/examples/list-generator/list-elementsYaml-example.yaml 77 - list: 78 elementsYaml: "{{ .key.components | toJson }}" 79 template: 80 metadata: 81 name: '{{.name}}' 82 spec: 83 project: default 84 syncPolicy: 85 automated: 86 selfHeal: true 87 syncOptions: 88 - CreateNamespace=true 89 sources: 90 - chart: '{{.chart}}' 91 repoURL: '{{.repoUrl}}' 92 targetRevision: '{{.version}}' 93 helm: 94 releaseName: '{{.releaseName}}' 95 destination: 96 server: https://kubernetes.default.svc 97 namespace: '{{.namespace}}' 98 ``` 99 100 where `list-elementsYaml-example.yaml` content is: 101 ```yaml 102 key: 103 components: 104 - name: component1 105 chart: podinfo 106 version: "6.3.2" 107 releaseName: component1 108 repoUrl: "https://stefanprodan.github.io/podinfo" 109 namespace: component1 110 - name: component2 111 chart: podinfo 112 version: "6.3.3" 113 releaseName: component2 114 repoUrl: "ghcr.io/stefanprodan/charts" 115 namespace: component2 116 ```