Skip to content

Commit 3712054

Browse files
authored
docs for kpt fn exclude (#3022)
1 parent 724ca71 commit 3712054

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

site/book/04-using-functions/01-declarative-function-execution.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,86 @@ Successfully executed 5 function(s) in 2 package(s).
325325
Note that the `ensure-name-substring` function is applied only to the
326326
resources matching the selection criteria.
327327

328+
If you have resources with particular labels or annotations that you want to use to
329+
select your resources, you can do so. For example, here is a function that will only
330+
be applied to resources matching the label `foo: bar`:
331+
332+
```yaml
333+
apiVersion: kpt.dev/v1
334+
kind: Kptfile
335+
metadata:
336+
name: wordpress
337+
pipeline:
338+
mutators:
339+
- image: gcr.io/kpt-fn/set-annotations:v0.1
340+
configMap:
341+
tier: mysql
342+
selectors:
343+
- labels:
344+
foo: bar
345+
validators:
346+
- image: gcr.io/kpt-fn/kubeval:v0.1
347+
```
348+
328349
The following are the matchers you can specify in a selector:
329350

330351
1. `apiVersion`: `apiVersion` field value of resources to be selected.
331352
2. `kind`: `kind` field value of resources to be selected.
332353
3. `name`: `metadata.name` field value of resources to be selected.
333354
4. `namespace`: `metadata.namespace` field of resources to be selected.
355+
5. `annotations`: resources with matching annotations will be selected.
356+
6. `labels`: resources with matching labels will be selected.
357+
358+
### Specifying exclusions
359+
360+
Similar to `selectors`, you can also specify resources that should be excluded from functions.
361+
362+
For example, you can exclude a resource if it has both kind "Deployment" and name "nginx":
363+
364+
```yaml
365+
apiVersion: kpt.dev/v1
366+
kind: Kptfile
367+
metadata:
368+
name: wordpress
369+
pipeline:
370+
mutators:
371+
- image: gcr.io/kpt-fn/set-annotations:v0.1
372+
configMap:
373+
tier: mysql
374+
exclude:
375+
- kind: Deployment
376+
name: nginx
377+
validators:
378+
- image: gcr.io/kpt-fn/kubeval:v0.1
379+
```
380+
381+
This is distinct from the following, which excludes a resource if it has either kind "Deployment" or name "nginx":
382+
383+
```yaml
384+
apiVersion: kpt.dev/v1
385+
kind: Kptfile
386+
metadata:
387+
name: wordpress
388+
pipeline:
389+
mutators:
390+
- image: gcr.io/kpt-fn/set-annotations:v0.1
391+
configMap:
392+
tier: mysql
393+
exclude:
394+
- kind: Deployment
395+
- name: nginx
396+
validators:
397+
- image: gcr.io/kpt-fn/kubeval:v0.1
398+
```
399+
400+
The following are the matchers you can specify in an exclusion:
401+
402+
1. `apiVersion`: `apiVersion` field value of resources to be excluded.
403+
2. `kind`: `kind` field value of resources to be excluded.
404+
3. `name`: `metadata.name` field value of resources to be excluded.
405+
4. `namespace`: `metadata.namespace` field of resources to be excluded.
406+
5. `annotations`: resources with matching annotations will be excluded.
407+
6. `labels`: resources with matching labels will be excluded.
334408

335409
[chapter 2]: /book/02-concepts/03-functions
336410
[render-doc]: /reference/cli/fn/render/

site/book/04-using-functions/02-imperative-function-execution.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,34 @@ Here is the list of available selector matcher flags:
101101
2. `match-kind`
102102
3. `match-name`
103103
4. `match-namespace`
104+
5. `match-annotations`
105+
6. `match-labels`
106+
107+
## Specifying `exclusions`
108+
109+
Exclusions can be used to exclude specific resources for a function execution.
110+
111+
For example, you can set the namespace of all resources in the wordpress package,
112+
except for the ones with the label `foo: bar`:
113+
114+
```shell
115+
$ kpt fn eval wordpress -i set-namespace:v0.1 --exclude-labels foo=bar -- namespace=my-namespace
116+
```
117+
118+
If you use multiple exclusions, it will exclude resources that match all provided exclusions. For
119+
example, you can set the namespace of all resources, except for those that have both kind "Deployment"
120+
and name "nginx":
121+
122+
`$ kpt fn eval wordpress -i set-namespace:v0.1 --exclude-kind Deployment --exclude-name nginx -- namespace=my-namespace`
123+
124+
Here is the list of available exclusion flags:
125+
126+
1. `exclude-api-version`
127+
2. `exclude-kind`
128+
3. `exclude-name`
129+
4. `exclude-namespace`
130+
5. `exclude-annotations`
131+
6. `exclude-labels`
104132

105133
## Privileged Execution
106134

0 commit comments

Comments
 (0)