Commit 7dbf0c4e authored by Michael Schurter's avatar Michael Schurter
Browse files

Log missing mapped ports instead of failing

SDNs, overlays, etc often won't need to map ports.
parent 0921368f
Showing with 26 additions and 20 deletions
+26 -20
......@@ -32,6 +32,7 @@ IMPROVEMENTS:
* driver/docker: Adds support for `ulimit` and `sysctl` options [GH-3568]
* driver/docker: Adds support for StopTimeout (set to the same value as
kill_timeout [GH-3601]
* driver/rkt: Don't fail on unmapped ports [GH-3637]
* driver/rkt: Add support for passing through user [GH-3612]
* driver/qemu: Support graceful shutdowns on unix platforms [GH-3411]
* template: Updated to consul template 0.19.4 [GH-3543]
......
......@@ -535,41 +535,43 @@ func (d *RktDriver) Start(ctx *ExecContext, task *structs.Task) (*StartResponse,
} else {
// TODO add support for more than one network
network := task.Resources.Networks[0]
unmappedPorts := make([]string, 0, len(network.ReservedPorts)+len(network.DynamicPorts))
for _, port := range network.ReservedPorts {
var containerPort string
mapped, ok := driverConfig.PortMap[port.Label]
if !ok {
// If the user doesn't have a mapped port using port_map, driver stops running container.
return nil, fmt.Errorf("port_map is not set. When you defined port in the resources, you need to configure port_map.")
unmappedPorts = append(unmappedPorts, port.Label)
continue
}
containerPort = mapped
hostPortStr := strconv.Itoa(port.Value)
d.logger.Printf("[DEBUG] driver.rkt: exposed port %s", containerPort)
d.logger.Printf("[DEBUG] driver.rkt: alloc %s task %s mapped reserved port %s:%s",
d.DriverContext.allocID, task.Name, mapped, hostPortStr)
// Add port option to rkt run arguments. rkt allows multiple port args
prepareArgs = append(prepareArgs, fmt.Sprintf("--port=%s:%s", containerPort, hostPortStr))
prepareArgs = append(prepareArgs, fmt.Sprintf("--port=%s:%s", mapped, hostPortStr))
}
for _, port := range network.DynamicPorts {
// By default we will map the allocated port 1:1 to the container
var containerPort string
if mapped, ok := driverConfig.PortMap[port.Label]; ok {
containerPort = mapped
} else {
// If the user doesn't have mapped a port using port_map, driver stops running container.
return nil, fmt.Errorf("port_map is not set. When you defined port in the resources, you need to configure port_map.")
mapped, ok := driverConfig.PortMap[port.Label]
if !ok {
unmappedPorts = append(unmappedPorts, port.Label)
continue
}
hostPortStr := strconv.Itoa(port.Value)
d.logger.Printf("[DEBUG] driver.rkt: exposed port %s", containerPort)
d.logger.Printf("[DEBUG] driver.rkt: alloc %s task %s mapped dynamic port %s:%s",
d.DriverContext.allocID, task.Name, mapped, hostPortStr)
// Add port option to rkt run arguments. rkt allows multiple port args
prepareArgs = append(prepareArgs, fmt.Sprintf("--port=%s:%s", containerPort, hostPortStr))
prepareArgs = append(prepareArgs, fmt.Sprintf("--port=%s:%s", mapped, hostPortStr))
}
if len(unmappedPorts) > 0 {
d.logger.Printf("[INFO] driver.rkt: alloc %s task %s did not map these ports: %s",
d.DriverContext.allocID, task.Name, strings.Join(unmappedPorts, ", "))
}
}
// If a user has been specified for the task, pass it through to the user
......
......@@ -453,7 +453,7 @@ func TestRktTaskValidate(t *testing.T) {
}
// TODO: Port Mapping test should be ran with proper ACI image and test the port access.
func TestRktDriver_PortsMapping(t *testing.T) {
func TestRktDriver_PortMapping(t *testing.T) {
if !testutil.IsTravis() {
t.Parallel()
}
......@@ -483,8 +483,11 @@ func TestRktDriver_PortsMapping(t *testing.T) {
CPU: 512,
Networks: []*structs.NetworkResource{
{
IP: "127.0.0.1",
ReservedPorts: []structs.Port{{Label: "main", Value: 8080}},
IP: "127.0.0.1",
ReservedPorts: []structs.Port{
{Label: "main", Value: 8080},
{Label: "unmapped", Value: 9999},
},
},
},
},
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment