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

Add Host IP to port response for v4 container response #3136

Merged
merged 1 commit into from Mar 1, 2022

Conversation

mythri-garaga
Copy link
Contributor

Summary

Currently there is no way to identify ipv4 ports vs ipv6 ports from Task metadata endpoint v4. This PR includes changes to add Host IP to port response for Task metadata endpoint v4

Related to issue - #3096

Implementation details

  • agent/handlers/v1/response.go : updated PortResponse struct to include HostIp field.
  • agent/handlers/v2/response.go : added HostIp to container response if includeV4Metadata flag is set
  • agent/handlers/v2/response_test.go: updated TestContainerResponseMarshal() test to check if containerResponse for includes HostIp when includeV4Metadata is set

Testing

Tested this change by running a task with container port mappings configured on a IPv6 enabled instance and see the following response for curl ${ECS_CONTAINER_METADATA_URI_V4:-}/task | jq

{
  "Cluster": "default",
  ...
  "Containers": [
    {
      "DockerId": "502ec633cc68f7e7ebdc00ae9b0c1f7ef730a0a9b3dc747107e5cfd91a42fb11",
      "Name": "server",
      "DockerName": "ecs-nginx-server-3-server-84f9f8dbe4879a8e8801",
      "Image": "nginx:latest",
      "ImageID": "sha256:c316d5a335a5cf324b0dc83b3da82d7608724769f6454f6d9a621f3ec2534a5a",
      "Ports": [
        {
          "ContainerPort": 8888,
          "Protocol": "tcp",
          "HostPort": 49825,
          "HostIp": "0.0.0.0"
        },
        {
          "ContainerPort": 8888,
          "Protocol": "tcp",
          "HostPort": 49825,
          "HostIp": "::"
        },
        {
          "ContainerPort": 8888,
          "Protocol": "tcp",
          "HostPort": 49832,
          "HostIp": "0.0.0.0"
        },
        {
          "ContainerPort": 8888,
          "Protocol": "tcp",
          "HostPort": 49832,
          "HostIp": "::"
        }
      ],
      ...
}

Container response with v2 curl ${ECS_CONTAINER_METADATA_URI:-}/task | jq

{
  "Cluster": "default",
   ...
  "Containers": [
    {
      "DockerId": "502ec633cc68f7e7ebdc00ae9b0c1f7ef730a0a9b3dc747107e5cfd91a42fb11",
      "Name": "server",
      "DockerName": "ecs-nginx-server-3-server-84f9f8dbe4879a8e8801",
      "Image": "nginx:latest",
      "ImageID": "sha256:c316d5a335a5cf324b0dc83b3da82d7608724769f6454f6d9a621f3ec2534a5a",
      "Ports": [
        {
          "ContainerPort": 8888,
          "Protocol": "tcp",
          "HostPort": 49825
        },
        {
          "ContainerPort": 8888,
          "Protocol": "tcp",
          "HostPort": 49825
        },
        {
          "ContainerPort": 8888,
          "Protocol": "tcp",
          "HostPort": 49832
        },
        {
          "ContainerPort": 8888,
          "Protocol": "tcp",
          "HostPort": 49832
        }
      ],
...
}

New tests cover the changes: yes

Description for the changelog

Licensing

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

@mythri-garaga mythri-garaga merged commit 5a9ddd7 into aws:dev Mar 1, 2022
@mythri-garaga mythri-garaga deleted the task_metadata_host_ip_address branch March 1, 2022 21:33
@chienhanlin chienhanlin mentioned this pull request Mar 2, 2022
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.

None yet

5 participants