Skip to content

Commit

Permalink
Remove fallback to Docker for host port ranges assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
EC2 Default User committed Feb 12, 2023
1 parent 3d44aaa commit a2269ea
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 32 deletions.
12 changes: 3 additions & 9 deletions agent/api/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -2408,20 +2408,14 @@ func (task *Task) dockerPortMap(container *apicontainer.Container, dynamicHostPo
// we are guaranteed to have the entire hostPortRange in a single network binding while sending this info to ECS.
hostPortRange, err := getHostPortRange(numberOfPorts, protocol, dynamicHostPortRange)
if err != nil {
// in the odd case where we're unable to find a contiguous set of host ports, we fall back to docker dynamic port
// assignment for the requested ContainerPortRange.
logger.Error("Unable to find contiguous host ports for container, falling back to "+
"docker dynamic port assignment", logger.Fields{
logger.Error("Unable to find contiguous host ports for container", logger.Fields{
field.TaskID: task.GetID(),
field.Container: container.Name,
"containerPortRange": containerPortRange,
field.Error: err,
})

// append individual container port from the containerPortRange into the containerPortSet.
// this will ensure that we populate network bindings for ports that docker dynamically assigned.
for port := startContainerPort; port <= endContainerPort; port++ {
containerPortSet[port] = struct{}{}
if err != nil {
return nil, err
}
} else {
// append ranges to the dockerPortMap
Expand Down
23 changes: 0 additions & 23 deletions agent/api/task/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package task

import (
"encoding/json"
"errors"
"fmt"
"reflect"
"runtime"
Expand Down Expand Up @@ -317,28 +316,6 @@ func TestDockerHostConfigPortBinding(t *testing.T) {
},
expectedContainerPortRangeMap: map[string]string{},
},
{
testName: "2 port bindings, each with container port range, 1 found valid host port range, other didn't",
testTask: testTask2,
getHostPortRange: func(numberOfPorts int, protocol string, dynamicHostPortRange string) (string, error) {
if numberOfPorts == 3 {
return "", errors.New("couldn't find host ports")
}
return "99-100", nil
},
expectedPortBinding: nat.PortMap{
nat.Port("999/tcp"): []nat.PortBinding{{HostPort: "99"}},
nat.Port("1000/tcp"): []nat.PortBinding{{HostPort: "100"}},
},
expectedContainerPortSet: map[int]struct{}{
1: {},
2: {},
3: {},
},
expectedContainerPortRangeMap: map[string]string{
"999-1000": "99-100",
},
},
{
testName: "2 port bindings, one with container port range, other with singular container port",
testTask: testTask3,
Expand Down

0 comments on commit a2269ea

Please sign in to comment.