@@ -481,8 +481,7 @@ func Test_otelCollectorFeature_ManageNodeAgent(t *testing.T) {
481
481
expectedOtelImage := images .GetLatestDdotCollectorImage ()
482
482
assert .Equal (t , expectedOtelImage , container .Image , "OTel Agent container should use ddot-collector image when UseStandaloneImage is true" )
483
483
} else {
484
- // Other containers should not use -full image when UseStandaloneImage is true
485
- assert .NotContains (t , container .Image , "-full" , "Non-OTel containers should not use -full image when UseStandaloneImage is true" )
484
+ assert .Equal (t , images .GetLatestAgentImage (), container .Image , "Other containers should use agent image when UseStandaloneImage is true" )
486
485
}
487
486
}
488
487
assert .True (t , otelContainerFound , "OTel Agent container should be present" )
@@ -496,16 +495,37 @@ func Test_otelCollectorFeature_ManageNodeAgent(t *testing.T) {
496
495
WithOTelCollectorUseStandaloneImage (false ).
497
496
Build (),
498
497
WantConfigure : true ,
499
- Agent : test .NewDefaultComponentTest ().WithWantFunc (
500
- func (t testing.TB , mgrInterface feature.PodTemplateManagers ) {
498
+ Agent : & test.ComponentTest {
499
+ CreateFunc : func (t testing.TB ) (feature.PodTemplateManagers , string ) {
500
+ // Create pod template with both CoreAgent and OtelAgent containers
501
+ newPTS := corev1.PodTemplateSpec {
502
+ Spec : corev1.PodSpec {
503
+ Containers : []corev1.Container {
504
+ {
505
+ Name : string (apicommon .CoreAgentContainerName ),
506
+ Image : images .GetLatestAgentImageWithSuffix (false , false , true ),
507
+ Command : []string {"agent" , "run" },
508
+ },
509
+ {
510
+ Name : string (apicommon .OtelAgent ),
511
+ Image : images .GetLatestAgentImageWithSuffix (false , false , true ),
512
+ Command : []string {"otel-agent" },
513
+ },
514
+ },
515
+ },
516
+ }
517
+ return fake .NewPodTemplateManagers (t , newPTS ), kubernetes .DefaultProvider
518
+ },
519
+ WantFunc : func (t testing.TB , mgrInterface feature.PodTemplateManagers ) {
501
520
mgr := mgrInterface .(* fake.PodTemplateManagers )
502
521
503
- // When UseStandaloneImage is false, all containers should use -full image
522
+ // When UseStandaloneImage is false, all containers should use agent image with -full suffix
504
523
for _ , container := range mgr .PodTemplateSpec ().Spec .Containers {
505
- assert .Contains (t , container .Image , "-full" , "All containers should use -full image when UseStandaloneImage is false" )
524
+ expectedImage := images .GetLatestAgentImageWithSuffix (false , false , true )
525
+ assert .Equal (t , expectedImage , container .Image , "All containers should use agent image with -full suffix when UseStandaloneImage is false" )
506
526
}
507
527
},
508
- ) ,
528
+ } ,
509
529
},
510
530
}
511
531
@@ -552,9 +572,10 @@ func Test_otelCollectorFeature_VersionCheck(t *testing.T) {
552
572
func (t testing.TB , mgrInterface feature.PodTemplateManagers ) {
553
573
mgr := mgrInterface .(* fake.PodTemplateManagers )
554
574
// Version 7.66.0 is below 7.67.0, so UseStandaloneImage should be disabled
555
- // All containers should use -full image
575
+ // However, with explicit image override, the override should be respected as-is
576
+ // No containers should have -full suffix when there's an explicit override
556
577
for _ , container := range mgr .PodTemplateSpec ().Spec .Containers {
557
- assert .Contains (t , container .Image , "-full" , "All containers should use -full image when agent version < 7.67.0 " )
578
+ assert .NotContains (t , container .Image , "-full" , "Containers should not use -full image when there's an explicit image override " )
558
579
}
559
580
},
560
581
),
@@ -572,19 +593,42 @@ func Test_otelCollectorFeature_VersionCheck(t *testing.T) {
572
593
}).
573
594
Build (),
574
595
WantConfigure : true ,
575
- Agent : test .NewDefaultComponentTest ().WithWantFunc (
576
- func (t testing.TB , mgrInterface feature.PodTemplateManagers ) {
596
+ Agent : & test.ComponentTest {
597
+ CreateFunc : func (t testing.TB ) (feature.PodTemplateManagers , string ) {
598
+ newPTS := corev1.PodTemplateSpec {
599
+ Spec : corev1.PodSpec {
600
+ Containers : []corev1.Container {
601
+ {
602
+ Name : string (apicommon .CoreAgentContainerName ),
603
+ Image : "datadog/agent:7.68.0" ,
604
+ Command : []string {"agent" , "run" },
605
+ },
606
+ {
607
+ Name : string (apicommon .OtelAgent ),
608
+ Image : "datadog/agent:7.68.0" , // This will be changed to ddot-collector:7.68.0
609
+ Command : []string {"otel-agent" },
610
+ },
611
+ },
612
+ },
613
+ }
614
+ return fake .NewPodTemplateManagers (t , newPTS ), kubernetes .DefaultProvider
615
+ },
616
+ WantFunc : func (t testing.TB , mgrInterface feature.PodTemplateManagers ) {
577
617
mgr := mgrInterface .(* fake.PodTemplateManagers )
578
618
// Version 7.68.0 is >= 7.67.0, so UseStandaloneImage should be enabled
619
+ // With image override, should use the override tag but with appropriate image names
579
620
for _ , container := range mgr .PodTemplateSpec ().Spec .Containers {
580
621
if container .Name == string (apicommon .OtelAgent ) {
581
- assert .Equal (t , images .GetLatestDdotCollectorImage (), container .Image )
622
+ // OTel Agent should use ddot-collector image with override tag
623
+ // Since the override is datadog/agent:7.68.0, it should become datadog/ddot-collector:7.68.0
624
+ assert .Equal (t , "datadog/ddot-collector:7.68.0" , container .Image )
582
625
} else {
583
- assert .Equal (t , images .GetLatestAgentImage (), container .Image )
626
+ // Other containers should use the override image as-is
627
+ assert .Equal (t , "datadog/agent:7.68.0" , container .Image )
584
628
}
585
629
}
586
630
},
587
- ) ,
631
+ } ,
588
632
},
589
633
{
590
634
Name : "UseStandaloneImage disabled for 7.60.0 with image override" ,
@@ -603,8 +647,9 @@ func Test_otelCollectorFeature_VersionCheck(t *testing.T) {
603
647
func (t testing.TB , mgrInterface feature.PodTemplateManagers ) {
604
648
mgr := mgrInterface .(* fake.PodTemplateManagers )
605
649
// Version 7.60.0 is below 7.67.0, so UseStandaloneImage should be disabled
650
+ // However, with explicit image override, the override should be respected as-is
606
651
for _ , container := range mgr .PodTemplateSpec ().Spec .Containers {
607
- assert .Contains (t , container .Image , "-full" , "All containers should use -full image when agent version < 7.67.0 " )
652
+ assert .NotContains (t , container .Image , "-full" , "Containers should not use -full image when there's an explicit image override " )
608
653
}
609
654
},
610
655
),
@@ -647,7 +692,7 @@ func Test_otelCollectorFeature_VersionCheck(t *testing.T) {
647
692
// Version 7.67.0 is >= 7.67.0, so UseStandaloneImage should be enabled
648
693
for _ , container := range mgr .PodTemplateSpec ().Spec .Containers {
649
694
if container .Name == string (apicommon .OtelAgent ) {
650
- // With custom image override, OTel Agent should use custom ddot-collector image
695
+ // With custom image override, OTel Agent should use custom ddot-collector image and the custom registry + tag
651
696
assert .Equal (t , "custom-registry/ddot-collector:7.67.0-custom" , container .Image )
652
697
} else {
653
698
// With custom image override, non-OTel containers should use the custom image without -full suffix
@@ -657,33 +702,6 @@ func Test_otelCollectorFeature_VersionCheck(t *testing.T) {
657
702
},
658
703
},
659
704
},
660
- {
661
- Name : "UseStandaloneImage disabled with invalid version string" ,
662
- DDA : testutils .NewDatadogAgentBuilder ().
663
- WithOTelCollectorEnabled (true ).
664
- WithOTelCollectorUseStandaloneImage (true ).
665
- WithComponentOverride (v2alpha1 .NodeAgentComponentName , v2alpha1.DatadogAgentComponentOverride {
666
- Image : & v2alpha1.AgentImageConfig {
667
- Name : "datadog/agent" ,
668
- Tag : "invalid-version" ,
669
- },
670
- }).
671
- Build (),
672
- WantConfigure : true ,
673
- Agent : test .NewDefaultComponentTest ().WithWantFunc (
674
- func (t testing.TB , mgrInterface feature.PodTemplateManagers ) {
675
- mgr := mgrInterface .(* fake.PodTemplateManagers )
676
- // Invalid version strings should be treated as >= 7.67.0 per utils.IsAboveMinVersion behavior
677
- for _ , container := range mgr .PodTemplateSpec ().Spec .Containers {
678
- if container .Name == string (apicommon .OtelAgent ) {
679
- assert .Equal (t , images .GetLatestDdotCollectorImage (), container .Image )
680
- } else {
681
- assert .Equal (t , images .GetLatestAgentImage (), container .Image )
682
- }
683
- }
684
- },
685
- ),
686
- },
687
705
}
688
706
689
707
tests .Run (t , buildOtelCollectorFeature )
0 commit comments