@@ -515,6 +515,7 @@ func TestServiceControllerKey(t *testing.T) {
515
515
516
516
func TestGetEndpointPorts (t * testing.T ) {
517
517
protoTCP := v1 .ProtocolTCP
518
+ restartPolicyAlways := v1 .ContainerRestartPolicyAlways
518
519
519
520
testCases := map [string ]struct {
520
521
service * v1.Service
@@ -585,6 +586,51 @@ func TestGetEndpointPorts(t *testing.T) {
585
586
AppProtocol : pointer .String ("https" ),
586
587
}},
587
588
},
589
+ "service with named port for restartable init container" : {
590
+ service : & v1.Service {
591
+ Spec : v1.ServiceSpec {
592
+ Ports : []v1.ServicePort {{
593
+ Name : "http-sidecar" ,
594
+ Port : 8080 ,
595
+ TargetPort : intstr .FromInt32 (8080 ),
596
+ Protocol : protoTCP ,
597
+ }, {
598
+ Name : "http" ,
599
+ Port : 8090 ,
600
+ TargetPort : intstr .FromString ("http" ),
601
+ Protocol : protoTCP ,
602
+ }},
603
+ },
604
+ },
605
+ pod : & v1.Pod {
606
+ Spec : v1.PodSpec {
607
+ InitContainers : []v1.Container {{
608
+ Ports : []v1.ContainerPort {{
609
+ Name : "http-sidecar" ,
610
+ ContainerPort : int32 (8080 ),
611
+ Protocol : protoTCP ,
612
+ }},
613
+ RestartPolicy : & restartPolicyAlways ,
614
+ }},
615
+ Containers : []v1.Container {{
616
+ Ports : []v1.ContainerPort {{
617
+ Name : "http" ,
618
+ ContainerPort : int32 (8090 ),
619
+ Protocol : protoTCP ,
620
+ }},
621
+ }},
622
+ },
623
+ },
624
+ expectedPorts : []* discovery.EndpointPort {{
625
+ Name : pointer .String ("http-sidecar" ),
626
+ Port : pointer .Int32 (8080 ),
627
+ Protocol : & protoTCP ,
628
+ }, {
629
+ Name : pointer .String ("http" ),
630
+ Port : pointer .Int32 (8090 ),
631
+ Protocol : & protoTCP ,
632
+ }},
633
+ },
588
634
}
589
635
590
636
for name , tc := range testCases {
0 commit comments