Skip to content

Commit

Permalink
docs: Mention that DELETE should be specified if mutation on deletion…
Browse files Browse the repository at this point in the history
… is required

Signed-off-by: aerosouund <[email protected]>
  • Loading branch information
aerosouund committed Sep 13, 2024
1 parent 66cd1a0 commit de671e1
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions content/en/docs/writing-policies/mutate.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,68 @@ spec:
imagePullPolicy: "IfNotPresent"
```
Starting from kyverno `v1.11.2`, rules with mutations that trigger on deletion of a resource will be skipped unless explicitly specified that the `DELETE` operation should match

For example, The following policy should add a label to a configmap when a deployment is created or updated

```yaml
apiVersion: kyverno.io/v1
kind: Policy
metadata:
name: mutate-configmap-on-undefined-deployment-operation
spec:
background: false
rules:
- name: mutate-configmap-on-undefined-deployment-operation
match:
all:
- resources:
kinds:
- Deployment
mutate:
targets:
- apiVersion: v1
kind: ConfigMap
name: example
namespace: example
patchesJson6902: |-
- path: "/metadata/labels/modified-by-kyverno"
op: add
value: "true"
```

To have it also run the mutation when the deployment is deleted, the policy should be modified as such

```yaml
apiVersion: kyverno.io/v1
kind: Policy
metadata:
name: mutate-configmap-on-undefined-deployment-operation
spec:
background: false
rules:
- name: mutate-configmap-on-undefined-deployment-operation
match:
all:
- resources:
kinds:
- Deployment
operations:
# add other operations if needed
- DELETE
mutate:
targets:
- apiVersion: v1
kind: ConfigMap
name: example
namespace: example
patchesJson6902: |-
- path: "/metadata/labels/modified-by-kyverno"
op: add
value: "true"
```

## RFC 6902 JSONPatch

A [JSON Patch](http://jsonpatch.com/), implemented as a mutation method called `patchesJson6902`, provides a precise way to mutate resources and supports the following operations (in the `op` field):
Expand Down

0 comments on commit de671e1

Please sign in to comment.