@@ -580,8 +580,6 @@ func TestMakePortMappings(t *testing.T) {
580
580
port ("foo" , v1 .ProtocolUDP , 555 , 5555 , "" ),
581
581
// Duplicated, should be ignored.
582
582
port ("foo" , v1 .ProtocolUDP , 888 , 8888 , "" ),
583
- // Duplicated, should be ignored.
584
- port ("" , v1 .ProtocolTCP , 80 , 8888 , "127.0.0.1" ),
585
583
// Duplicated with different address family, shouldn't be ignored
586
584
port ("" , v1 .ProtocolTCP , 80 , 8080 , "::" ),
587
585
// No address family specified
@@ -596,6 +594,47 @@ func TestMakePortMappings(t *testing.T) {
596
594
portMapping (v1 .ProtocolTCP , 1234 , 5678 , "" ),
597
595
},
598
596
},
597
+ {
598
+ // The same container port can be mapped to different host ports
599
+ & v1.Container {
600
+ Name : "fooContainer" ,
601
+ Ports : []v1.ContainerPort {
602
+ port ("" , v1 .ProtocolTCP , 443 , 4343 , "192.168.0.1" ),
603
+ port ("" , v1 .ProtocolTCP , 4343 , 4343 , "192.168.0.1" ),
604
+ },
605
+ },
606
+ []PortMapping {
607
+ portMapping (v1 .ProtocolTCP , 443 , 4343 , "192.168.0.1" ),
608
+ portMapping (v1 .ProtocolTCP , 4343 , 4343 , "192.168.0.1" ),
609
+ },
610
+ },
611
+ {
612
+ // The same container port AND same container host is not OK
613
+ & v1.Container {
614
+ Name : "fooContainer" ,
615
+ Ports : []v1.ContainerPort {
616
+ port ("" , v1 .ProtocolTCP , 443 , 4343 , "" ),
617
+ port ("" , v1 .ProtocolTCP , 443 , 4343 , "" ),
618
+ },
619
+ },
620
+ []PortMapping {
621
+ portMapping (v1 .ProtocolTCP , 443 , 4343 , "" ),
622
+ },
623
+ },
624
+ {
625
+ // multihomed nodes - multiple IP scenario
626
+ & v1.Container {
627
+ Name : "fooContainer" ,
628
+ Ports : []v1.ContainerPort {
629
+ port ("" , v1 .ProtocolTCP , 443 , 4343 , "192.168.0.1" ),
630
+ port ("" , v1 .ProtocolTCP , 443 , 4343 , "172.16.0.1" ),
631
+ },
632
+ },
633
+ []PortMapping {
634
+ portMapping (v1 .ProtocolTCP , 443 , 4343 , "192.168.0.1" ),
635
+ portMapping (v1 .ProtocolTCP , 443 , 4343 , "172.16.0.1" ),
636
+ },
637
+ },
599
638
}
600
639
601
640
for i , tt := range tests {
0 commit comments