Skip to content

Commit

Permalink
Add for older kyverno version
Browse files Browse the repository at this point in the history
  • Loading branch information
Denish3436 committed Feb 21, 2025
1 parent e8030ae commit ae0cbbe
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions content/en/docs/writing-policies/mutate.md
Original file line number Diff line number Diff line change
Expand Up @@ -1187,15 +1187,41 @@ spec:
mutate:
foreach:
- list: request.object.spec.tls[]
as: element0
as: element0 # Outer loop element (tls array)
foreach:
- list: "element.hosts"
as: element1
as: element1 # Inner loop element (hosts array)
patchesJson6902: |-
- path: /spec/tls/{{elementIndex0}}/hosts/{{elementIndex1}}
op: replace
value: "{{ replace_all('{{element1}}', '.old.com', '.new.com') }}"
```
For older Kyverno versions that do not support as:, elements can be accessed directly using {{element0}} and {{element1}}.

```yaml
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: replace-dns-suffix-legacy
spec:
background: false
rules:
- name: replace-dns-suffix
match:
any:
- resources:
kinds:
- Ingress
mutate:
foreach:
- list: request.object.spec.tls[]
foreach:
- list: element.hosts
patchesJson6902: |-
- path: /spec/tls/{{elementIndex0}}/hosts/{{elementIndex1}}
op: replace
value: "{{ replace_all('{{element}}', '.old.com', '.new.com') }}"
```

## GitOps Considerations

Expand Down

0 comments on commit ae0cbbe

Please sign in to comment.