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

Fix for the attchmentIndex #2389

Merged
merged 1 commit into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions agent/handlers/task_server_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ var (
ExecutionStoppedAt: aws.Time(now.UTC()),
AvailabilityZone: availabilityzone,
}
attachmentIndexVar = attachmentIndex
expectedV4ContainerResponse = v4.ContainerResponse{
ContainerResponse: &expectedContainerResponse,
Networks: []v4.Network{{
Expand All @@ -302,7 +303,7 @@ var (
IPv4Addresses: []string{eniIPv4Address},
},
NetworkInterfaceProperties: v4.NetworkInterfaceProperties{
AttachmentIndex: attachmentIndex,
AttachmentIndex: &attachmentIndexVar,
IPV4SubnetCIDRBlock: iPv4SubnetCIDRBlock,
MACAddress: macAddress,
PrivateDNSName: privateDNSName,
Expand All @@ -322,7 +323,7 @@ var (
IPv4Addresses: []string{bridgeIPAddr},
},
NetworkInterfaceProperties: v4.NetworkInterfaceProperties{
AttachmentIndex: attachmentIndex,
AttachmentIndex: nil,
IPV4SubnetCIDRBlock: "",
MACAddress: "",
PrivateDNSName: "",
Expand Down
23 changes: 15 additions & 8 deletions agent/handlers/v4/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ type Network struct {
type NetworkInterfaceProperties struct {
// AttachmentIndex reflects the `index` specified by the customer (if any)
// while creating the task with `awsvpc` mode.
AttachmentIndex int `json:"AttachmentIndex"`
AttachmentIndex *int `json:"AttachmentIndex,omitempty"`
// IPV4SubnetCIDRBlock is the subnet CIDR netmask associated with network interface.
IPV4SubnetCIDRBlock string `json:"IPv4SubnetCIDRBlock,ommitempty"`
IPV4SubnetCIDRBlock string `json:"IPv4SubnetCIDRBlock,omitempty"`
// MACAddress is the mac address of the network interface.
MACAddress string `json:"MACAddress,ommitempty"`
MACAddress string `json:"MACAddress,omitempty"`
// DomainNameServers specifies the nameserver IP addresses for the network interface.
DomainNameServers []string `json:"DomainNameServers,omitempty"`
// DomainNameSearchList specifies the search list for the domain name lookup for
Expand All @@ -69,7 +69,7 @@ type NetworkInterfaceProperties struct {
// PrivateDNSName is the dns name assigned to this network interface.
PrivateDNSName string `json:"PrivateDNSName,omitempty"`
// SubnetGatewayIPV4Address is the gateway address for the network interface.
SubnetGatewayIPV4Address string `json:"SubnetGatewayIpv4Address,ommitempty"`
SubnetGatewayIPV4Address string `json:"SubnetGatewayIpv4Address,omitempty"`
}

// NewTaskResponse creates a new v4 response object for the task. It augments v2 task response
Expand All @@ -91,15 +91,15 @@ func NewTaskResponse(
}
var containers []ContainerResponse
// Convert each container response into v4 container response.
for _, container := range v2Resp.Containers {
for i, container := range v2Resp.Containers {
networks, err := toV4NetworkResponse(container.Networks, func() (*apitask.Task, bool) {
return state.TaskByArn(taskARN)
})
if err != nil {
return nil, err
}
containers = append(containers, ContainerResponse{
ContainerResponse: &container,
ContainerResponse: &v2Resp.Containers[i],
Networks: networks,
})
}
Expand Down Expand Up @@ -172,11 +172,18 @@ func newNetworkInterfaceProperties(task *apitask.Task) (NetworkInterfaceProperti
"v4 metadata response: unable to parse subnet ipv4 address '%s'",
eni.SubnetGatewayIPV4Address)
}

var attachmentIndexPtr *int
if task.IsNetworkModeAWSVPC() {
var vpcIndex = 0
attachmentIndexPtr = &vpcIndex
}

return NetworkInterfaceProperties{
// TODO this is hard-coded to `0` for now. Once backend starts populating
// `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: 0,
// only support 1 ENI per task anyway, setting it to `0` is acceptable
AttachmentIndex: attachmentIndexPtr,
IPV4SubnetCIDRBlock: ipv4Net.String(),
MACAddress: eni.MacAddress,
DomainNameServers: eni.DomainNameServers,
Expand Down