Skip to content

Commit

Permalink
Clarify nested foreach referencing in Kyverno documentation
Browse files Browse the repository at this point in the history
Signed-off-by: Denish Tomar <[email protected]>
  • Loading branch information
Denish3436 committed Feb 14, 2025
1 parent 2502b20 commit e8030ae
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions content/en/docs/writing-policies/mutate.md
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ spec:
secretName: mytlscertsecret
```

This type of advanced mutation can be performed with nested foreach loops as shown below. Notice that in the JSON patch, the `path` value references the current index of `tls[]` as `{{elementIndex0}}` and the current index of `hosts[]` as `{{elementIndex1}}`. In the `value` field, the `{{element}}` variable still references the current value of the `hosts[]` array being processed.
This type of advanced mutation can be performed with nested foreach loops as shown below. Notice that in the JSON patch, the `path` value references the current index of `tls[]` as `{{elementIndex0}}` and the current index of `hosts[]` as `{{elementIndex1}}`. In the `value` field, the `{{element1}}` variable still references the current value of the `hosts[]` array being processed.

```yaml
apiVersion: kyverno.io/v1
Expand All @@ -1187,12 +1187,14 @@ spec:
mutate:
foreach:
- list: request.object.spec.tls[]
as: element0
foreach:
- list: "element.hosts"
as: element1
patchesJson6902: |-
- path: /spec/tls/{{elementIndex0}}/hosts/{{elementIndex1}}
op: replace
value: "{{ replace_all('{{element}}', '.old.com', '.new.com') }}"
value: "{{ replace_all('{{element1}}', '.old.com', '.new.com') }}"
```

## GitOps Considerations
Expand Down

0 comments on commit e8030ae

Please sign in to comment.