Skip to content

Commit 91c845d

Browse files
committed
test(charts): add helm unit tests for CRD and RBAC manifest generation
Add charts/kubewarden-controller/tests/rbac_roles_test.yaml to verify that the controller-gen-generated controller-rbac-roles.yaml contains the expected Helm labels and annotations on both the ClusterRole and Role resources, and that additionalLabels and additionalAnnotations values are propagated correctly. Add charts/kubewarden-crds/tests/crds_test.yaml to verify that each of the five Kubewarden CRD files renders as a CustomResourceDefinition with the correct metadata.name and spec.group. Update the helm-unittest Makefile target to include the kubewarden-crds chart. Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
1 parent a3e4027 commit 91c845d

3 files changed

Lines changed: 151 additions & 0 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ test-rust:
4747
.PHONY: helm-unittest
4848
helm-unittest:
4949
helm unittest charts/kubewarden-controller --file "tests/**/*_test.yaml"
50+
helm unittest charts/kubewarden-crds --file "tests/**/*_test.yaml"
5051

5152
.PHONY: test-e2e
5253
test-e2e: controller-image audit-scanner-image policy-server-image
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
suite: controller RBAC roles
2+
templates:
3+
- controller-rbac-roles.yaml
4+
release:
5+
namespace: "kubewarden"
6+
tests:
7+
- it: "ClusterRole should have Helm labels"
8+
documentSelector:
9+
path: kind
10+
value: ClusterRole
11+
asserts:
12+
- isNotNullOrEmpty:
13+
path: metadata.labels
14+
- equal:
15+
path: metadata.labels["app.kubernetes.io/component"]
16+
value: controller
17+
- equal:
18+
path: metadata.labels["app.kubernetes.io/part-of"]
19+
value: kubewarden
20+
- equal:
21+
path: metadata.labels["app.kubernetes.io/managed-by"]
22+
value: Helm
23+
24+
- it: "Role should have Helm labels"
25+
documentSelector:
26+
path: kind
27+
value: Role
28+
asserts:
29+
- isNotNullOrEmpty:
30+
path: metadata.labels
31+
- equal:
32+
path: metadata.labels["app.kubernetes.io/component"]
33+
value: controller
34+
- equal:
35+
path: metadata.labels["app.kubernetes.io/part-of"]
36+
value: kubewarden
37+
38+
- it: "ClusterRole should include additionalLabels when specified"
39+
set:
40+
additionalLabels:
41+
custom-label: "test-value"
42+
documentSelector:
43+
path: kind
44+
value: ClusterRole
45+
asserts:
46+
- equal:
47+
path: metadata.labels["custom-label"]
48+
value: "test-value"
49+
50+
- it: "Role should include additionalLabels when specified"
51+
set:
52+
additionalLabels:
53+
custom-label: "test-value"
54+
documentSelector:
55+
path: kind
56+
value: Role
57+
asserts:
58+
- equal:
59+
path: metadata.labels["custom-label"]
60+
value: "test-value"
61+
62+
- it: "ClusterRole should include additionalAnnotations when specified"
63+
set:
64+
additionalAnnotations:
65+
custom-annotation: "test-annotation"
66+
documentSelector:
67+
path: kind
68+
value: ClusterRole
69+
asserts:
70+
- equal:
71+
path: metadata.annotations["custom-annotation"]
72+
value: "test-annotation"
73+
74+
- it: "Role should include additionalAnnotations when specified"
75+
set:
76+
additionalAnnotations:
77+
custom-annotation: "test-annotation"
78+
documentSelector:
79+
path: kind
80+
value: Role
81+
asserts:
82+
- equal:
83+
path: metadata.annotations["custom-annotation"]
84+
value: "test-annotation"
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
suite: Kubewarden CRDs
2+
tests:
3+
- it: "admissionpolicies CRD should be a CustomResourceDefinition"
4+
template: admissionpolicies.yaml
5+
asserts:
6+
- equal:
7+
path: kind
8+
value: CustomResourceDefinition
9+
- equal:
10+
path: metadata.name
11+
value: admissionpolicies.policies.kubewarden.io
12+
- equal:
13+
path: spec.group
14+
value: policies.kubewarden.io
15+
16+
- it: "admissionpolicygroups CRD should be a CustomResourceDefinition"
17+
template: admissionpolicygroups.yaml
18+
asserts:
19+
- equal:
20+
path: kind
21+
value: CustomResourceDefinition
22+
- equal:
23+
path: metadata.name
24+
value: admissionpolicygroups.policies.kubewarden.io
25+
- equal:
26+
path: spec.group
27+
value: policies.kubewarden.io
28+
29+
- it: "clusteradmissionpolicies CRD should be a CustomResourceDefinition"
30+
template: clusteradmissionpolicies.yaml
31+
asserts:
32+
- equal:
33+
path: kind
34+
value: CustomResourceDefinition
35+
- equal:
36+
path: metadata.name
37+
value: clusteradmissionpolicies.policies.kubewarden.io
38+
- equal:
39+
path: spec.group
40+
value: policies.kubewarden.io
41+
42+
- it: "clusteradmissionpolicygroups CRD should be a CustomResourceDefinition"
43+
template: clusteradmissionpolicygroups.yaml
44+
asserts:
45+
- equal:
46+
path: kind
47+
value: CustomResourceDefinition
48+
- equal:
49+
path: metadata.name
50+
value: clusteradmissionpolicygroups.policies.kubewarden.io
51+
- equal:
52+
path: spec.group
53+
value: policies.kubewarden.io
54+
55+
- it: "policyservers CRD should be a CustomResourceDefinition"
56+
template: policyservers.yaml
57+
asserts:
58+
- equal:
59+
path: kind
60+
value: CustomResourceDefinition
61+
- equal:
62+
path: metadata.name
63+
value: policyservers.policies.kubewarden.io
64+
- equal:
65+
path: spec.group
66+
value: policies.kubewarden.io

0 commit comments

Comments
 (0)