@@ -454,6 +454,69 @@ func TestK8SServiceIngressAdditionalPathsHigherPriorityNoServiceName(t *testing.
454454 assert .Equal (t , secondPath .Backend .ServicePort .StrVal , "app" )
455455}
456456
457+ // Test that omitting a serviceName on additionalPaths reuses the application service name even when hosts is set
458+ func TestK8SServiceIngressWithHostsAdditionalPathsNoServiceName (t * testing.T ) {
459+ t .Parallel ()
460+
461+ ingress := renderK8SServiceIngressWithSetValues (
462+ t ,
463+ map [string ]string {
464+ "ingress.enabled" : "true" ,
465+ "ingress.path" : "/app" ,
466+ "ingress.servicePort" : "app" ,
467+ "ingress.hosts[0]" : "chart-example.local" ,
468+ "ingress.additionalPaths[0].path" : "/black-hole" ,
469+ "ingress.additionalPaths[0].servicePort" : "3000" ,
470+ },
471+ )
472+ pathRules := ingress .Spec .Rules [0 ].HTTP .Paths
473+ assert .Equal (t , len (pathRules ), 2 )
474+
475+ // The first path should be the main service path
476+ firstPath := pathRules [0 ]
477+ assert .Equal (t , firstPath .Path , "/app" )
478+ assert .Equal (t , strings .ToLower (firstPath .Backend .ServiceName ), "release-name-linter" )
479+ assert .Equal (t , firstPath .Backend .ServicePort .StrVal , "app" )
480+
481+ // The second path should be the black hole
482+ secondPath := pathRules [1 ]
483+ assert .Equal (t , secondPath .Path , "/black-hole" )
484+ assert .Equal (t , strings .ToLower (secondPath .Backend .ServiceName ), "release-name-linter" )
485+ assert .Equal (t , secondPath .Backend .ServicePort .IntVal , int32 (3000 ))
486+ }
487+
488+ // Test that omitting a serviceName on additionalPathsHigherPriority reuses the application service name even when hosts
489+ // is set
490+ func TestK8SServiceIngressWithHostsAdditionalPathsHigherPriorityNoServiceName (t * testing.T ) {
491+ t .Parallel ()
492+
493+ ingress := renderK8SServiceIngressWithSetValues (
494+ t ,
495+ map [string ]string {
496+ "ingress.enabled" : "true" ,
497+ "ingress.path" : "/app" ,
498+ "ingress.servicePort" : "app" ,
499+ "ingress.hosts[0]" : "chart-example.local" ,
500+ "ingress.additionalPathsHigherPriority[0].path" : "/black-hole" ,
501+ "ingress.additionalPathsHigherPriority[0].servicePort" : "3000" ,
502+ },
503+ )
504+ pathRules := ingress .Spec .Rules [0 ].HTTP .Paths
505+ assert .Equal (t , len (pathRules ), 2 )
506+
507+ // The first path should be the black hole
508+ firstPath := pathRules [0 ]
509+ assert .Equal (t , firstPath .Path , "/black-hole" )
510+ assert .Equal (t , strings .ToLower (firstPath .Backend .ServiceName ), "release-name-linter" )
511+ assert .Equal (t , firstPath .Backend .ServicePort .IntVal , int32 (3000 ))
512+
513+ // The second path should be the main service path
514+ secondPath := pathRules [1 ]
515+ assert .Equal (t , secondPath .Path , "/app" )
516+ assert .Equal (t , strings .ToLower (secondPath .Backend .ServiceName ), "release-name-linter" )
517+ assert .Equal (t , secondPath .Backend .ServicePort .StrVal , "app" )
518+ }
519+
457520// Test rendering Managed Certificate
458521func TestK8SServiceManagedCertDomainNameAndName (t * testing.T ) {
459522 t .Parallel ()
@@ -612,3 +675,17 @@ func TestK8SServiceIngressMultiCert(t *testing.T) {
612675 assert .Equal (t , secondTlsHosts [0 ], "chart1-example-tls-host" )
613676 assert .Equal (t , secondTlsHosts [1 ], "chart1-example-tls-host2" )
614677}
678+
679+ func TestK8SServiceSideCarContainersRendersCorrectly (t * testing.T ) {
680+ t .Parallel ()
681+ deployment := renderK8SServiceDeploymentWithSetValues (
682+ t ,
683+ map [string ]string {
684+ "sideCarContainers.datadog.image" : "datadog/agent:latest" ,
685+ },
686+ )
687+ renderedContainers := deployment .Spec .Template .Spec .Containers
688+ require .Equal (t , len (renderedContainers ), 2 )
689+ sideCarContainer := renderedContainers [1 ]
690+ assert .Equal (t , sideCarContainer .Image , "datadog/agent:latest" )
691+ }
0 commit comments