Skip to content

Commit ae0cbbe

Browse files
committed
Add for older kyverno version
1 parent e8030ae commit ae0cbbe

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

content/en/docs/writing-policies/mutate.md

+28-2
Original file line numberDiff line numberDiff line change
@@ -1187,15 +1187,41 @@ spec:
11871187
mutate:
11881188
foreach:
11891189
- list: request.object.spec.tls[]
1190-
as: element0
1190+
as: element0 # Outer loop element (tls array)
11911191
foreach:
11921192
- list: "element.hosts"
1193-
as: element1
1193+
as: element1 # Inner loop element (hosts array)
11941194
patchesJson6902: |-
11951195
- path: /spec/tls/{{elementIndex0}}/hosts/{{elementIndex1}}
11961196
op: replace
11971197
value: "{{ replace_all('{{element1}}', '.old.com', '.new.com') }}"
11981198
```
1199+
For older Kyverno versions that do not support as:, elements can be accessed directly using {{element0}} and {{element1}}.
1200+
1201+
```yaml
1202+
apiVersion: kyverno.io/v1
1203+
kind: ClusterPolicy
1204+
metadata:
1205+
name: replace-dns-suffix-legacy
1206+
spec:
1207+
background: false
1208+
rules:
1209+
- name: replace-dns-suffix
1210+
match:
1211+
any:
1212+
- resources:
1213+
kinds:
1214+
- Ingress
1215+
mutate:
1216+
foreach:
1217+
- list: request.object.spec.tls[]
1218+
foreach:
1219+
- list: element.hosts
1220+
patchesJson6902: |-
1221+
- path: /spec/tls/{{elementIndex0}}/hosts/{{elementIndex1}}
1222+
op: replace
1223+
value: "{{ replace_all('{{element}}', '.old.com', '.new.com') }}"
1224+
```
11991225

12001226
## GitOps Considerations
12011227

0 commit comments

Comments
 (0)