-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathwebhooks_coverage_test.yaml
More file actions
299 lines (271 loc) · 9.66 KB
/
webhooks_coverage_test.yaml
File metadata and controls
299 lines (271 loc) · 9.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
suite: webhooks Helm templating coverage
templates:
- webhooks.yaml
release:
namespace: "kubewarden"
tests:
# ── Group 1: Resource names must be kubewarden-controller-prefixed, not plain controller-gen names ──
- it: "MutatingWebhookConfiguration should have the kubewarden-controller-prefixed name"
documentSelector:
path: kind
value: MutatingWebhookConfiguration
asserts:
- equal:
path: metadata.name
value: kubewarden-controller-mutating-webhook-configuration
- it: "ValidatingWebhookConfiguration should have the kubewarden-controller-prefixed name"
documentSelector:
path: kind
value: ValidatingWebhookConfiguration
asserts:
- equal:
path: metadata.name
value: kubewarden-controller-validating-webhook-configuration
# ── Group 2: Helm labels and annotations must be present on webhook configs ──
- it: "MutatingWebhookConfiguration should have Helm labels"
documentSelector:
path: kind
value: MutatingWebhookConfiguration
asserts:
- isNotNullOrEmpty:
path: metadata.labels
- equal:
path: metadata.labels["app.kubernetes.io/managed-by"]
value: Helm
- it: "ValidatingWebhookConfiguration should have Helm labels"
documentSelector:
path: kind
value: ValidatingWebhookConfiguration
asserts:
- isNotNullOrEmpty:
path: metadata.labels
- equal:
path: metadata.labels["app.kubernetes.io/managed-by"]
value: Helm
# ── Group 3: caBundle must be present on all webhooks ──
- it: "all mutating webhooks should have caBundle injected"
documentSelector:
path: kind
value: MutatingWebhookConfiguration
asserts:
- isNotNullOrEmpty:
path: webhooks[0].clientConfig.caBundle
- isNotNullOrEmpty:
path: webhooks[1].clientConfig.caBundle
- isNotNullOrEmpty:
path: webhooks[2].clientConfig.caBundle
- isNotNullOrEmpty:
path: webhooks[3].clientConfig.caBundle
- isNotNullOrEmpty:
path: webhooks[4].clientConfig.caBundle
- it: "all validating webhooks should have caBundle injected"
documentSelector:
path: kind
value: ValidatingWebhookConfiguration
asserts:
- isNotNullOrEmpty:
path: webhooks[0].clientConfig.caBundle
- isNotNullOrEmpty:
path: webhooks[1].clientConfig.caBundle
- isNotNullOrEmpty:
path: webhooks[2].clientConfig.caBundle
- isNotNullOrEmpty:
path: webhooks[3].clientConfig.caBundle
- isNotNullOrEmpty:
path: webhooks[4].clientConfig.caBundle
# ── Group 4: service.name must use the release name prefix, not plain 'webhook-service' ──
- it: "mutating webhooks should use release-prefixed service name, not plain 'webhook-service'"
documentSelector:
path: kind
value: MutatingWebhookConfiguration
asserts:
- matchRegex:
path: webhooks[0].clientConfig.service.name
pattern: "^.+-webhook-service$"
- notEqual:
path: webhooks[0].clientConfig.service.name
value: webhook-service
- it: "validating webhooks should use release-prefixed service name, not plain 'webhook-service'"
documentSelector:
path: kind
value: ValidatingWebhookConfiguration
asserts:
- matchRegex:
path: webhooks[0].clientConfig.service.name
pattern: "^.+-webhook-service$"
- notEqual:
path: webhooks[0].clientConfig.service.name
value: webhook-service
# ── Group 5: service.namespace must use the release namespace, not controller-gen's 'system' ──
- it: "mutating webhooks should use the release namespace, not 'system'"
documentSelector:
path: kind
value: MutatingWebhookConfiguration
asserts:
- equal:
path: webhooks[0].clientConfig.service.namespace
value: kubewarden
- notEqual:
path: webhooks[0].clientConfig.service.namespace
value: system
- it: "validating webhooks should use the release namespace, not 'system'"
documentSelector:
path: kind
value: ValidatingWebhookConfiguration
asserts:
- equal:
path: webhooks[0].clientConfig.service.namespace
value: kubewarden
- notEqual:
path: webhooks[0].clientConfig.service.namespace
value: system
# ── Group 6: the 3 TLS/CA Secret documents must be present ──
- it: "kubewarden-ca Secret should be present"
documentSelector:
path: metadata.name
value: kubewarden-ca
asserts:
- equal:
path: kind
value: Secret
- it: "kubewarden-webhook-server-cert Secret should be present"
documentSelector:
path: metadata.name
value: kubewarden-webhook-server-cert
asserts:
- equal:
path: kind
value: Secret
- it: "kubewarden-audit-scanner-client-cert Secret should be present"
documentSelector:
path: metadata.name
value: kubewarden-audit-scanner-client-cert
asserts:
- equal:
path: kind
value: Secret
# ── Group 7: webhook count must match what controller-gen produces ──
- it: "MutatingWebhookConfiguration should have exactly 5 webhooks"
documentSelector:
path: kind
value: MutatingWebhookConfiguration
asserts:
- lengthEqual:
path: webhooks
count: 5
- it: "ValidatingWebhookConfiguration should have exactly 5 webhooks"
documentSelector:
path: kind
value: ValidatingWebhookConfiguration
asserts:
- lengthEqual:
path: webhooks
count: 5
# ── Group 8: each mutating webhook must be present with correct name and service path ──
# Note: helm-unittest `contains` does not support deep partial matching on nested fields,
# so we check `name` presence separately from the service `path` per index.
- it: "MutatingWebhookConfiguration should have all expected webhook names"
documentSelector:
path: kind
value: MutatingWebhookConfiguration
asserts:
- contains:
path: webhooks
any: true
content:
name: madmissionpolicy.kb.io
- contains:
path: webhooks
any: true
content:
name: madmissionpolicygroup.kb.io
- contains:
path: webhooks
any: true
content:
name: mclusteradmissionpolicy.kb.io
- contains:
path: webhooks
any: true
content:
name: mclusteradmissionpolicygroup.kb.io
- contains:
path: webhooks
any: true
content:
name: mpolicyserver.kb.io
- it: "MutatingWebhookConfiguration should have correct service paths for all webhooks"
documentSelector:
path: kind
value: MutatingWebhookConfiguration
asserts:
# Order matches webhooks.yaml: clusteradmissionpolicy, clusteradmissionpolicygroup,
# policyserver, admissionpolicy, admissionpolicygroup
- equal:
path: webhooks[0].clientConfig.service.path
value: /mutate-policies-kubewarden-io-v1-clusteradmissionpolicy
- equal:
path: webhooks[1].clientConfig.service.path
value: /mutate-policies-kubewarden-io-v1-clusteradmissionpolicygroup
- equal:
path: webhooks[2].clientConfig.service.path
value: /mutate-policies-kubewarden-io-v1-policyserver
- equal:
path: webhooks[3].clientConfig.service.path
value: /mutate-policies-kubewarden-io-v1-admissionpolicy
- equal:
path: webhooks[4].clientConfig.service.path
value: /mutate-policies-kubewarden-io-v1-admissionpolicygroup
# ── Group 8 (cont.): each validating webhook must be present with correct name and service path ──
- it: "ValidatingWebhookConfiguration should have all expected webhook names"
documentSelector:
path: kind
value: ValidatingWebhookConfiguration
asserts:
- contains:
path: webhooks
any: true
content:
name: vadmissionpolicy.kb.io
- contains:
path: webhooks
any: true
content:
name: vadmissionpolicygroup.kb.io
- contains:
path: webhooks
any: true
content:
name: vclusteradmissionpolicy.kb.io
- contains:
path: webhooks
any: true
content:
name: vclusteradmissionpolicygroup.kb.io
- contains:
path: webhooks
any: true
content:
name: vpolicyserver.kb.io
- it: "ValidatingWebhookConfiguration should have correct service paths for all webhooks"
documentSelector:
path: kind
value: ValidatingWebhookConfiguration
asserts:
# Order matches webhooks.yaml: clusteradmissionpolicy, clusteradmissionpolicygroup,
# admissionpolicy, admissionpolicygroup, policyserver
- equal:
path: webhooks[0].clientConfig.service.path
value: /validate-policies-kubewarden-io-v1-clusteradmissionpolicy
- equal:
path: webhooks[1].clientConfig.service.path
value: /validate-policies-kubewarden-io-v1-clusteradmissionpolicygroup
- equal:
path: webhooks[2].clientConfig.service.path
value: /validate-policies-kubewarden-io-v1-admissionpolicy
- equal:
path: webhooks[3].clientConfig.service.path
value: /validate-policies-kubewarden-io-v1-admissionpolicygroup
- equal:
path: webhooks[4].clientConfig.service.path
value: /validate-policies-kubewarden-io-v1-policyserver