@@ -218,6 +218,188 @@ func TestLookoutReconciler_Reconcile(t *testing.T) {
218
218
}
219
219
}
220
220
221
+ func TestLookoutReconciler_ReconcilePruningDisabled (t * testing.T ) {
222
+ t .Parallel ()
223
+
224
+ mockCtrl := gomock .NewController (t )
225
+ defer mockCtrl .Finish ()
226
+
227
+ scheme , err := v1alpha1 .SchemeBuilder .Build ()
228
+ if err != nil {
229
+ t .Fatalf ("should not return error when building schema" )
230
+ }
231
+
232
+ expectedNamespacedName := types.NamespacedName {Namespace : "default" , Name : "lookout" }
233
+ dbPruningEnabled := false
234
+ dbPruningSchedule := "1d"
235
+ terminationGracePeriod := int64 (20 )
236
+ expectedLookout := v1alpha1.Lookout {
237
+ TypeMeta : metav1.TypeMeta {
238
+ Kind : "Lookout" ,
239
+ APIVersion : "install.armadaproject.io/v1alpha1" ,
240
+ },
241
+ ObjectMeta : metav1.ObjectMeta {Namespace : "default" , Name : "lookout" },
242
+ Spec : v1alpha1.LookoutSpec {
243
+ Replicas : ptr.To [int32 ](2 ),
244
+ CommonSpecBase : installv1alpha1.CommonSpecBase {
245
+ Labels : nil ,
246
+ Image : v1alpha1.Image {
247
+ Repository : "testrepo" ,
248
+ Tag : "1.0.0" ,
249
+ },
250
+ ApplicationConfig : runtime.RawExtension {},
251
+ Resources : & corev1.ResourceRequirements {},
252
+ Prometheus : & installv1alpha1.PrometheusConfig {Enabled : true , ScrapeInterval : & metav1.Duration {Duration : 1 * time .Second }},
253
+ TerminationGracePeriodSeconds : & terminationGracePeriod ,
254
+ },
255
+ ClusterIssuer : "test" ,
256
+ HostNames : []string {"localhost" },
257
+ Ingress : & installv1alpha1.IngressConfig {
258
+ IngressClass : "nginx" ,
259
+ Labels : map [string ]string {"test" : "hello" },
260
+ Annotations : map [string ]string {"test" : "hello" },
261
+ },
262
+ DbPruningEnabled : & dbPruningEnabled ,
263
+ DbPruningSchedule : & dbPruningSchedule ,
264
+ },
265
+ }
266
+
267
+ mockK8sClient := k8sclient .NewMockClient (mockCtrl )
268
+ // Lookout
269
+ mockK8sClient .
270
+ EXPECT ().
271
+ Get (gomock .Any (), expectedNamespacedName , gomock .AssignableToTypeOf (& v1alpha1.Lookout {})).
272
+ Return (nil ).
273
+ SetArg (2 , expectedLookout )
274
+
275
+ // Finalizer
276
+ mockK8sClient .
277
+ EXPECT ().
278
+ Update (gomock .Any (), gomock .AssignableToTypeOf (& installv1alpha1.Lookout {})).
279
+ Return (nil )
280
+
281
+ // ServiceAccount
282
+ mockK8sClient .
283
+ EXPECT ().
284
+ Get (gomock .Any (), expectedNamespacedName , gomock .AssignableToTypeOf (& corev1.ServiceAccount {})).
285
+ Return (errors .NewNotFound (schema.GroupResource {}, "lookout" ))
286
+ mockK8sClient .
287
+ EXPECT ().
288
+ Create (gomock .Any (), gomock .AssignableToTypeOf (& corev1.ServiceAccount {})).
289
+ Return (nil )
290
+
291
+ mockK8sClient .
292
+ EXPECT ().
293
+ Get (gomock .Any (), expectedNamespacedName , gomock .AssignableToTypeOf (& corev1.Secret {})).
294
+ Return (errors .NewNotFound (schema.GroupResource {}, "lookout" ))
295
+ mockK8sClient .
296
+ EXPECT ().
297
+ Create (gomock .Any (), gomock .AssignableToTypeOf (& corev1.Secret {})).
298
+ Return (nil )
299
+
300
+ expectedJobName := types.NamespacedName {Namespace : "default" , Name : "lookout-migration" }
301
+ expectedMigrationJob := & batchv1.Job {
302
+ ObjectMeta : metav1.ObjectMeta {
303
+ Namespace : "default" ,
304
+ Name : "lookout-migration" ,
305
+ },
306
+ Spec : batchv1.JobSpec {
307
+ Template : corev1.PodTemplateSpec {
308
+ Spec : corev1.PodSpec {
309
+ Containers : []corev1.Container {
310
+ {
311
+ Name : "lookout-migration" ,
312
+ Image : "testrepo:1.0.0" ,
313
+ },
314
+ },
315
+ },
316
+ },
317
+ },
318
+ Status : batchv1.JobStatus {
319
+ Conditions : []batchv1.JobCondition {{
320
+ Type : batchv1 .JobComplete ,
321
+ Status : corev1 .ConditionTrue ,
322
+ }},
323
+ },
324
+ }
325
+
326
+ mockK8sClient .
327
+ EXPECT ().
328
+ Get (gomock .Any (), expectedJobName , gomock .AssignableToTypeOf (& batchv1.Job {})).
329
+ Return (errors .NewNotFound (schema.GroupResource {}, "lookout" ))
330
+ mockK8sClient .
331
+ EXPECT ().
332
+ Create (gomock .Any (), gomock .AssignableToTypeOf (& batchv1.Job {})).
333
+ Return (nil )
334
+ mockK8sClient .
335
+ EXPECT ().
336
+ Get (gomock .Any (), expectedJobName , gomock .AssignableToTypeOf (& batchv1.Job {})).
337
+ Return (nil ).
338
+ SetArg (2 , * expectedMigrationJob )
339
+
340
+ mockK8sClient .
341
+ EXPECT ().
342
+ Get (gomock .Any (), expectedNamespacedName , gomock .AssignableToTypeOf (& appsv1.Deployment {})).
343
+ Return (errors .NewNotFound (schema.GroupResource {}, "lookout" ))
344
+ mockK8sClient .
345
+ EXPECT ().
346
+ Create (gomock .Any (), gomock .AssignableToTypeOf (& appsv1.Deployment {})).
347
+ Return (nil )
348
+
349
+ mockK8sClient .
350
+ EXPECT ().
351
+ Get (gomock .Any (), expectedNamespacedName , gomock .AssignableToTypeOf (& corev1.Service {})).
352
+ Return (errors .NewNotFound (schema.GroupResource {}, "lookout" ))
353
+ mockK8sClient .
354
+ EXPECT ().
355
+ Create (gomock .Any (), gomock .AssignableToTypeOf (& corev1.Service {})).
356
+ Return (nil )
357
+
358
+ // IngressHttp
359
+ expectedIngressName := expectedNamespacedName
360
+ expectedIngressName .Name = expectedIngressName .Name + "-rest"
361
+ mockK8sClient .
362
+ EXPECT ().
363
+ Get (gomock .Any (), expectedIngressName , gomock .AssignableToTypeOf (& networkingv1.Ingress {})).
364
+ Return (errors .NewNotFound (schema.GroupResource {}, "lookout" ))
365
+ mockK8sClient .
366
+ EXPECT ().
367
+ Create (gomock .Any (), gomock .AssignableToTypeOf (& networkingv1.Ingress {})).
368
+ Return (nil )
369
+
370
+ // ServiceMonitor
371
+ mockK8sClient .
372
+ EXPECT ().
373
+ Get (gomock .Any (), expectedNamespacedName , gomock .AssignableToTypeOf (& monitoringv1.ServiceMonitor {})).
374
+ Return (errors .NewNotFound (schema.GroupResource {}, "armadaserver" ))
375
+ mockK8sClient .
376
+ EXPECT ().
377
+ Create (gomock .Any (), gomock .AssignableToTypeOf (& monitoringv1.ServiceMonitor {})).
378
+ Return (nil )
379
+
380
+ // CronJob should be deleted
381
+ expectedCronJobName := expectedNamespacedName
382
+ expectedCronJobName .Name = expectedCronJobName .Name + "-db-pruner"
383
+ mockK8sClient .
384
+ EXPECT ().
385
+ Delete (gomock .Any (), gomock .AssignableToTypeOf (& batchv1.CronJob {})).
386
+ Return (nil )
387
+
388
+ r := LookoutReconciler {
389
+ Client : mockK8sClient ,
390
+ Scheme : scheme ,
391
+ }
392
+
393
+ req := ctrl.Request {
394
+ NamespacedName : types.NamespacedName {Namespace : "default" , Name : "lookout" },
395
+ }
396
+
397
+ _ , err = r .Reconcile (context .Background (), req )
398
+ if err != nil {
399
+ t .Fatalf ("reconcile should not return error" )
400
+ }
401
+ }
402
+
221
403
func TestLookoutReconciler_ReconcileNoLookout (t * testing.T ) {
222
404
t .Parallel ()
223
405
0 commit comments