@@ -134,6 +134,107 @@ func deletePieProbeAndReferencingResources(ctx context.Context, pieProbe *piev1a
134
134
return nil
135
135
}
136
136
137
+ var _ = Describe ("PieProbe controller for specifying resources" , func () {
138
+ ctx := context .Background ()
139
+ var stopFunc func ()
140
+
141
+ nodeSelector := corev1.NodeSelector {
142
+ NodeSelectorTerms : []corev1.NodeSelectorTerm {
143
+ {
144
+ MatchExpressions : []corev1.NodeSelectorRequirement {
145
+ {
146
+ Key : "key1" ,
147
+ Operator : corev1 .NodeSelectorOpIn ,
148
+ Values : []string {"value1" },
149
+ },
150
+ },
151
+ },
152
+ },
153
+ }
154
+
155
+ BeforeEach (func () {
156
+ skipNameValidation := true
157
+ mgr , err := ctrl .NewManager (cfg , ctrl.Options {
158
+ Scheme : scheme ,
159
+ Metrics : metricsserver.Options {BindAddress : "0" },
160
+ Controller : config.Controller {
161
+ SkipNameValidation : & skipNameValidation ,
162
+ },
163
+ })
164
+ Expect (err ).NotTo (HaveOccurred ())
165
+
166
+ err = prepareObjects (ctx )
167
+ Expect (err ).NotTo (HaveOccurred ())
168
+
169
+ pieProbeReconciler := NewPieProbeController (
170
+ k8sClient ,
171
+ "dummy.image" ,
172
+ "http://localhost:8082" ,
173
+ )
174
+ err = pieProbeReconciler .SetupWithManager (mgr )
175
+ Expect (err ).NotTo (HaveOccurred ())
176
+
177
+ ctx , cancel := context .WithCancel (ctx )
178
+ stopFunc = cancel
179
+ go func () {
180
+ err := mgr .Start (ctx )
181
+ if err != nil {
182
+ panic (err )
183
+ }
184
+ }()
185
+ time .Sleep (100 * time .Millisecond )
186
+ })
187
+
188
+ AfterEach (func () {
189
+ stopFunc ()
190
+ time .Sleep (100 * time .Millisecond )
191
+ })
192
+
193
+ DescribeTable ("should create CronJob with the resource specified in the PieProbe resource" ,
194
+ func (limits , requests corev1.ResourceList ) {
195
+ By ("creating a new CronJob via PieProbe with .spec.resources" )
196
+ pieProbe := & piev1alpha1.PieProbe {
197
+ ObjectMeta : metav1.ObjectMeta {
198
+ Namespace : "default" ,
199
+ Name : "pie-probe-sc" ,
200
+ },
201
+ Spec : piev1alpha1.PieProbeSpec {
202
+ MonitoringStorageClass : "sc" ,
203
+ NodeSelector : nodeSelector ,
204
+ ProbePeriod : 1 ,
205
+ Resources : corev1.ResourceRequirements {
206
+ Limits : limits ,
207
+ Requests : requests ,
208
+ },
209
+ },
210
+ }
211
+ _ , err := ctrl .CreateOrUpdate (ctx , k8sClient , pieProbe , func () error { return nil })
212
+ Expect (err ).NotTo (HaveOccurred ())
213
+ defer deletePieProbeAndReferencingResources (ctx , pieProbe )
214
+
215
+ By ("checking the CronJob's resource specified" )
216
+ Eventually (func (g Gomega ) {
217
+ var cronjobList batchv1.CronJobList
218
+ err := k8sClient .List (ctx , & cronjobList , client .MatchingLabels (map [string ]string {
219
+ "storage-class" : "sc" ,
220
+ }))
221
+ g .Expect (err ).NotTo (HaveOccurred ())
222
+ g .Expect (cronjobList .Items ).To (HaveLen (3 ))
223
+
224
+ cronjob := cronjobList .Items [0 ]
225
+ resources := cronjob .Spec .JobTemplate .Spec .Template .Spec .Containers [0 ].Resources
226
+
227
+ g .Expect (resources .Limits ).To (Equal (limits ))
228
+ g .Expect (resources .Requests ).To (Equal (requests ))
229
+ }).Should (Succeed ())
230
+ },
231
+ Entry ("When both cpu limits and requests are not specified" , nil , nil ),
232
+ Entry ("When only cpu limits are specified" , corev1.ResourceList {corev1 .ResourceCPU : resource .MustParse ("100m" )}, nil ),
233
+ Entry ("When only cpu requests are specified" , nil , corev1.ResourceList {corev1 .ResourceCPU : resource .MustParse ("50m" )}),
234
+ Entry ("When both cpu limits and requests are specified" , corev1.ResourceList {corev1 .ResourceCPU : resource .MustParse ("100m" )}, corev1.ResourceList {corev1 .ResourceCPU : resource .MustParse ("50m" )}),
235
+ )
236
+ })
237
+
137
238
var _ = Describe ("PieProbe controller" , func () {
138
239
ctx := context .Background ()
139
240
var stopFunc func ()
@@ -280,7 +381,8 @@ var _ = Describe("PieProbe controller", func() {
280
381
}).Should (Succeed ())
281
382
282
383
By ("cleaning up PVCs and CronJobs for sc2" )
283
- deletePieProbeAndReferencingResources (ctx , pieProbe2 )
384
+ err = deletePieProbeAndReferencingResources (ctx , pieProbe2 )
385
+ Expect (err ).NotTo (HaveOccurred ())
284
386
})
285
387
286
388
It ("should create only mount probes if .spec.disableProvisionProbes is true" , func () {
@@ -303,7 +405,7 @@ var _ = Describe("PieProbe controller", func() {
303
405
By ("checking mount probes exist and provision probes DO NOT exist" )
304
406
Eventually (func (g Gomega ) {
305
407
var cronjobList batchv1.CronJobList
306
- err = k8sClient .List (context . Background () , & cronjobList , client .MatchingLabels (map [string ]string {
408
+ err = k8sClient .List (ctx , & cronjobList , client .MatchingLabels (map [string ]string {
307
409
"storage-class" : "sc2" ,
308
410
}))
309
411
g .Expect (err ).NotTo (HaveOccurred ())
@@ -314,7 +416,8 @@ var _ = Describe("PieProbe controller", func() {
314
416
}).Should (Succeed ())
315
417
316
418
By ("cleaning up PVCs and CronJobs for sc2" )
317
- deletePieProbeAndReferencingResources (ctx , pieProbe2 )
419
+ err = deletePieProbeAndReferencingResources (ctx , pieProbe2 )
420
+ Expect (err ).NotTo (HaveOccurred ())
318
421
})
319
422
320
423
It ("should create only provision probes if .spec.disableMountProbes is true" , func () {
@@ -348,7 +451,8 @@ var _ = Describe("PieProbe controller", func() {
348
451
}).Should (Succeed ())
349
452
350
453
By ("cleaning up PVCs and CronJobs for sc2" )
351
- deletePieProbeAndReferencingResources (ctx , pieProbe2 )
454
+ err = deletePieProbeAndReferencingResources (ctx , pieProbe2 )
455
+ Expect (err ).NotTo (HaveOccurred ())
352
456
})
353
457
354
458
It ("should reject to edit monitoringStorageClass" , func () {
@@ -378,7 +482,7 @@ var _ = Describe("PieProbe controller", func() {
378
482
var cronJobList batchv1.CronJobList
379
483
err := k8sClient .List (ctx , & cronJobList )
380
484
g .Expect (err ).NotTo (HaveOccurred ())
381
- g .Expect (len ( cronJobList .Items )). Should ( Equal (3 ))
485
+ g .Expect (cronJobList .Items ). To ( HaveLen (3 ))
382
486
for _ , cronJob := range cronJobList .Items {
383
487
g .Expect (cronJob .OwnerReferences ).Should (Equal ([]metav1.OwnerReference {{
384
488
APIVersion : "pie.topolvm.io/v1alpha1" ,
0 commit comments