1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

feat: add the kuttl test for Policy (Namespaced) with generate rule, data, and sync (#6387)

* add the test

Signed-off-by: ShutingZhao <shuting@nirmata.com>

* update readme

Signed-off-by: ShutingZhao <shuting@nirmata.com>

---------

Signed-off-by: ShutingZhao <shuting@nirmata.com>
This commit is contained in:
shuting 2023-02-25 05:59:17 +08:00 committed by GitHub
parent 70acfb4af8
commit 3653130806
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 88 additions and 0 deletions

View file

@ -0,0 +1,33 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: pol-data-sync-modify-downstream
---
apiVersion: kyverno.io/v1
kind: Policy
metadata:
name: pol-data-sync
namespace: pol-data-sync-modify-downstream
spec:
rules:
- name: gen-zk
match:
any:
- resources:
kinds:
- Secret
generate:
synchronize: true
apiVersion: v1
kind: ConfigMap
name: zk-kafka-address
namespace: pol-data-sync-modify-downstream
data:
kind: ConfigMap
metadata:
labels:
somekey: somevalue
data:
ZK_ADDRESS: "192.168.10.10:2181,192.168.10.11:2181,192.168.10.12:2181"
KAFKA_ADDRESS: "192.168.10.13:9092,192.168.10.14:9092,192.168.10.15:9092"

View file

@ -0,0 +1,8 @@
apiVersion: v1
data:
foo: YmFy
kind: Secret
metadata:
name: test
namespace: pol-data-sync-modify-downstream
type: Opaque

View file

@ -0,0 +1,10 @@
apiVersion: v1
data:
KAFKA_ADDRESS: 192.168.10.13:9092,192.168.10.14:9092,192.168.10.15:9092
ZK_ADDRESS: 192.168.10.10:2181,192.168.10.11:2181,192.168.10.12:2181
kind: ConfigMap
metadata:
labels:
somekey: somevalue
name: zk-kafka-address
namespace: pol-data-sync-modify-downstream

View file

@ -0,0 +1,10 @@
apiVersion: v1
data:
KAFKA_ADDRESS: 192.168.10.13:9092,192.168.10.14:9092,192.168.10.15:9092
ZK_ADDRESS: modified
kind: ConfigMap
metadata:
labels:
somekey: somevalue
name: zk-kafka-address
namespace: pol-data-sync-modify-downstream

View file

@ -0,0 +1,5 @@
# A command can only run a single command, not a pipeline and not a script. The program called must exist on the system where the test is run.
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- command: sleep 3

View file

@ -0,0 +1,10 @@
apiVersion: v1
data:
KAFKA_ADDRESS: 192.168.10.13:9092,192.168.10.14:9092,192.168.10.15:9092
ZK_ADDRESS: 192.168.10.10:2181,192.168.10.11:2181,192.168.10.12:2181
kind: ConfigMap
metadata:
labels:
somekey: somevalue
name: zk-kafka-address
namespace: pol-data-sync-modify-downstream

View file

@ -0,0 +1,12 @@
## Description
This test ensures that modification of the downstream (cloned/generated) resource used by a Policy `generate` rule with sync enabled using a data declaration causes those changes to be reverted and synchronized from the state of the upstream/source.
## Expected Behavior
After the downstream resource is modified, the changes should be reverted after synchronization occurs. If the downstream resource is synced with the state of the source resource, the test passes. If the downstream resource remains in a modified state, the test fails.
## Reference Issue(s)
https://github.com/kyverno/kyverno/issues/5764