mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #117 from brendanburns/udp
Add udp support, and unit tests to match. Closes #96
This commit is contained in:
commit
c6c59ff03f
@ -274,7 +274,19 @@ func makePortsAndBindings(container *api.Container) (map[docker.Port]struct{}, m
|
|||||||
exteriorPort := port.HostPort
|
exteriorPort := port.HostPort
|
||||||
// Some of this port stuff is under-documented voodoo.
|
// Some of this port stuff is under-documented voodoo.
|
||||||
// See http://stackoverflow.com/questions/20428302/binding-a-port-to-a-host-interface-using-the-rest-api
|
// See http://stackoverflow.com/questions/20428302/binding-a-port-to-a-host-interface-using-the-rest-api
|
||||||
dockerPort := docker.Port(strconv.Itoa(interiorPort) + "/tcp")
|
var protocol string
|
||||||
|
switch port.Protocol {
|
||||||
|
case "udp":
|
||||||
|
protocol = "/udp"
|
||||||
|
case "tcp":
|
||||||
|
protocol = "/tcp"
|
||||||
|
default:
|
||||||
|
if len(port.Protocol) != 0 {
|
||||||
|
log.Printf("Unknown protocol: %s, defaulting to tcp.", port.Protocol)
|
||||||
|
}
|
||||||
|
protocol = "/tcp"
|
||||||
|
}
|
||||||
|
dockerPort := docker.Port(strconv.Itoa(interiorPort) + protocol)
|
||||||
exposedPorts[dockerPort] = struct{}{}
|
exposedPorts[dockerPort] = struct{}{}
|
||||||
portBindings[dockerPort] = []docker.PortBinding{
|
portBindings[dockerPort] = []docker.PortBinding{
|
||||||
{
|
{
|
||||||
|
@ -677,6 +677,17 @@ func TestMakePortsAndBindings(t *testing.T) {
|
|||||||
{
|
{
|
||||||
ContainerPort: 443,
|
ContainerPort: 443,
|
||||||
HostPort: 443,
|
HostPort: 443,
|
||||||
|
Protocol: "tcp",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ContainerPort: 444,
|
||||||
|
HostPort: 444,
|
||||||
|
Protocol: "udp",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ContainerPort: 445,
|
||||||
|
HostPort: 445,
|
||||||
|
Protocol: "foobar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -685,6 +696,27 @@ func TestMakePortsAndBindings(t *testing.T) {
|
|||||||
len(container.Ports) != len(bindings) {
|
len(container.Ports) != len(bindings) {
|
||||||
t.Errorf("Unexpected ports and bindings, %#v %#v %#v", container, exposedPorts, bindings)
|
t.Errorf("Unexpected ports and bindings, %#v %#v %#v", container, exposedPorts, bindings)
|
||||||
}
|
}
|
||||||
|
for key, value := range bindings {
|
||||||
|
switch value[0].HostPort {
|
||||||
|
case "8080":
|
||||||
|
if !reflect.DeepEqual(docker.Port("80/tcp"), key) {
|
||||||
|
t.Errorf("Unexpected docker port: %#v", key)
|
||||||
|
}
|
||||||
|
case "443":
|
||||||
|
if !reflect.DeepEqual(docker.Port("443/tcp"), key) {
|
||||||
|
t.Errorf("Unexpected docker port: %#v", key)
|
||||||
|
}
|
||||||
|
case "444":
|
||||||
|
if !reflect.DeepEqual(docker.Port("444/udp"), key) {
|
||||||
|
t.Errorf("Unexpected docker port: %#v", key)
|
||||||
|
}
|
||||||
|
case "445":
|
||||||
|
if !reflect.DeepEqual(docker.Port("445/tcp"), key) {
|
||||||
|
t.Errorf("Unexpected docker port: %#v", key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExtractFromNonExistentFile(t *testing.T) {
|
func TestExtractFromNonExistentFile(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user