@@ -18,16 +18,16 @@ func New(cnf config.Configuration) *Checks {
18
18
cnf : cnf ,
19
19
20
20
all : make ([]ks.Check , 0 ),
21
- metas : make (map [string ]MetaCheck ),
21
+ metas : make (map [string ]GenCheck [ks. BothMeta ] ),
22
22
pods : make (map [string ]PodCheck ),
23
- services : make (map [string ]ServiceCheck ),
24
- statefulsets : make (map [string ]StatefulSetCheck ),
25
- deployments : make (map [string ]DeploymentCheck ),
26
- networkpolicies : make (map [string ]NetworkPolicyCheck ),
27
- ingresses : make (map [string ]IngressCheck ),
28
- cronjobs : make (map [string ]CronJobCheck ),
29
- horizontalPodAutoscalers : make (map [string ]HorizontalPodAutoscalerCheck ),
30
- poddisruptionbudgets : make (map [string ]PodDisruptionBudgetCheck ),
23
+ services : make (map [string ]GenCheck [corev1. Service ] ),
24
+ statefulsets : make (map [string ]GenCheck [appsv1. StatefulSet ] ),
25
+ deployments : make (map [string ]GenCheck [appsv1. Deployment ] ),
26
+ networkpolicies : make (map [string ]GenCheck [networkingv1. NetworkPolicy ] ),
27
+ ingresses : make (map [string ]GenCheck [ks. Ingress ] ),
28
+ cronjobs : make (map [string ]GenCheck [ks. CronJob ] ),
29
+ horizontalPodAutoscalers : make (map [string ]GenCheck [ks. HpaTargeter ] ),
30
+ poddisruptionbudgets : make (map [string ]GenCheck [ks. PodDisruptionBudget ] ),
31
31
}
32
32
}
33
33
@@ -59,66 +59,25 @@ type PodCheck struct {
59
59
Fn PodCheckFn
60
60
}
61
61
62
- type ServiceCheckFn = func (corev1.Service ) scorecard.TestScore
63
- type ServiceCheck struct {
64
- ks.Check
65
- Fn ServiceCheckFn
66
- }
67
-
68
- type StatefulSetCheckFn = func (appsv1.StatefulSet ) (scorecard.TestScore , error )
69
- type StatefulSetCheck struct {
70
- ks.Check
71
- Fn StatefulSetCheckFn
72
- }
73
-
74
- type DeploymentCheckFn = func (appsv1.Deployment ) (scorecard.TestScore , error )
75
- type DeploymentCheck struct {
76
- ks.Check
77
- Fn DeploymentCheckFn
78
- }
79
-
80
- type NetworkPolicyCheckFn = func (networkingv1.NetworkPolicy ) scorecard.TestScore
81
- type NetworkPolicyCheck struct {
82
- ks.Check
83
- Fn NetworkPolicyCheckFn
84
- }
62
+ type CheckFunc [T any ] func (T ) (scorecard.TestScore , error )
85
63
86
- type IngressCheckFn = func (ks.Ingress ) scorecard.TestScore
87
- type IngressCheck struct {
64
+ type GenCheck [T any ] struct {
88
65
ks.Check
89
- Fn IngressCheckFn
90
- }
91
-
92
- type CronJobCheckFn = func (ks.CronJob ) scorecard.TestScore
93
- type CronJobCheck struct {
94
- ks.Check
95
- Fn CronJobCheckFn
96
- }
97
-
98
- type HorizontalPodAutoscalerCheckFn = func (ks.HpaTargeter ) scorecard.TestScore
99
- type HorizontalPodAutoscalerCheck struct {
100
- ks.Check
101
- Fn HorizontalPodAutoscalerCheckFn
102
- }
103
-
104
- type PodDisruptionBudgetCheckFn = func (ks.PodDisruptionBudget ) scorecard.TestScore
105
- type PodDisruptionBudgetCheck struct {
106
- ks.Check
107
- Fn PodDisruptionBudgetCheckFn
66
+ Fn CheckFunc [T ]
108
67
}
109
68
110
69
type Checks struct {
111
70
all []ks.Check
112
- metas map [string ]MetaCheck
71
+ metas map [string ]GenCheck [ks. BothMeta ]
113
72
pods map [string ]PodCheck
114
- services map [string ]ServiceCheck
115
- statefulsets map [string ]StatefulSetCheck
116
- deployments map [string ]DeploymentCheck
117
- networkpolicies map [string ]NetworkPolicyCheck
118
- ingresses map [string ]IngressCheck
119
- cronjobs map [string ]CronJobCheck
120
- horizontalPodAutoscalers map [string ]HorizontalPodAutoscalerCheck
121
- poddisruptionbudgets map [string ]PodDisruptionBudgetCheck
73
+ services map [string ]GenCheck [corev1. Service ]
74
+ statefulsets map [string ]GenCheck [appsv1. StatefulSet ]
75
+ deployments map [string ]GenCheck [appsv1. Deployment ]
76
+ networkpolicies map [string ]GenCheck [networkingv1. NetworkPolicy ]
77
+ ingresses map [string ]GenCheck [ks. Ingress ]
78
+ cronjobs map [string ]GenCheck [ks. CronJob ]
79
+ horizontalPodAutoscalers map [string ]GenCheck [ks. HpaTargeter ]
80
+ poddisruptionbudgets map [string ]GenCheck [ks. PodDisruptionBudget ]
122
81
123
82
cnf config.Configuration
124
83
}
@@ -128,17 +87,17 @@ func (c Checks) isEnabled(check ks.Check) bool {
128
87
return ! ok
129
88
}
130
89
131
- func (c * Checks ) RegisterMetaCheck (name , comment string , fn MetaCheckFn ) {
90
+ func (c * Checks ) RegisterMetaCheck (name , comment string , fn CheckFunc [ks. BothMeta ] ) {
132
91
ch := NewCheck (name , "all" , comment , false )
133
- c .registerMetaCheck (MetaCheck {ch , fn })
92
+ c .registerMetaCheck (GenCheck [ks. BothMeta ] {ch , fn })
134
93
}
135
94
136
- func (c * Checks ) RegisterOptionalMetaCheck (name , comment string , fn MetaCheckFn ) {
95
+ func (c * Checks ) RegisterOptionalMetaCheck (name , comment string , fn CheckFunc [ks. BothMeta ] ) {
137
96
ch := NewCheck (name , "all" , comment , true )
138
- c .registerMetaCheck (MetaCheck {ch , fn })
97
+ c .registerMetaCheck (GenCheck [ks. BothMeta ] {ch , fn })
139
98
}
140
99
141
- func (c * Checks ) registerMetaCheck (ch MetaCheck ) {
100
+ func (c * Checks ) registerMetaCheck (ch GenCheck [ks. BothMeta ] ) {
142
101
c .all = append (c .all , ch .Check )
143
102
144
103
if ! c .isEnabled (ch .Check ) {
@@ -147,7 +106,7 @@ func (c *Checks) registerMetaCheck(ch MetaCheck) {
147
106
c .metas [machineFriendlyName (ch .Name )] = ch
148
107
}
149
108
150
- func (c * Checks ) Metas () map [string ]MetaCheck {
109
+ func (c * Checks ) Metas () map [string ]GenCheck [ks. BothMeta ] {
151
110
return c .metas
152
111
}
153
112
@@ -174,17 +133,17 @@ func (c *Checks) Pods() map[string]PodCheck {
174
133
return c .pods
175
134
}
176
135
177
- func (c * Checks ) RegisterHorizontalPodAutoscalerCheck (name , comment string , fn HorizontalPodAutoscalerCheckFn ) {
136
+ func (c * Checks ) RegisterHorizontalPodAutoscalerCheck (name , comment string , fn CheckFunc [ks. HpaTargeter ] ) {
178
137
ch := NewCheck (name , "HorizontalPodAutoscaler" , comment , false )
179
- c .registerHorizontalPodAutoscalerCheck (HorizontalPodAutoscalerCheck {ch , fn })
138
+ c .registerHorizontalPodAutoscalerCheck (GenCheck [ks. HpaTargeter ] {ch , fn })
180
139
}
181
140
182
- func (c * Checks ) RegisterOptionalHorizontalPodAutoscalerCheck (name , comment string , fn HorizontalPodAutoscalerCheckFn ) {
141
+ func (c * Checks ) RegisterOptionalHorizontalPodAutoscalerCheck (name , comment string , fn CheckFunc [ks. HpaTargeter ] ) {
183
142
ch := NewCheck (name , "HorizontalPodAutoscaler" , comment , true )
184
- c .registerHorizontalPodAutoscalerCheck (HorizontalPodAutoscalerCheck {ch , fn })
143
+ c .registerHorizontalPodAutoscalerCheck (GenCheck [ks. HpaTargeter ] {ch , fn })
185
144
}
186
145
187
- func (c * Checks ) registerHorizontalPodAutoscalerCheck (ch HorizontalPodAutoscalerCheck ) {
146
+ func (c * Checks ) registerHorizontalPodAutoscalerCheck (ch GenCheck [ks. HpaTargeter ] ) {
188
147
c .all = append (c .all , ch .Check )
189
148
190
149
if ! c .isEnabled (ch .Check ) {
@@ -193,21 +152,21 @@ func (c *Checks) registerHorizontalPodAutoscalerCheck(ch HorizontalPodAutoscaler
193
152
c .horizontalPodAutoscalers [machineFriendlyName (ch .Name )] = ch
194
153
}
195
154
196
- func (c * Checks ) HorizontalPodAutoscalers () map [string ]HorizontalPodAutoscalerCheck {
155
+ func (c * Checks ) HorizontalPodAutoscalers () map [string ]GenCheck [ks. HpaTargeter ] {
197
156
return c .horizontalPodAutoscalers
198
157
}
199
158
200
- func (c * Checks ) RegisterCronJobCheck (name , comment string , fn CronJobCheckFn ) {
159
+ func (c * Checks ) RegisterCronJobCheck (name , comment string , fn CheckFunc [ks. CronJob ] ) {
201
160
ch := NewCheck (name , "CronJob" , comment , false )
202
- c .registerCronJobCheck (CronJobCheck {ch , fn })
161
+ c .registerCronJobCheck (GenCheck [ks. CronJob ] {ch , fn })
203
162
}
204
163
205
- func (c * Checks ) RegisterOptionalCronJobCheck (name , comment string , fn CronJobCheckFn ) {
164
+ func (c * Checks ) RegisterOptionalCronJobCheck (name , comment string , fn CheckFunc [ks. CronJob ] ) {
206
165
ch := NewCheck (name , "CronJob" , comment , true )
207
- c .registerCronJobCheck (CronJobCheck {ch , fn })
166
+ c .registerCronJobCheck (GenCheck [ks. CronJob ] {ch , fn })
208
167
}
209
168
210
- func (c * Checks ) registerCronJobCheck (ch CronJobCheck ) {
169
+ func (c * Checks ) registerCronJobCheck (ch GenCheck [ks. CronJob ] ) {
211
170
c .all = append (c .all , ch .Check )
212
171
213
172
if ! c .isEnabled (ch .Check ) {
@@ -216,21 +175,21 @@ func (c *Checks) registerCronJobCheck(ch CronJobCheck) {
216
175
c .cronjobs [machineFriendlyName (ch .Name )] = ch
217
176
}
218
177
219
- func (c * Checks ) CronJobs () map [string ]CronJobCheck {
178
+ func (c * Checks ) CronJobs () map [string ]GenCheck [ks. CronJob ] {
220
179
return c .cronjobs
221
180
}
222
181
223
- func (c * Checks ) RegisterStatefulSetCheck (name , comment string , fn StatefulSetCheckFn ) {
182
+ func (c * Checks ) RegisterStatefulSetCheck (name , comment string , fn CheckFunc [appsv1. StatefulSet ] ) {
224
183
ch := NewCheck (name , "StatefulSet" , comment , false )
225
- c .registerStatefulSetCheck (StatefulSetCheck {ch , fn })
184
+ c .registerStatefulSetCheck (GenCheck [appsv1. StatefulSet ] {ch , fn })
226
185
}
227
186
228
- func (c * Checks ) RegisterOptionalStatefulSetCheck (name , comment string , fn StatefulSetCheckFn ) {
187
+ func (c * Checks ) RegisterOptionalStatefulSetCheck (name , comment string , fn CheckFunc [appsv1. StatefulSet ] ) {
229
188
ch := NewCheck (name , "StatefulSet" , comment , true )
230
- c .registerStatefulSetCheck (StatefulSetCheck {ch , fn })
189
+ c .registerStatefulSetCheck (GenCheck [appsv1. StatefulSet ] {ch , fn })
231
190
}
232
191
233
- func (c * Checks ) registerStatefulSetCheck (ch StatefulSetCheck ) {
192
+ func (c * Checks ) registerStatefulSetCheck (ch GenCheck [appsv1. StatefulSet ] ) {
234
193
c .all = append (c .all , ch .Check )
235
194
236
195
if ! c .isEnabled (ch .Check ) {
@@ -239,21 +198,21 @@ func (c *Checks) registerStatefulSetCheck(ch StatefulSetCheck) {
239
198
c .statefulsets [machineFriendlyName (ch .Name )] = ch
240
199
}
241
200
242
- func (c * Checks ) StatefulSets () map [string ]StatefulSetCheck {
201
+ func (c * Checks ) StatefulSets () map [string ]GenCheck [appsv1. StatefulSet ] {
243
202
return c .statefulsets
244
203
}
245
204
246
- func (c * Checks ) RegisterDeploymentCheck (name , comment string , fn DeploymentCheckFn ) {
205
+ func (c * Checks ) RegisterDeploymentCheck (name , comment string , fn CheckFunc [appsv1. Deployment ] ) {
247
206
ch := NewCheck (name , "Deployment" , comment , false )
248
- c .registerDeploymentCheck (DeploymentCheck {ch , fn })
207
+ c .registerDeploymentCheck (GenCheck [appsv1. Deployment ] {ch , fn })
249
208
}
250
209
251
- func (c * Checks ) RegisterOptionalDeploymentCheck (name , comment string , fn DeploymentCheckFn ) {
210
+ func (c * Checks ) RegisterOptionalDeploymentCheck (name , comment string , fn CheckFunc [appsv1. Deployment ] ) {
252
211
ch := NewCheck (name , "Deployment" , comment , true )
253
- c .registerDeploymentCheck (DeploymentCheck {ch , fn })
212
+ c .registerDeploymentCheck (GenCheck [appsv1. Deployment ] {ch , fn })
254
213
}
255
214
256
- func (c * Checks ) registerDeploymentCheck (ch DeploymentCheck ) {
215
+ func (c * Checks ) registerDeploymentCheck (ch GenCheck [appsv1. Deployment ] ) {
257
216
c .all = append (c .all , ch .Check )
258
217
259
218
if ! c .isEnabled (ch .Check ) {
@@ -262,21 +221,21 @@ func (c *Checks) registerDeploymentCheck(ch DeploymentCheck) {
262
221
c .deployments [machineFriendlyName (ch .Name )] = ch
263
222
}
264
223
265
- func (c * Checks ) Deployments () map [string ]DeploymentCheck {
224
+ func (c * Checks ) Deployments () map [string ]GenCheck [appsv1. Deployment ] {
266
225
return c .deployments
267
226
}
268
227
269
- func (c * Checks ) RegisterIngressCheck (name , comment string , fn IngressCheckFn ) {
228
+ func (c * Checks ) RegisterIngressCheck (name , comment string , fn CheckFunc [ks. Ingress ] ) {
270
229
ch := NewCheck (name , "Ingress" , comment , false )
271
- c .registerIngressCheck (IngressCheck {ch , fn })
230
+ c .registerIngressCheck (GenCheck [ks. Ingress ] {ch , fn })
272
231
}
273
232
274
- func (c * Checks ) RegisterOptionalIngressCheck (name , comment string , fn IngressCheckFn ) {
233
+ func (c * Checks ) RegisterOptionalIngressCheck (name , comment string , fn CheckFunc [ks. Ingress ] ) {
275
234
ch := NewCheck (name , "Ingress" , comment , true )
276
- c .registerIngressCheck (IngressCheck {ch , fn })
235
+ c .registerIngressCheck (GenCheck [ks. Ingress ] {ch , fn })
277
236
}
278
237
279
- func (c * Checks ) registerIngressCheck (ch IngressCheck ) {
238
+ func (c * Checks ) registerIngressCheck (ch GenCheck [ks. Ingress ] ) {
280
239
c .all = append (c .all , ch .Check )
281
240
282
241
if ! c .isEnabled (ch .Check ) {
@@ -285,21 +244,21 @@ func (c *Checks) registerIngressCheck(ch IngressCheck) {
285
244
c .ingresses [machineFriendlyName (ch .Name )] = ch
286
245
}
287
246
288
- func (c * Checks ) Ingresses () map [string ]IngressCheck {
247
+ func (c * Checks ) Ingresses () map [string ]GenCheck [ks. Ingress ] {
289
248
return c .ingresses
290
249
}
291
250
292
- func (c * Checks ) RegisterNetworkPolicyCheck (name , comment string , fn NetworkPolicyCheckFn ) {
251
+ func (c * Checks ) RegisterNetworkPolicyCheck (name , comment string , fn CheckFunc [networkingv1. NetworkPolicy ] ) {
293
252
ch := NewCheck (name , "NetworkPolicy" , comment , false )
294
- c .registerNetworkPolicyCheck (NetworkPolicyCheck {ch , fn })
253
+ c .registerNetworkPolicyCheck (GenCheck [networkingv1. NetworkPolicy ] {ch , fn })
295
254
}
296
255
297
- func (c * Checks ) RegisterOptionalNetworkPolicyCheck (name , comment string , fn NetworkPolicyCheckFn ) {
256
+ func (c * Checks ) RegisterOptionalNetworkPolicyCheck (name , comment string , fn CheckFunc [networkingv1. NetworkPolicy ] ) {
298
257
ch := NewCheck (name , "NetworkPolicy" , comment , true )
299
- c .registerNetworkPolicyCheck (NetworkPolicyCheck {ch , fn })
258
+ c .registerNetworkPolicyCheck (GenCheck [networkingv1. NetworkPolicy ] {ch , fn })
300
259
}
301
260
302
- func (c * Checks ) registerNetworkPolicyCheck (ch NetworkPolicyCheck ) {
261
+ func (c * Checks ) registerNetworkPolicyCheck (ch GenCheck [networkingv1. NetworkPolicy ] ) {
303
262
c .all = append (c .all , ch .Check )
304
263
305
264
if ! c .isEnabled (ch .Check ) {
@@ -308,39 +267,40 @@ func (c *Checks) registerNetworkPolicyCheck(ch NetworkPolicyCheck) {
308
267
c .networkpolicies [machineFriendlyName (ch .Name )] = ch
309
268
}
310
269
311
- func (c * Checks ) NetworkPolicies () map [string ]NetworkPolicyCheck {
270
+ func (c * Checks ) NetworkPolicies () map [string ]GenCheck [networkingv1. NetworkPolicy ] {
312
271
return c .networkpolicies
313
272
}
314
273
315
- func (c * Checks ) RegisterPodDisruptionBudgetCheck (name , comment string , fn PodDisruptionBudgetCheckFn ) {
274
+ func (c * Checks ) RegisterPodDisruptionBudgetCheck (name , comment string , fn CheckFunc [ks. PodDisruptionBudget ] ) {
316
275
ch := NewCheck (name , "PodDisruptionBudget" , comment , false )
317
- c .registerPodDisruptionBudgetCheck (PodDisruptionBudgetCheck {ch , fn })
276
+ c .registerPodDisruptionBudgetCheck (GenCheck [ks. PodDisruptionBudget ] {ch , fn })
318
277
}
319
278
320
- func (c * Checks ) registerPodDisruptionBudgetCheck (ch PodDisruptionBudgetCheck ) {
279
+ func (c * Checks ) registerPodDisruptionBudgetCheck (ch GenCheck [ks. PodDisruptionBudget ] ) {
321
280
c .all = append (c .all , ch .Check )
322
281
323
282
if ! c .isEnabled (ch .Check ) {
324
283
return
325
284
}
285
+
326
286
c .poddisruptionbudgets [machineFriendlyName (ch .Name )] = ch
327
287
}
328
288
329
- func (c * Checks ) PodDisruptionBudgets () map [string ]PodDisruptionBudgetCheck {
289
+ func (c * Checks ) PodDisruptionBudgets () map [string ]GenCheck [ks. PodDisruptionBudget ] {
330
290
return c .poddisruptionbudgets
331
291
}
332
292
333
- func (c * Checks ) RegisterServiceCheck (name , comment string , fn ServiceCheckFn ) {
293
+ func (c * Checks ) RegisterServiceCheck (name , comment string , fn CheckFunc [corev1. Service ] ) {
334
294
ch := NewCheck (name , "Service" , comment , false )
335
- c .registerServiceCheck (ServiceCheck {ch , fn })
295
+ c .registerServiceCheck (GenCheck [corev1. Service ] {ch , fn })
336
296
}
337
297
338
- func (c * Checks ) RegisterOptionalServiceCheck (name , comment string , fn ServiceCheckFn ) {
298
+ func (c * Checks ) RegisterOptionalServiceCheck (name , comment string , fn CheckFunc [corev1. Service ] ) {
339
299
ch := NewCheck (name , "Service" , comment , true )
340
- c .registerServiceCheck (ServiceCheck {ch , fn })
300
+ c .registerServiceCheck (GenCheck [corev1. Service ] {ch , fn })
341
301
}
342
302
343
- func (c * Checks ) registerServiceCheck (ch ServiceCheck ) {
303
+ func (c * Checks ) registerServiceCheck (ch GenCheck [corev1. Service ] ) {
344
304
c .all = append (c .all , ch .Check )
345
305
346
306
if ! c .isEnabled (ch .Check ) {
@@ -349,7 +309,7 @@ func (c *Checks) registerServiceCheck(ch ServiceCheck) {
349
309
c .services [machineFriendlyName (ch .Name )] = ch
350
310
}
351
311
352
- func (c * Checks ) Services () map [string ]ServiceCheck {
312
+ func (c * Checks ) Services () map [string ]GenCheck [corev1. Service ] {
353
313
return c .services
354
314
}
355
315
0 commit comments