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

chore: add cascading kuttl test (#6425)

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
Charles-Edouard Brétéché 2023-02-28 16:27:27 +01:00 committed by GitHub
parent efae284745
commit 5585ed5e9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 76 additions and 0 deletions

View file

@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- policy.yaml
assert:
- policy-assert.yaml

View file

@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- file: configmap.yaml
assert:
- configmap-assert.yaml

View file

@ -0,0 +1,9 @@
## Description
This test creates a policy with two mutation rules.
The second rule depends on the mutation in the first rule.
To succeed, the changes in the first mutation rule need to cascade correctly to get the second rule to execute correctly.
## Related issue
https://github.com/kyverno/kyverno/issues/6210

View file

@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: cm
annotations:
mutation1: '1'
mutation2: 'found mutation1: 1'

View file

@ -0,0 +1,4 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: cm

View file

@ -0,0 +1,9 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: mutate-chain
status:
conditions:
- reason: Succeeded
status: 'True'
type: Ready

View file

@ -0,0 +1,35 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: mutate-chain
spec:
background: false
validationFailureAction: Enforce
rules:
- name: mutation1
match:
all:
- resources:
kinds:
- v1/ConfigMap
mutate:
foreach:
- list: "['dummy']"
patchStrategicMerge:
metadata:
annotations:
# value is a counter in case K8s decides for multiple mutation rounds
mutation1: "{{ not_null(request.object.metadata.annotations.mutation1, '0') | add(@, '1') }}"
- name: mutation2
match:
all:
- resources:
kinds:
- v1/ConfigMap
mutate:
foreach:
- list: "['dummy']"
patchStrategicMerge:
metadata:
annotations:
mutation2: "found mutation1: {{ request.object.metadata.annotations.mutation1 || '<nothing>' }}"