-
Notifications
You must be signed in to change notification settings - Fork 2
/
kyverno-policy.yaml
40 lines (40 loc) · 1.15 KB
/
kyverno-policy.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: kubernetes-gcr-to-registry
spec:
background: false
rules:
- name: replace-image-registry-pod-containers
match:
any:
- resources:
kinds:
- Pod
mutate:
foreach:
- list: "request.object.spec.containers"
patchStrategicMerge:
spec:
containers:
- name: "{{ element.name }}"
image: "{{ replace_all('{{element.image}}', 'k8s.gcr.io', 'registry.k8s.io' )}}"
- name: replace-image-registry-pod-initcontainers
match:
any:
- resources:
kinds:
- Pod
preconditions:
all:
- key: "{{ request.object.spec.initContainers[] || `[]` | length(@) }}"
operator: GreaterThanOrEquals
value: 1
mutate:
foreach:
- list: "request.object.spec.initContainers"
patchStrategicMerge:
spec:
initContainers:
- name: "{{ element.name }}"
image: "{{ replace_all('{{element.image}}', 'k8s.gcr.io', 'registry.k8s.io' )}}"