Skip to content

Commit 35702d9

Browse files
committed
Add CEL rules test suite
This patch adds several YAML test cases that check if the CEL rules included in the CRDs are correctly working. Both validation rules and transition rules are checked. A shell script is provided to execute these tests.
1 parent 0932517 commit 35702d9

File tree

104 files changed

+977
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+977
-0
lines changed

client/hack/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Scripts User Guide
22

33
This README documents:
4+
45
* What update-crd.sh and update-generated-code.sh do
56
* When and how to use them
7+
* The CRD CEL rules test suite
68

79
## update-generated-code.sh
810

@@ -104,3 +106,35 @@ Update the restoreSize property to use type string only:
104106
```
105107
106108
* Add the VolumeSnapshot namespace to the `additionalPrinterColumns` section in `client/config/crd/snapshot.storage.k8s.io_volumesnapshotcontents.yaml`. Refer https://github.com/kubernetes-csi/external-snapshotter/pull/535 for more details.
109+
110+
## Test suite
111+
112+
The `test-suite` directory contains several test cases that are useful to
113+
validate if the CEL rules that are included in the CRD definitions
114+
are correctly working.
115+
116+
### Prerequisites
117+
118+
- Kubectl access to a cluster with the installed CRDs
119+
- Kubernetes >= 1.29
120+
121+
### How to use it
122+
123+
```
124+
./hack/run-cel-tests.sh
125+
126+
cel-tests/volumegroupsnapshotcontent/vgsc-change-ref-namespace.post.yaml: SUCCESS
127+
cel-tests/volumegroupsnapshotcontent/vgsc-source-volume-to-groupsnapshot.post.yaml: SUCCESS
128+
cel-tests/volumegroupsnapshotcontent/vgsc-source-empty.yaml: SUCCEES (expected failure)
129+
cel-tests/volumegroupsnapshotcontent/vgsc-change-ref-namespace.pre.yaml: SUCCESS
130+
cel-tests/volumegroupsnapshotcontent/vgsc-ref-only-name.yaml: SUCCEES (expected failure)
131+
[...]
132+
cel-tests/volumegroupsnapshotcontent/vgsc-change-ref-namespace.pre.yaml -> cel-tests/volumegroupsnapshotcontent/vgsc-change-ref-namespace.post.yaml: SUCCEES (expected failure)
133+
cel-tests/volumegroupsnapshotcontent/vgsc-source-volume-immutable.pre.yaml -> cel-tests/volumegroupsnapshotcontent/vgsc-source-volume-immutable.post.yaml: SUCCEES (expected failure)
134+
cel-tests/volumegroupsnapshotcontent/vgsc-source-volume-to-groupsnapshot.pre.yaml -> cel-tests/volumegroupsnapshotcontent/vgsc-source-volume-to-groupsnapshot.post.yaml: SUCCEES (expected failure)
135+
cel-tests/volumegroupsnapshotcontent/vgsc-source-groupsnapshot-immutable.pre.yaml -> cel-tests/volumegroupsnapshotcontent/vgsc-source-groupsnapshot-immutable.post.yaml: SUCCEES (expected failure)
136+
[...]
137+
138+
SUCCESS: 90
139+
FAILURES: 0
140+
```

client/hack/cel-tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.out
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
apiVersion: groupsnapshot.storage.k8s.io/v1alpha1
3+
kind: VolumeGroupSnapshot
4+
metadata:
5+
name: new-groupsnapshot-demo
6+
spec:
7+
source:
8+
selector:
9+
matchLabels:
10+
app.kubernetes.io/name: postgresql
11+
volumeGroupSnapshotClassName: ""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
volumeGroupSnapshotClassName must not be the empty string when set
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
apiVersion: groupsnapshot.storage.k8s.io/v1alpha1
3+
kind: VolumeGroupSnapshot
4+
metadata:
5+
name: new-groupsnapshot-demo
6+
spec:
7+
source:
8+
volumeGroupSnapshotContentName: this-test-changed
9+
volumeGroupSnapshotClassName: csi-hostpath-groupsnapclass
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
volumeGroupSnapshotContentName is immutable
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
apiVersion: groupsnapshot.storage.k8s.io/v1alpha1
3+
kind: VolumeGroupSnapshot
4+
metadata:
5+
name: new-groupsnapshot-demo
6+
spec:
7+
source:
8+
volumeGroupSnapshotContentName: this-test
9+
volumeGroupSnapshotClassName: csi-hostpath-groupsnapclass
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
apiVersion: groupsnapshot.storage.k8s.io/v1alpha1
3+
kind: VolumeGroupSnapshot
4+
metadata:
5+
name: new-groupsnapshot-demo
6+
spec:
7+
source:
8+
selector:
9+
matchLabels:
10+
app.kubernetes.io/name: postgresql
11+
volumeGroupSnapshotClassName: csi-hostpath-groupsnapclass
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
volumeGroupSnapshotContentName is required once set
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
apiVersion: groupsnapshot.storage.k8s.io/v1alpha1
3+
kind: VolumeGroupSnapshot
4+
metadata:
5+
name: new-groupsnapshot-demo
6+
spec:
7+
source:
8+
volumeGroupSnapshotContentName: this-test
9+
volumeGroupSnapshotClassName: csi-hostpath-groupsnapclass

0 commit comments

Comments
 (0)