Skip to content

Commit

Permalink
Merge pull request #2596 from cyastella/ipv6
Browse files Browse the repository at this point in the history
add IPv6SubnetCIDRBlock for awsvpc task in task metadata
  • Loading branch information
cyastella authored Aug 28, 2020
2 parents 81d0561 + 0a00fc6 commit e1de982
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
11 changes: 2 additions & 9 deletions agent/handlers/v4/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
package v4

import (
"net"

"github.com/aws/amazon-ecs-agent/agent/api"
apitask "github.com/aws/amazon-ecs-agent/agent/api/task"
"github.com/aws/amazon-ecs-agent/agent/containermetadata"
Expand Down Expand Up @@ -168,12 +166,6 @@ func toV4NetworkResponse(
// task.
func newNetworkInterfaceProperties(task *apitask.Task) (NetworkInterfaceProperties, error) {
eni := task.GetPrimaryENI()
_, ipv4Net, err := net.ParseCIDR(eni.SubnetGatewayIPV4Address)
if err != nil {
return NetworkInterfaceProperties{}, errors.Wrapf(err,
"v4 metadata response: unable to parse subnet ipv4 address '%s'",
eni.SubnetGatewayIPV4Address)
}

var attachmentIndexPtr *int
if task.IsNetworkModeAWSVPC() {
Expand All @@ -186,7 +178,8 @@ func newNetworkInterfaceProperties(task *apitask.Task) (NetworkInterfaceProperti
// `Index` field for an ENI, we should set it as per that. Since we
// only support 1 ENI per task anyway, setting it to `0` is acceptable
AttachmentIndex: attachmentIndexPtr,
IPV4SubnetCIDRBlock: ipv4Net.String(),
IPV4SubnetCIDRBlock: eni.GetIPv4SubnetCIDRBlock(),
IPv6SubnetCIDRBlock: eni.GetIPv6SubnetCIDRBlock(),
MACAddress: eni.MacAddress,
DomainNameServers: eni.DomainNameServers,
DomainNameSearchList: eni.DomainNameSearchList,
Expand Down
12 changes: 11 additions & 1 deletion agent/handlers/v4/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const (
cpu = 1024
memory = 512
eniIPv4Address = "192.168.0.5"
ipv4SubnetCIDRBlock = "192.168.0.0/24"
eniIPv6Address = "2600:1f18:619e:f900:8467:78b2:81c4:207d"
ipv6SubnetCIDRBlock = "2600:1f18:619e:f900::/64"
subnetGatewayIPV4Address = "192.168.0.1/24"
volName = "volume1"
volSource = "/var/lib/volume1"
Expand Down Expand Up @@ -73,6 +76,11 @@ func TestNewTaskContainerResponses(t *testing.T) {
Address: eniIPv4Address,
},
},
IPV6Addresses: []*apieni.ENIIPV6Address{
{
Address: eniIPv6Address,
},
},
SubnetGatewayIPV4Address: subnetGatewayIPV4Address,
},
},
Expand Down Expand Up @@ -130,7 +138,9 @@ func TestNewTaskContainerResponses(t *testing.T) {
_, err = json.Marshal(taskResponse)
require.NoError(t, err)
assert.Equal(t, created.UTC().String(), taskResponse.Containers[0].CreatedAt.String())
assert.Equal(t, "192.168.0.0/24", taskResponse.Containers[0].Networks[0].IPV4SubnetCIDRBlock)
assert.Equal(t, ipv4SubnetCIDRBlock, taskResponse.Containers[0].Networks[0].IPV4SubnetCIDRBlock)
assert.Equal(t, eniIPv6Address, taskResponse.Containers[0].Networks[0].IPv6Addresses[0])
assert.Equal(t, ipv6SubnetCIDRBlock, taskResponse.Containers[0].Networks[0].IPv6SubnetCIDRBlock)
assert.Equal(t, subnetGatewayIPV4Address, taskResponse.Containers[0].Networks[0].SubnetGatewayIPV4Address)

gomock.InOrder(
Expand Down

0 comments on commit e1de982

Please sign in to comment.