From e75c766acd0b9a2e34e18a9006423de13e357268 Mon Sep 17 00:00:00 2001 From: shuting Date: Fri, 31 Mar 2023 19:56:32 +0800 Subject: [PATCH] add new test (#6752) Signed-off-by: ShutingZhao --- .../01-manifests.yaml | 12 +++++++ .../02-assert.yaml | 9 ++++++ .../02-policy.yaml | 32 +++++++++++++++++++ .../03-assert.yaml | 9 ++++++ .../03-pod.yaml | 9 ++++++ .../README.md | 11 +++++++ 6 files changed, 82 insertions(+) create mode 100644 test/conformance/kuttl/mutate/e2e/foreach-patchStrategicMerge-context/01-manifests.yaml create mode 100644 test/conformance/kuttl/mutate/e2e/foreach-patchStrategicMerge-context/02-assert.yaml create mode 100644 test/conformance/kuttl/mutate/e2e/foreach-patchStrategicMerge-context/02-policy.yaml create mode 100644 test/conformance/kuttl/mutate/e2e/foreach-patchStrategicMerge-context/03-assert.yaml create mode 100644 test/conformance/kuttl/mutate/e2e/foreach-patchStrategicMerge-context/03-pod.yaml create mode 100644 test/conformance/kuttl/mutate/e2e/foreach-patchStrategicMerge-context/README.md diff --git a/test/conformance/kuttl/mutate/e2e/foreach-patchStrategicMerge-context/01-manifests.yaml b/test/conformance/kuttl/mutate/e2e/foreach-patchStrategicMerge-context/01-manifests.yaml new file mode 100644 index 0000000000..bd785469fb --- /dev/null +++ b/test/conformance/kuttl/mutate/e2e/foreach-patchStrategicMerge-context/01-manifests.yaml @@ -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 \ No newline at end of file diff --git a/test/conformance/kuttl/mutate/e2e/foreach-patchStrategicMerge-context/02-assert.yaml b/test/conformance/kuttl/mutate/e2e/foreach-patchStrategicMerge-context/02-assert.yaml new file mode 100644 index 0000000000..f8af584a54 --- /dev/null +++ b/test/conformance/kuttl/mutate/e2e/foreach-patchStrategicMerge-context/02-assert.yaml @@ -0,0 +1,9 @@ +apiVersion: kyverno.io/v1 +kind: ClusterPolicy +metadata: + name: foreach-patchstrategicmerge-context-policy +status: + conditions: + - reason: Succeeded + status: "True" + type: Ready diff --git a/test/conformance/kuttl/mutate/e2e/foreach-patchStrategicMerge-context/02-policy.yaml b/test/conformance/kuttl/mutate/e2e/foreach-patchStrategicMerge-context/02-policy.yaml new file mode 100644 index 0000000000..577c8f18cc --- /dev/null +++ b/test/conformance/kuttl/mutate/e2e/foreach-patchStrategicMerge-context/02-policy.yaml @@ -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 }}" diff --git a/test/conformance/kuttl/mutate/e2e/foreach-patchStrategicMerge-context/03-assert.yaml b/test/conformance/kuttl/mutate/e2e/foreach-patchStrategicMerge-context/03-assert.yaml new file mode 100644 index 0000000000..78031686e9 --- /dev/null +++ b/test/conformance/kuttl/mutate/e2e/foreach-patchStrategicMerge-context/03-assert.yaml @@ -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 \ No newline at end of file diff --git a/test/conformance/kuttl/mutate/e2e/foreach-patchStrategicMerge-context/03-pod.yaml b/test/conformance/kuttl/mutate/e2e/foreach-patchStrategicMerge-context/03-pod.yaml new file mode 100644 index 0000000000..e53c9606f1 --- /dev/null +++ b/test/conformance/kuttl/mutate/e2e/foreach-patchStrategicMerge-context/03-pod.yaml @@ -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 \ No newline at end of file diff --git a/test/conformance/kuttl/mutate/e2e/foreach-patchStrategicMerge-context/README.md b/test/conformance/kuttl/mutate/e2e/foreach-patchStrategicMerge-context/README.md new file mode 100644 index 0000000000..baab403c4c --- /dev/null +++ b/test/conformance/kuttl/mutate/e2e/foreach-patchStrategicMerge-context/README.md @@ -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 \ No newline at end of file