@@ -44,7 +44,7 @@ func TestReconcile(t *testing.T) {
44
44
fakeClient := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (& pipeline ).WithStatusSubresource (& pipeline ).Build ()
45
45
46
46
agentApplierDeleterMock := & mocks.AgentApplierDeleter {}
47
- agentApplierDeleterMock .On ("ApplyResources " , mock .Anything , mock .Anything , mock . Anything ).Return (nil )
47
+ agentApplierDeleterMock .On ("DeleteResources " , mock .Anything , mock .Anything ).Return (nil ). Times ( 1 )
48
48
49
49
agentConfigBuilderMock := & mocks.AgentConfigBuilder {}
50
50
agentConfigBuilderMock .On ("Build" , mock .Anything ).Return (& gateway.Config {}, nil , nil ).Times (1 )
@@ -97,7 +97,7 @@ func TestReconcile(t *testing.T) {
97
97
fakeClient := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (& pipeline ).WithStatusSubresource (& pipeline ).Build ()
98
98
99
99
agentApplierDeleterMock := & mocks.AgentApplierDeleter {}
100
- agentApplierDeleterMock .On ("ApplyResources " , mock .Anything , mock .Anything , mock . Anything ).Return (nil )
100
+ agentApplierDeleterMock .On ("DeleteResources " , mock .Anything , mock .Anything ).Return (nil ). Times ( 1 )
101
101
102
102
agentConfigBuilderMock := & mocks.AgentConfigBuilder {}
103
103
agentConfigBuilderMock .On ("Build" , containsPipeline (pipeline ), mock .Anything ).Return (& gateway.Config {}, nil , nil ).Times (1 )
@@ -150,7 +150,7 @@ func TestReconcile(t *testing.T) {
150
150
fakeClient := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (& pipeline ).WithStatusSubresource (& pipeline ).Build ()
151
151
152
152
agentApplierDeleterMock := & mocks.AgentApplierDeleter {}
153
- agentApplierDeleterMock .On ("ApplyResources " , mock .Anything , mock .Anything , mock . Anything ).Return (nil )
153
+ agentApplierDeleterMock .On ("DeleteResources " , mock .Anything , mock .Anything ).Return (nil ). Times ( 1 )
154
154
155
155
agentConfigBuilderMock := & mocks.AgentConfigBuilder {}
156
156
agentConfigBuilderMock .On ("Build" , containsPipeline (pipeline ), mock .Anything ).Return (& gateway.Config {}, nil , nil ).Times (1 )
@@ -196,6 +196,7 @@ func TestReconcile(t *testing.T) {
196
196
197
197
gatewayConfigBuilderMock .AssertExpectations (t )
198
198
})
199
+
199
200
t .Run ("log agent daemonset is not ready" , func (t * testing.T ) {
200
201
pipeline := testutils .NewLogPipelineBuilder ().WithName ("pipeline" ).WithOTLPOutput ().WithApplicationInput (true ).Build ()
201
202
fakeClient := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (& pipeline ).WithStatusSubresource (& pipeline ).Build ()
@@ -299,12 +300,199 @@ func TestReconcile(t *testing.T) {
299
300
agentConfigBuilderMock .AssertExpectations (t )
300
301
gatewayConfigBuilderMock .AssertExpectations (t )
301
302
})
303
+
302
304
// TODO: "referenced secret missing" (requires SecretRefValidator to be implemented)
303
305
// TODO: "referenced secret exists" (requires SecretRefValidator to be implemented)
304
306
// TODO: "flow healthy" (requires SelfMonitoring to be implemented)
305
307
// TODO: "tls conditions" (requires TLSCertValidator to be implemented)
306
308
// TODO: "all log pipelines are non-reconcilable" (requires SecretRefValidator to be implemented)
307
309
// TODO: "Check different Pod Error Conditions" (requires SecretRefValidator to be implemented)
310
+
311
+ t .Run ("one log pipeline does not require an agent" , func (t * testing.T ) {
312
+ pipeline := testutils .NewLogPipelineBuilder ().WithName ("pipeline" ).WithOTLPOutput ().WithApplicationInput (false ).Build ()
313
+ fakeClient := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (& pipeline ).WithStatusSubresource (& pipeline ).Build ()
314
+
315
+ agentApplierDeleterMock := & mocks.AgentApplierDeleter {}
316
+ agentApplierDeleterMock .On ("DeleteResources" , mock .Anything , mock .Anything ).Return (nil ).Times (1 )
317
+
318
+ gatewayConfigBuilderMock := & mocks.GatewayConfigBuilder {}
319
+ gatewayConfigBuilderMock .On ("Build" , mock .Anything , containsPipeline (pipeline ), mock .Anything ).Return (& gateway.Config {}, nil , nil ).Times (1 )
320
+
321
+ gatewayApplierDeleterMock := & mocks.GatewayApplierDeleter {}
322
+ gatewayApplierDeleterMock .On ("ApplyResources" , mock .Anything , mock .Anything , mock .Anything ).Return (nil )
323
+
324
+ gatewayProberStub := commonStatusStubs .NewDeploymentSetProber (nil )
325
+ agentProberStub := commonStatusStubs .NewDaemonSetProber (nil )
326
+
327
+ sut := New (
328
+ fakeClient ,
329
+ telemetryNamespace ,
330
+ moduleVersion ,
331
+ & mocks.AgentConfigBuilder {},
332
+ agentApplierDeleterMock ,
333
+ agentProberStub ,
334
+ gatewayApplierDeleterMock ,
335
+ gatewayConfigBuilderMock ,
336
+ gatewayProberStub ,
337
+ istioStatusCheckerStub ,
338
+ & Validator {},
339
+ & conditions.ErrorToMessageConverter {})
340
+ err := sut .Reconcile (context .Background (), & pipeline )
341
+ require .NoError (t , err )
342
+
343
+ var updatedPipeline telemetryv1alpha1.LogPipeline
344
+ _ = fakeClient .Get (context .Background (), types.NamespacedName {Name : pipeline .Name }, & updatedPipeline )
345
+
346
+ requireHasStatusCondition (t , updatedPipeline ,
347
+ conditions .TypeAgentHealthy ,
348
+ metav1 .ConditionTrue ,
349
+ conditions .ReasonLogAgentNotRequired ,
350
+ "" )
351
+
352
+ agentApplierDeleterMock .AssertExpectations (t )
353
+ gatewayConfigBuilderMock .AssertExpectations (t )
354
+ })
355
+
356
+ t .Run ("some log pipelines do not require an agent" , func (t * testing.T ) {
357
+ pipeline1 := testutils .NewLogPipelineBuilder ().WithName ("pipeline1" ).WithOTLPOutput ().WithApplicationInput (false ).Build ()
358
+ pipeline2 := testutils .NewLogPipelineBuilder ().WithName ("pipeline2" ).WithOTLPOutput ().WithApplicationInput (true ).Build ()
359
+ fakeClient := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (& pipeline1 , & pipeline2 ).WithStatusSubresource (& pipeline1 , & pipeline2 ).Build ()
360
+
361
+ agentConfigBuilderMock := & mocks.AgentConfigBuilder {}
362
+ agentConfigBuilderMock .On ("Build" , containsPipelines ([]telemetryv1alpha1.LogPipeline {pipeline1 , pipeline2 }), mock .Anything ).Return (& agent.Config {}, nil , nil ).Times (1 )
363
+
364
+ agentApplierDeleterMock := & mocks.AgentApplierDeleter {}
365
+ agentApplierDeleterMock .On ("ApplyResources" , mock .Anything , mock .Anything , mock .Anything ).Return (nil ).Times (1 )
366
+
367
+ gatewayConfigBuilderMock := & mocks.GatewayConfigBuilder {}
368
+ gatewayConfigBuilderMock .On ("Build" , mock .Anything , containsPipelines ([]telemetryv1alpha1.LogPipeline {pipeline1 , pipeline2 }), mock .Anything ).Return (& gateway.Config {}, nil , nil )
369
+
370
+ gatewayApplierDeleterMock := & mocks.GatewayApplierDeleter {}
371
+ gatewayApplierDeleterMock .On ("ApplyResources" , mock .Anything , mock .Anything , mock .Anything ).Return (nil )
372
+
373
+ gatewayProberStub := commonStatusStubs .NewDeploymentSetProber (nil )
374
+ agentProberStub := commonStatusStubs .NewDaemonSetProber (nil )
375
+
376
+ sut := New (
377
+ fakeClient ,
378
+ telemetryNamespace ,
379
+ moduleVersion ,
380
+ agentConfigBuilderMock ,
381
+ agentApplierDeleterMock ,
382
+ agentProberStub ,
383
+ gatewayApplierDeleterMock ,
384
+ gatewayConfigBuilderMock ,
385
+ gatewayProberStub ,
386
+ istioStatusCheckerStub ,
387
+ & Validator {},
388
+ & conditions.ErrorToMessageConverter {})
389
+ err1 := sut .Reconcile (context .Background (), & pipeline1 )
390
+ err2 := sut .Reconcile (context .Background (), & pipeline2 )
391
+
392
+ require .NoError (t , err1 )
393
+ require .NoError (t , err2 )
394
+
395
+ var updatedPipeline1 telemetryv1alpha1.LogPipeline
396
+ _ = fakeClient .Get (context .Background (), types.NamespacedName {Name : pipeline1 .Name }, & updatedPipeline1 )
397
+
398
+ requireHasStatusCondition (t , updatedPipeline1 ,
399
+ conditions .TypeAgentHealthy ,
400
+ metav1 .ConditionTrue ,
401
+ conditions .ReasonLogAgentNotRequired ,
402
+ "" )
403
+
404
+ agentConfigBuilderMock .AssertExpectations (t )
405
+ agentApplierDeleterMock .AssertExpectations (t )
406
+ gatewayConfigBuilderMock .AssertExpectations (t )
407
+ })
408
+
409
+ t .Run ("all log pipelines do not require an agent" , func (t * testing.T ) {
410
+ pipeline1 := testutils .NewLogPipelineBuilder ().WithName ("pipeline1" ).WithOTLPOutput ().WithApplicationInput (false ).Build ()
411
+ pipeline2 := testutils .NewLogPipelineBuilder ().WithName ("pipeline2" ).WithOTLPOutput ().WithApplicationInput (false ).Build ()
412
+ fakeClient := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (& pipeline1 , & pipeline2 ).WithStatusSubresource (& pipeline1 , & pipeline2 ).Build ()
413
+
414
+ agentApplierDeleterMock := & mocks.AgentApplierDeleter {}
415
+ agentApplierDeleterMock .On ("DeleteResources" , mock .Anything , mock .Anything ).Return (nil ).Times (2 )
416
+
417
+ gatewayConfigBuilderMock := & mocks.GatewayConfigBuilder {}
418
+ gatewayConfigBuilderMock .On ("Build" , mock .Anything , containsPipelines ([]telemetryv1alpha1.LogPipeline {pipeline1 , pipeline2 }), mock .Anything ).Return (& gateway.Config {}, nil , nil )
419
+
420
+ gatewayApplierDeleterMock := & mocks.GatewayApplierDeleter {}
421
+ gatewayApplierDeleterMock .On ("ApplyResources" , mock .Anything , mock .Anything , mock .Anything ).Return (nil )
422
+
423
+ gatewayProberStub := commonStatusStubs .NewDeploymentSetProber (nil )
424
+ agentProberStub := commonStatusStubs .NewDaemonSetProber (nil )
425
+
426
+ sut := New (
427
+ fakeClient ,
428
+ telemetryNamespace ,
429
+ moduleVersion ,
430
+ & mocks.AgentConfigBuilder {},
431
+ agentApplierDeleterMock ,
432
+ agentProberStub ,
433
+ gatewayApplierDeleterMock ,
434
+ gatewayConfigBuilderMock ,
435
+ gatewayProberStub ,
436
+ istioStatusCheckerStub ,
437
+ & Validator {},
438
+ & conditions.ErrorToMessageConverter {})
439
+ err1 := sut .Reconcile (context .Background (), & pipeline1 )
440
+ err2 := sut .Reconcile (context .Background (), & pipeline2 )
441
+
442
+ require .NoError (t , err1 )
443
+ require .NoError (t , err2 )
444
+
445
+ var updatedPipeline1 telemetryv1alpha1.LogPipeline
446
+
447
+ var updatedPipeline2 telemetryv1alpha1.LogPipeline
448
+
449
+ _ = fakeClient .Get (context .Background (), types.NamespacedName {Name : pipeline1 .Name }, & updatedPipeline1 )
450
+ _ = fakeClient .Get (context .Background (), types.NamespacedName {Name : pipeline1 .Name }, & updatedPipeline2 )
451
+
452
+ requireHasStatusCondition (t , updatedPipeline1 ,
453
+ conditions .TypeAgentHealthy ,
454
+ metav1 .ConditionTrue ,
455
+ conditions .ReasonLogAgentNotRequired ,
456
+ "" )
457
+ requireHasStatusCondition (t , updatedPipeline2 ,
458
+ conditions .TypeAgentHealthy ,
459
+ metav1 .ConditionTrue ,
460
+ conditions .ReasonLogAgentNotRequired ,
461
+ "" )
462
+
463
+ agentApplierDeleterMock .AssertExpectations (t )
464
+ gatewayConfigBuilderMock .AssertExpectations (t )
465
+ })
466
+ }
467
+
468
+ func TestGetPipelinesRequiringAgents (t * testing.T ) {
469
+ r := Reconciler {}
470
+
471
+ t .Run ("no pipelines" , func (t * testing.T ) {
472
+ pipelines := []telemetryv1alpha1.LogPipeline {}
473
+ require .Empty (t , r .getPipelinesRequiringAgents (pipelines ))
474
+ })
475
+
476
+ t .Run ("no pipeline requires an agent" , func (t * testing.T ) {
477
+ pipeline1 := testutils .NewLogPipelineBuilder ().WithOTLPOutput ().WithApplicationInput (false ).Build ()
478
+ pipeline2 := testutils .NewLogPipelineBuilder ().WithOTLPOutput ().WithApplicationInput (false ).Build ()
479
+ pipelines := []telemetryv1alpha1.LogPipeline {pipeline1 , pipeline2 }
480
+ require .Empty (t , r .getPipelinesRequiringAgents (pipelines ))
481
+ })
482
+
483
+ t .Run ("some pipelines require an agent" , func (t * testing.T ) {
484
+ pipeline1 := testutils .NewLogPipelineBuilder ().WithOTLPOutput ().WithApplicationInput (true ).Build ()
485
+ pipeline2 := testutils .NewLogPipelineBuilder ().WithOTLPOutput ().WithApplicationInput (false ).Build ()
486
+ pipelines := []telemetryv1alpha1.LogPipeline {pipeline1 , pipeline2 }
487
+ require .ElementsMatch (t , []telemetryv1alpha1.LogPipeline {pipeline1 }, r .getPipelinesRequiringAgents (pipelines ))
488
+ })
489
+
490
+ t .Run ("all pipelines require an agent" , func (t * testing.T ) {
491
+ pipeline1 := testutils .NewLogPipelineBuilder ().WithOTLPOutput ().WithApplicationInput (true ).Build ()
492
+ pipeline2 := testutils .NewLogPipelineBuilder ().WithOTLPOutput ().WithApplicationInput (true ).Build ()
493
+ pipelines := []telemetryv1alpha1.LogPipeline {pipeline1 , pipeline2 }
494
+ require .ElementsMatch (t , []telemetryv1alpha1.LogPipeline {pipeline1 , pipeline2 }, r .getPipelinesRequiringAgents (pipelines ))
495
+ })
308
496
}
309
497
310
498
func requireHasStatusCondition (t * testing.T , pipeline telemetryv1alpha1.LogPipeline , condType string , status metav1.ConditionStatus , reason , message string ) {
@@ -322,3 +510,24 @@ func containsPipeline(p telemetryv1alpha1.LogPipeline) any {
322
510
return len (pipelines ) == 1 && pipelines [0 ].Name == p .Name
323
511
})
324
512
}
513
+
514
+ func containsPipelines (pp []telemetryv1alpha1.LogPipeline ) any {
515
+ return mock .MatchedBy (func (pipelines []telemetryv1alpha1.LogPipeline ) bool {
516
+ if len (pipelines ) != len (pp ) {
517
+ return false
518
+ }
519
+
520
+ pipelineMap := make (map [string ]bool )
521
+ for _ , p := range pipelines {
522
+ pipelineMap [p .Name ] = true
523
+ }
524
+
525
+ for _ , p := range pp {
526
+ if ! pipelineMap [p .Name ] {
527
+ return false
528
+ }
529
+ }
530
+
531
+ return true
532
+ })
533
+ }
0 commit comments