1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-29 10:55:05 +00:00

add new test (#6752)

Signed-off-by: ShutingZhao <shuting@nirmata.com>
This commit is contained in:
shuting 2023-03-31 19:56:32 +08:00 committed by GitHub
parent a243b405d2
commit e75c766acd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 82 additions and 0 deletions

View file

@ -0,0 +1,12 @@
apiVersion: v1
kind: Namespace
metadata:
name: foreach-patchstrategicmerge-context-ns
---
apiVersion: v1
data:
image: nginx
kind: ConfigMap
metadata:
name: foreach-patchstrategicmerge-context-configmap
namespace: foreach-patchstrategicmerge-context-ns

View file

@ -0,0 +1,9 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: foreach-patchstrategicmerge-context-policy
status:
conditions:
- reason: Succeeded
status: "True"
type: Ready

View file

@ -0,0 +1,32 @@
apiVersion : kyverno.io/v1
kind: ClusterPolicy
metadata:
name: foreach-patchstrategicmerge-context-policy
spec:
background: false
rules:
- name: resolve-image-containers
match:
resources:
kinds:
- Pod
preconditions:
all:
- key: "{{request.operation}}"
operator: In
value:
- CREATE
- UPDATE
mutate:
foreach:
- list: "request.object.spec.containers"
context:
- name: dictionary
configMap:
name: foreach-patchstrategicmerge-context-configmap
namespace: foreach-patchstrategicmerge-context-ns
patchStrategicMerge:
spec:
containers:
- name: "{{ element.name }}"
image: "{{ dictionary.data.image }}"

View file

@ -0,0 +1,9 @@
apiVersion: v1
kind: Pod
metadata:
name: foreach-patchstrategicmerge-context-pod
namespace: foreach-patchstrategicmerge-context-ns
spec:
containers:
- image: nginx
name: foreach-patchstrategicmerge-context-container

View file

@ -0,0 +1,9 @@
apiVersion: v1
kind: Pod
metadata:
name: foreach-patchstrategicmerge-context-pod
namespace: foreach-patchstrategicmerge-context-ns
spec:
containers:
- image: busybox
name: foreach-patchstrategicmerge-context-container

View file

@ -0,0 +1,11 @@
## Description
This test ensures that context look up works for mutate foreach.
## Expected Behavior
The pod image should be mutated to `nginx`.
## Reference Issue(s)
N/A