github.com/argoproj/argo-cd/v3@v3.2.1/docs/operator-manual/applicationset/Generators-Post-Selector.md (about) 1 # Post Selector all generators 2 3 The `selector` field on a generator allows an `ApplicationSet` to post-filter results using [the Kubernetes common labelSelector format](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors) and the generated values. 4 5 `matchLabels` is a map of `{key,value}` pairs. This `list` generator generates a set of two `Applications`, which is then filtered using `matchLabels` to only the list element containing the key `env` with value `staging`: 6 ``` 7 spec: 8 generators: 9 - list: 10 elements: 11 - cluster: engineering-dev 12 url: https://kubernetes.default.svc 13 env: staging 14 - cluster: engineering-prod 15 url: https://kubernetes.default.svc 16 env: prod 17 selector: 18 matchLabels: 19 env: staging 20 ``` 21 22 The `list` generator + `matchLabels` selector generates a single set of parameters: 23 ```yaml 24 - cluster: engineering-dev 25 url: https://kubernetes.default.svc 26 env: staging 27 ``` 28 29 It is also possible to use `matchExpressions` for more powerful selectors. 30 31 A single `{key,value}` in the `matchLabels` map is equivalent to an element of `matchExpressions`, whose `key` field is the "key", the `operator` is "In", and the `values` array contains only the "value". So the same example using `matchExpressions` looks like: 32 ```yaml 33 spec: 34 generators: 35 - list: 36 elements: 37 - cluster: engineering-dev 38 url: https://kubernetes.default.svc 39 env: staging 40 - cluster: engineering-prod 41 url: https://kubernetes.default.svc 42 env: prod 43 selector: 44 matchExpressions: 45 - key: env 46 operator: In 47 values: 48 - staging 49 ``` 50 51 Valid `operators` include `In`, `NotIn`, `Exists`, and `DoesNotExist`. The `values` set must be non-empty in the case of `In` and `NotIn`. 52 53 ## Full Example 54 In the example, the list generator generates a set of two applications, which then filter by the key value to only select the `env` with value `staging`: 55 ```yaml 56 apiVersion: argoproj.io/v1alpha1 57 kind: ApplicationSet 58 metadata: 59 name: guestbook 60 spec: 61 goTemplate: true 62 goTemplateOptions: ["missingkey=error"] 63 generators: 64 - list: 65 elements: 66 - cluster: engineering-dev 67 url: https://kubernetes.default.svc 68 env: staging 69 - cluster: engineering-prod 70 url: https://kubernetes.default.svc 71 env: prod 72 selector: 73 matchLabels: 74 env: staging 75 template: 76 metadata: 77 name: '{{.cluster}}-guestbook' 78 spec: 79 project: default 80 source: 81 repoURL: https://github.com/argoproj-labs/applicationset.git 82 targetRevision: HEAD 83 path: examples/list-generator/guestbook/{{.cluster}} 84 destination: 85 server: '{{.url}}' 86 namespace: guestbook 87 ```