mirror of https://github.com/docker/compose.git
Merge pull request #1053 from docker/aci_udp_ports
ACI: Allow setting protocol when publishing ports
This commit is contained in:
commit
99de963dfc
|
@ -32,6 +32,7 @@ func ContainerToComposeProject(r containers.ContainerConfig) (types.Project, err
|
|||
ports = append(ports, types.ServicePortConfig{
|
||||
Target: p.ContainerPort,
|
||||
Published: p.HostPort,
|
||||
Protocol: p.Protocol,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -37,12 +37,25 @@ func convertPortsToAci(service serviceConfigAciHelper) ([]containerinstance.Cont
|
|||
return nil, nil, nil, errors.New(msg)
|
||||
}
|
||||
portNumber := int32(portConfig.Target)
|
||||
var groupProtocol containerinstance.ContainerGroupNetworkProtocol
|
||||
var containerProtocol containerinstance.ContainerNetworkProtocol
|
||||
switch portConfig.Protocol {
|
||||
case "tcp", "":
|
||||
groupProtocol = containerinstance.TCP
|
||||
containerProtocol = containerinstance.ContainerNetworkProtocolTCP
|
||||
case "udp":
|
||||
groupProtocol = containerinstance.UDP
|
||||
containerProtocol = containerinstance.ContainerNetworkProtocolUDP
|
||||
default:
|
||||
return nil, nil, nil, fmt.Errorf("unknown protocol %q in exposed port for service %q", portConfig.Protocol, service.Name)
|
||||
}
|
||||
containerPorts = append(containerPorts, containerinstance.ContainerPort{
|
||||
Port: to.Int32Ptr(portNumber),
|
||||
Port: to.Int32Ptr(portNumber),
|
||||
Protocol: containerProtocol,
|
||||
})
|
||||
groupPorts = append(groupPorts, containerinstance.Port{
|
||||
Port: to.Int32Ptr(portNumber),
|
||||
Protocol: containerinstance.TCP,
|
||||
Protocol: groupProtocol,
|
||||
})
|
||||
}
|
||||
var dnsLabelName *string = nil
|
||||
|
|
|
@ -173,3 +173,85 @@ func TestPortConvert(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertTCPPortsToAci(t *testing.T) {
|
||||
service := types.ServiceConfig{
|
||||
Name: "myService",
|
||||
Ports: []types.ServicePortConfig{
|
||||
{
|
||||
Protocol: "",
|
||||
Target: 80,
|
||||
Published: 80,
|
||||
},
|
||||
{
|
||||
Protocol: "tcp",
|
||||
Target: 90,
|
||||
Published: 90,
|
||||
},
|
||||
},
|
||||
}
|
||||
containerPorts, groupPports, _, err := convertPortsToAci(serviceConfigAciHelper(service))
|
||||
assert.NilError(t, err)
|
||||
assert.DeepEqual(t, containerPorts, []containerinstance.ContainerPort{
|
||||
{
|
||||
Port: to.Int32Ptr(80),
|
||||
Protocol: containerinstance.ContainerNetworkProtocolTCP,
|
||||
},
|
||||
{
|
||||
Port: to.Int32Ptr(90),
|
||||
Protocol: containerinstance.ContainerNetworkProtocolTCP,
|
||||
},
|
||||
})
|
||||
assert.DeepEqual(t, groupPports, []containerinstance.Port{
|
||||
{
|
||||
Port: to.Int32Ptr(80),
|
||||
Protocol: containerinstance.TCP,
|
||||
},
|
||||
{
|
||||
Port: to.Int32Ptr(90),
|
||||
Protocol: containerinstance.TCP,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestConvertUDPPortsToAci(t *testing.T) {
|
||||
service := types.ServiceConfig{
|
||||
Name: "myService",
|
||||
Ports: []types.ServicePortConfig{
|
||||
{
|
||||
Protocol: "udp",
|
||||
Target: 80,
|
||||
Published: 80,
|
||||
},
|
||||
},
|
||||
}
|
||||
containerPorts, groupPports, _, err := convertPortsToAci(serviceConfigAciHelper(service))
|
||||
assert.NilError(t, err)
|
||||
assert.DeepEqual(t, containerPorts, []containerinstance.ContainerPort{
|
||||
{
|
||||
Port: to.Int32Ptr(80),
|
||||
Protocol: containerinstance.ContainerNetworkProtocolUDP,
|
||||
},
|
||||
})
|
||||
assert.DeepEqual(t, groupPports, []containerinstance.Port{
|
||||
{
|
||||
Port: to.Int32Ptr(80),
|
||||
Protocol: containerinstance.UDP,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestConvertErrorOnMappingPorts(t *testing.T) {
|
||||
service := types.ServiceConfig{
|
||||
Name: "myService",
|
||||
Ports: []types.ServicePortConfig{
|
||||
{
|
||||
Protocol: "",
|
||||
Target: 80,
|
||||
Published: 90,
|
||||
},
|
||||
},
|
||||
}
|
||||
_, _, _, err := convertPortsToAci(serviceConfigAciHelper(service))
|
||||
assert.Error(t, err, "Port mapping is not supported with ACI, cannot map port 90 to 80 for container myService")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue