Skip to content

Commit 4e21f53

Browse files
committed
Add test case for service with same named port for regular and sidecar containers
1 parent e637659 commit 4e21f53

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

staging/src/k8s.io/endpointslice/utils_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,43 @@ func TestGetEndpointPorts(t *testing.T) {
631631
Protocol: &protoTCP,
632632
}},
633633
},
634+
"service with same named port for regular and restartable init container": {
635+
service: &v1.Service{
636+
Spec: v1.ServiceSpec{
637+
Ports: []v1.ServicePort{
638+
{
639+
Name: "http",
640+
Port: 80,
641+
TargetPort: intstr.FromString("http"),
642+
Protocol: protoTCP,
643+
}},
644+
},
645+
},
646+
pod: &v1.Pod{
647+
Spec: v1.PodSpec{
648+
InitContainers: []v1.Container{{
649+
Ports: []v1.ContainerPort{{
650+
Name: "http",
651+
ContainerPort: int32(8080),
652+
Protocol: protoTCP,
653+
}},
654+
RestartPolicy: &restartPolicyAlways,
655+
}},
656+
Containers: []v1.Container{{
657+
Ports: []v1.ContainerPort{{
658+
Name: "http",
659+
ContainerPort: int32(8090),
660+
Protocol: protoTCP,
661+
}},
662+
}},
663+
},
664+
},
665+
expectedPorts: []*discovery.EndpointPort{{
666+
Name: pointer.String("http"),
667+
Port: pointer.Int32(8090),
668+
Protocol: &protoTCP,
669+
}},
670+
},
634671
}
635672

636673
for name, tc := range testCases {

0 commit comments

Comments
 (0)