mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 21:17:23 +00:00
Merge pull request #94494 from SergeyKanzhelev/hostportConflicts
Allow to map the same container port to different host ports
This commit is contained in:
commit
e6444e01ba
@ -335,7 +335,7 @@ func MakePortMappings(container *v1.Container) (ports []PortMapping) {
|
|||||||
|
|
||||||
var name string = p.Name
|
var name string = p.Name
|
||||||
if name == "" {
|
if name == "" {
|
||||||
name = fmt.Sprintf("%s-%s:%d", family, p.Protocol, p.ContainerPort)
|
name = fmt.Sprintf("%s-%s-%s:%d:%d", family, p.Protocol, p.HostIP, p.ContainerPort, p.HostPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Protect against a port name being used more than once in a container.
|
// Protect against a port name being used more than once in a container.
|
||||||
|
@ -580,8 +580,6 @@ func TestMakePortMappings(t *testing.T) {
|
|||||||
port("foo", v1.ProtocolUDP, 555, 5555, ""),
|
port("foo", v1.ProtocolUDP, 555, 5555, ""),
|
||||||
// Duplicated, should be ignored.
|
// Duplicated, should be ignored.
|
||||||
port("foo", v1.ProtocolUDP, 888, 8888, ""),
|
port("foo", v1.ProtocolUDP, 888, 8888, ""),
|
||||||
// Duplicated, should be ignored.
|
|
||||||
port("", v1.ProtocolTCP, 80, 8888, "127.0.0.1"),
|
|
||||||
// Duplicated with different address family, shouldn't be ignored
|
// Duplicated with different address family, shouldn't be ignored
|
||||||
port("", v1.ProtocolTCP, 80, 8080, "::"),
|
port("", v1.ProtocolTCP, 80, 8080, "::"),
|
||||||
// No address family specified
|
// No address family specified
|
||||||
@ -596,6 +594,47 @@ func TestMakePortMappings(t *testing.T) {
|
|||||||
portMapping(v1.ProtocolTCP, 1234, 5678, ""),
|
portMapping(v1.ProtocolTCP, 1234, 5678, ""),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// The same container port can be mapped to different host ports
|
||||||
|
&v1.Container{
|
||||||
|
Name: "fooContainer",
|
||||||
|
Ports: []v1.ContainerPort{
|
||||||
|
port("", v1.ProtocolTCP, 443, 4343, "192.168.0.1"),
|
||||||
|
port("", v1.ProtocolTCP, 4343, 4343, "192.168.0.1"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
[]PortMapping{
|
||||||
|
portMapping(v1.ProtocolTCP, 443, 4343, "192.168.0.1"),
|
||||||
|
portMapping(v1.ProtocolTCP, 4343, 4343, "192.168.0.1"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// The same container port AND same container host is not OK
|
||||||
|
&v1.Container{
|
||||||
|
Name: "fooContainer",
|
||||||
|
Ports: []v1.ContainerPort{
|
||||||
|
port("", v1.ProtocolTCP, 443, 4343, ""),
|
||||||
|
port("", v1.ProtocolTCP, 443, 4343, ""),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
[]PortMapping{
|
||||||
|
portMapping(v1.ProtocolTCP, 443, 4343, ""),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// multihomed nodes - multiple IP scenario
|
||||||
|
&v1.Container{
|
||||||
|
Name: "fooContainer",
|
||||||
|
Ports: []v1.ContainerPort{
|
||||||
|
port("", v1.ProtocolTCP, 443, 4343, "192.168.0.1"),
|
||||||
|
port("", v1.ProtocolTCP, 443, 4343, "172.16.0.1"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
[]PortMapping{
|
||||||
|
portMapping(v1.ProtocolTCP, 443, 4343, "192.168.0.1"),
|
||||||
|
portMapping(v1.ProtocolTCP, 443, 4343, "172.16.0.1"),
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tt := range tests {
|
for i, tt := range tests {
|
||||||
|
Loading…
Reference in New Issue
Block a user