Skip to content

Commit

Permalink
docs: expand appset post selector examples (#18257)
Browse files Browse the repository at this point in the history
Signed-off-by: Nicholas Morey <nicholas@morey.tech>
  • Loading branch information
morey-tech committed May 16, 2024
1 parent 5e6ca70 commit c9c3c1d
Showing 1 changed file with 51 additions and 25 deletions.
76 changes: 51 additions & 25 deletions docs/operator-manual/applicationset/Generators-Post-Selector.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,57 @@
# Post Selector all generators

The Selector allows to post-filter based on generated values using the Kubernetes common labelSelector format. In the example, the list generator generates a set of two application which then filter by the key value to only select the `env` with value `staging`:
The `selector` field on a generator allows an `ApplciationSet` 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.

## Example: List generator + Post Selector
`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`:
```
spec:
generators:
- list:
elements:
- cluster: engineering-dev
url: https://kubernetes.default.svc
env: staging
- cluster: engineering-prod
url: https://kubernetes.default.svc
env: prod
selector:
matchLabels:
env: staging
```

The `list` generator + `matchLabels` selector generates a single set of parameters:
```yaml
- cluster: engineering-dev
url: https://kubernetes.default.svc
env: staging
```
It is also possible to use `matchExpressions` for more powerful selectors.

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:
```yaml
spec:
generators:
- list:
elements:
- cluster: engineering-dev
url: https://kubernetes.default.svc
env: staging
- cluster: engineering-prod
url: https://kubernetes.default.svc
env: prod
selector:
matchExpressions:
- key: env
operator: In
values:
- staging
```

Valid `operators` include `In`, `NotIn`, `Exists`, and `DoesNotExist`. The `values` set must be non-empty in the case of `In` and `NotIn`.

## Full Example
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`:
```yaml
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
Expand Down Expand Up @@ -36,26 +85,3 @@ spec:
server: '{{.url}}'
namespace: guestbook
```
The List generator + Post Selector generates a single set of parameters:
```yaml
- cluster: engineering-dev
url: https://kubernetes.default.svc
env: staging
```
It is also possible to use `matchExpressions` for more powerful selectors.

```yaml
spec:
generators:
- clusters: {}
selector:
matchExpressions:
- key: server
operator: In
values:
- https://kubernetes.default.svc
- https://some-other-cluster
```

0 comments on commit c9c3c1d

Please sign in to comment.