Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upudate dockerPortMap() in task.go with dynamic host port range support part 2 #39

Closed
wants to merge 1 commit into from

Conversation

chienhanlin
Copy link
Owner

Summary

DHPA - Dynamic Host Port Assignment

The target branch of this PR is feature/dynamicHostPortAssignment.

This is a follow-up PR for Upudate dockerPortMap() in task.go with dynamic host port range support - part 1 to implement dynamic host port assignment for default bridge mode service connect ingress listener ports in dockerPortMap().

Comparing to the current Upudate dockerPortMap() in task.go with dynamic host port range support - part 1 PR, main changes in this PR include:

  1. Add function buildPortMapWithSCIngressConfig() to build a dockerPortMap and a containerPortSet for ingress listener ports under two service connect bridge mode cases:
  • Case 1. Non-default bridge mode service connect experience: customers specify host ports (ingressPortOverride) for listeners in the ingress config.
"serviceConnectConfiguration": {
        "enabled": true,
        "namespace": "<Namespace>",
        "services": [
            {
                "portName": "webserver",
                "discoveryName": "<DiscoveryName>",
                "ingressPortOverride": 15000,
                "clientAliases": [
                    {
                        "port": <Client Port>,
                        "dnsName": "<Client DNS>"
                    }
                ]
            }
        ],
}               
  • Case 2. Default bridge mode service connect experience: customers do not specify host ports for listeners in the ingress config. Instead, ECS Agent finds host ports within the given dynamic host port range. If ECS Agent cannot find an available host port within the range, an error will be returned.
  1. Update comments for function dockerPortMap() to include service connect ingress listener ports info
  2. Refactor how we create port bindings for service connect ingress listener ports in function dockerPortMap()
  3. Add a new function ResetTracker() in ephemeral_ports.go to reset the last assigned host port to 0. This function will be used in unit tests TestGetHostPort, TestGetHostPortRange and TestDockerHostConfigSCBridgeMode.
  4. Update TestDockerHostConfigSCBridgeMode to test changes made in this PR.

Note that dynamicHostPortRange can be configured by customers using ECS Agent environment variable ECS_DYNAMIC_HOST_PORT_RANGE; if the customized value is not provided, ECS Agent will use the default value returned from GetDynamicHostPortRange().

Implementation details

agent/api/task/task.go

  • Add function buildPortMapWithSCIngressConfig() to build a dockerPortMap and a containerPortSet for ingress listener ports
  • Refactor how we create port bindings for service connect ingress listener ports and update comments for function dockerPortMap()

agent/api/task/task_test.go

  • Update test cases in TestDockerHostConfigSCBridgeMode to test changes

agent/utils/ephemeral_ports.go

  • Add ResetTracker() and use it in TestGetHostPort and TestGetHostPortRange

agent/utils/ephemeral_ports_test.go

  • Use ResetTracker() in TestGetHostPort and TestGetHostPortRange
  • Add TestResetTracker

Testing

New tests cover the changes: yes

Unit test

TestDockerHostConfigSCBridgeMode

--- PASS: TestDockerHostConfigSCBridgeMode (0.00s)
    --- PASS: TestDockerHostConfigSCBridgeMode/with_default_dynamic_host_port_range (0.00s)
    --- PASS: TestDockerHostConfigSCBridgeMode/with_user-specified_dynamic_host_port_range (0.00s)
    --- PASS: TestDockerHostConfigSCBridgeMode/with_user-specified_dynamic_host_port_range_but_no_available_host_port (0.00s)

TestResetTracker

--- PASS: TestResetTracker (0.00s)

Manual test

See Upudate dockerPortMap() in task.go with dynamic host port range support - part 1 for container port and container port range testing results.

Description for the changelog

[Enhancement] Support user-specified dynamic host port range for a singular port and default bridge mode service connect ingress listener ports

Related PRs

  1. [DHPA] Add GetHostPort() and update unit tests aws/amazon-ecs-agent#3570
  2. Remove fallback to Docker for host port ranges assignment aws/amazon-ecs-agent#3569
  3. Add new config option for DynamicHostPortRange  aws/amazon-ecs-agent#3522
  4. [DHPA] Upudate dockerPortMap() in task.go with dynamic host port range support - part 1 aws/amazon-ecs-agent#3584

Licensing

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant