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 eni and appmesh ecs-agent module, and refactor eni to have a more general naming "NetworkInterface" with expanded attributes #3801

Merged
merged 1 commit into from
Aug 16, 2023
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
10 changes: 5 additions & 5 deletions agent/acs/handler/attach_eni_handler_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"github.com/aws/amazon-ecs-agent/agent/data"
"github.com/aws/amazon-ecs-agent/agent/engine/dockerstate"
"github.com/aws/amazon-ecs-agent/agent/utils"
apieni "github.com/aws/amazon-ecs-agent/ecs-agent/api/eni"
"github.com/aws/amazon-ecs-agent/ecs-agent/logger"
"github.com/aws/amazon-ecs-agent/ecs-agent/logger/field"
ni "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/networkinterface"
"github.com/aws/amazon-ecs-agent/ecs-agent/utils/arn"
"github.com/cihub/seelog"
"github.com/pkg/errors"
Expand All @@ -48,7 +48,7 @@ func NewENIHandler(state dockerstate.TaskEngineState, dataClient data.Client) *e
// 2. Otherwise add the attachment to state, start its ack timer, and save the state
// These are common tasks for handling a task ENI attachment and an instance ENI attachment, so they are put
// into this function to be shared by both attachment handlers
func (eniHandler *eniHandler) HandleENIAttachment(ea *apieni.ENIAttachment) error {
func (eniHandler *eniHandler) HandleENIAttachment(ea *ni.ENIAttachment) error {
attachmentType := ea.AttachmentType
attachmentARN := ea.AttachmentARN
taskARN := ea.TaskARN
Expand All @@ -70,7 +70,7 @@ func (eniHandler *eniHandler) HandleENIAttachment(ea *apieni.ENIAttachment) erro
}

// addENIAttachmentToState adds an ENI attachment to state, and start its ack timer
func (eniHandler *eniHandler) addENIAttachmentToState(ea *apieni.ENIAttachment) error {
func (eniHandler *eniHandler) addENIAttachmentToState(ea *ni.ENIAttachment) error {
attachmentType := ea.AttachmentType
attachmentARN := ea.AttachmentARN
taskARN := ea.TaskARN
Expand All @@ -82,14 +82,14 @@ func (eniHandler *eniHandler) addENIAttachmentToState(ea *apieni.ENIAttachment)
}

switch attachmentType {
case apieni.ENIAttachmentTypeTaskENI:
case ni.ENIAttachmentTypeTaskENI:
taskId, _ := arn.TaskIdFromArn(taskARN)
logger.Info("Adding eni attachment info to state for task", logger.Fields{
field.TaskID: taskId,
"attachmentARN": attachmentARN,
"mac": mac,
})
case apieni.ENIAttachmentTypeInstanceENI:
case ni.ENIAttachmentTypeInstanceENI:
logger.Info("Adding instance eni attachment info to state", logger.Fields{
"attachmentARN": attachmentARN,
"mac": mac,
Expand Down
26 changes: 13 additions & 13 deletions agent/acs/handler/attach_eni_handler_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/aws/amazon-ecs-agent/agent/engine/dockerstate"
"github.com/aws/amazon-ecs-agent/ecs-agent/acs/session/testconst"
"github.com/aws/amazon-ecs-agent/ecs-agent/api/attachmentinfo"
apieni "github.com/aws/amazon-ecs-agent/ecs-agent/api/eni"
ni "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/networkinterface"
)

const (
Expand All @@ -36,12 +36,12 @@ const (

// TestTaskENIAckTimeout tests acknowledge timeout for a task eni before submit the state change
func TestTaskENIAckTimeout(t *testing.T) {
testENIAckTimeout(t, apieni.ENIAttachmentTypeTaskENI)
testENIAckTimeout(t, ni.ENIAttachmentTypeTaskENI)
}

// TestInstanceENIAckTimeout tests acknowledge timeout for an instance level eni before submit the state change
func TestInstanceENIAckTimeout(t *testing.T) {
testENIAckTimeout(t, apieni.ENIAttachmentTypeInstanceENI)
testENIAckTimeout(t, ni.ENIAttachmentTypeInstanceENI)
}

func testENIAckTimeout(t *testing.T, attachmentType string) {
Expand All @@ -52,7 +52,7 @@ func testENIAckTimeout(t *testing.T, attachmentType string) {
dataClient := newTestDataClient(t)

expiresAt := time.Now().Add(time.Millisecond * testconst.WaitTimeoutMillis)
eniAttachment := &apieni.ENIAttachment{
eniAttachment := &ni.ENIAttachment{
AttachmentInfo: attachmentinfo.AttachmentInfo{
TaskARN: testconst.TaskARN,
AttachmentARN: attachmentArn,
Expand Down Expand Up @@ -83,12 +83,12 @@ func testENIAckTimeout(t *testing.T, attachmentType string) {

// TestTaskENIAckWithinTimeout tests the eni state change was reported before the timeout, for a task eni
func TestTaskENIAckWithinTimeout(t *testing.T) {
testENIAckWithinTimeout(t, apieni.ENIAttachmentTypeTaskENI)
testENIAckWithinTimeout(t, ni.ENIAttachmentTypeTaskENI)
}

// TestInstanceENIAckWithinTimeout tests the eni state change was reported before the timeout, for an instance eni
func TestInstanceENIAckWithinTimeout(t *testing.T) {
testENIAckWithinTimeout(t, apieni.ENIAttachmentTypeInstanceENI)
testENIAckWithinTimeout(t, ni.ENIAttachmentTypeInstanceENI)
}

func testENIAckWithinTimeout(t *testing.T, attachmentType string) {
Expand All @@ -98,7 +98,7 @@ func testENIAckWithinTimeout(t *testing.T, attachmentType string) {
taskEngineState := dockerstate.NewTaskEngineState()
dataClient := data.NewNoopClient()
expiresAt := time.Now().Add(time.Millisecond * testconst.WaitTimeoutMillis)
eniAttachment := &apieni.ENIAttachment{
eniAttachment := &ni.ENIAttachment{
AttachmentInfo: attachmentinfo.AttachmentInfo{
TaskARN: testconst.TaskARN,
AttachmentARN: attachmentArn,
Expand All @@ -124,12 +124,12 @@ func testENIAckWithinTimeout(t *testing.T, attachmentType string) {

// TestHandleENIAttachmentTaskENI tests handling a new task eni
func TestHandleENIAttachmentTaskENI(t *testing.T) {
testHandleENIAttachment(t, apieni.ENIAttachmentTypeTaskENI, testconst.TaskARN)
testHandleENIAttachment(t, ni.ENIAttachmentTypeTaskENI, testconst.TaskARN)
}

// TestHandleENIAttachmentInstanceENI tests handling a new instance eni
func TestHandleENIAttachmentInstanceENI(t *testing.T) {
testHandleENIAttachment(t, apieni.ENIAttachmentTypeInstanceENI, "")
testHandleENIAttachment(t, ni.ENIAttachmentTypeInstanceENI, "")
}

func testHandleENIAttachment(t *testing.T, attachmentType, taskArn string) {
Expand All @@ -140,7 +140,7 @@ func testHandleENIAttachment(t *testing.T, attachmentType, taskArn string) {

taskEngineState := dockerstate.NewTaskEngineState()
expiresAt := time.Now().Add(time.Millisecond * testconst.WaitTimeoutMillis)
eniAttachment := &apieni.ENIAttachment{
eniAttachment := &ni.ENIAttachment{
AttachmentInfo: attachmentinfo.AttachmentInfo{
TaskARN: taskArn,
AttachmentARN: attachmentArn,
Expand Down Expand Up @@ -169,12 +169,12 @@ func testHandleENIAttachment(t *testing.T, attachmentType, taskArn string) {

// TestHandleExpiredENIAttachmentTaskENI tests handling an expired task eni
func TestHandleExpiredENIAttachmentTaskENI(t *testing.T) {
testHandleExpiredENIAttachment(t, apieni.ENIAttachmentTypeTaskENI, testconst.TaskARN)
testHandleExpiredENIAttachment(t, ni.ENIAttachmentTypeTaskENI, testconst.TaskARN)
}

// TestHandleExpiredENIAttachmentInstanceENI tests handling an expired instance eni
func TestHandleExpiredENIAttachmentInstanceENI(t *testing.T) {
testHandleExpiredENIAttachment(t, apieni.ENIAttachmentTypeInstanceENI, "")
testHandleExpiredENIAttachment(t, ni.ENIAttachmentTypeInstanceENI, "")
}

func testHandleExpiredENIAttachment(t *testing.T, attachmentType, taskArn string) {
Expand All @@ -187,7 +187,7 @@ func testHandleExpiredENIAttachment(t *testing.T, attachmentType, taskArn string
taskEngineState := dockerstate.NewTaskEngineState()
dataClient := data.NewNoopClient()

eniAttachment := &apieni.ENIAttachment{
eniAttachment := &ni.ENIAttachment{
AttachmentInfo: attachmentinfo.AttachmentInfo{
TaskARN: taskArn,
AttachmentARN: attachmentArn,
Expand Down
4 changes: 2 additions & 2 deletions agent/acs/handler/attach_instance_eni_responder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
acssession "github.com/aws/amazon-ecs-agent/ecs-agent/acs/session"
"github.com/aws/amazon-ecs-agent/ecs-agent/acs/session/testconst"
"github.com/aws/amazon-ecs-agent/ecs-agent/api/attachmentinfo"
apieni "github.com/aws/amazon-ecs-agent/ecs-agent/api/eni"
ni "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/networkinterface"
)

var testAttachInstanceENIMessage = &ecsacs.AttachInstanceNetworkInterfacesMessage{
Expand Down Expand Up @@ -112,7 +112,7 @@ func TestInstanceENIAckSingleMessageWithDuplicateENIAttachment(t *testing.T) {
// the task engine state.
mockState.EXPECT().
ENIByMac(testconst.RandomMAC).
Return(&apieni.ENIAttachment{
Return(&ni.ENIAttachment{
AttachmentInfo: attachmentinfo.AttachmentInfo{
ExpiresAt: expiresAt,
},
Expand Down
4 changes: 2 additions & 2 deletions agent/acs/handler/attach_task_eni_responder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
acssession "github.com/aws/amazon-ecs-agent/ecs-agent/acs/session"
"github.com/aws/amazon-ecs-agent/ecs-agent/acs/session/testconst"
"github.com/aws/amazon-ecs-agent/ecs-agent/api/attachmentinfo"
apieni "github.com/aws/amazon-ecs-agent/ecs-agent/api/eni"
ni "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/networkinterface"
)

var testAttachTaskENIMessage = &ecsacs.AttachTaskNetworkInterfacesMessage{
Expand Down Expand Up @@ -112,7 +112,7 @@ func TestTaskENIAckSingleMessageWithDuplicateENIAttachment(t *testing.T) {
// the task engine state.
mockState.EXPECT().
ENIByMac(testconst.RandomMAC).
Return(&apieni.ENIAttachment{
Return(&ni.ENIAttachment{
AttachmentInfo: attachmentinfo.AttachmentInfo{
ExpiresAt: expiresAt,
},
Expand Down
8 changes: 4 additions & 4 deletions agent/acs/handler/payload_responder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ import (
"fmt"

"github.com/aws/amazon-ecs-agent/agent/api"
apiappmesh "github.com/aws/amazon-ecs-agent/agent/api/appmesh"
apitask "github.com/aws/amazon-ecs-agent/agent/api/task"
apitaskstatus "github.com/aws/amazon-ecs-agent/agent/api/task/status"
"github.com/aws/amazon-ecs-agent/agent/data"
"github.com/aws/amazon-ecs-agent/agent/engine"
"github.com/aws/amazon-ecs-agent/agent/eventhandler"
"github.com/aws/amazon-ecs-agent/ecs-agent/acs/model/ecsacs"
apieni "github.com/aws/amazon-ecs-agent/ecs-agent/api/eni"
"github.com/aws/amazon-ecs-agent/ecs-agent/credentials"
"github.com/aws/amazon-ecs-agent/ecs-agent/logger"
loggerfield "github.com/aws/amazon-ecs-agent/ecs-agent/logger/field"
nlappmesh "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/appmesh"
ni "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/networkinterface"
"github.com/aws/aws-sdk-go/aws"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -140,7 +140,7 @@ func (pmHandler *payloadMessageHandler) addPayloadTasks(payload *ecsacs.PayloadM

// Add ENI information to the task struct.
for _, acsENI := range task.ElasticNetworkInterfaces {
eni, err := apieni.ENIFromACS(acsENI)
eni, err := ni.ENIFromACS(acsENI)
if err != nil {
pmHandler.handleInvalidTask(task, err, payload)
allTasksOK = false
Expand All @@ -151,7 +151,7 @@ func (pmHandler *payloadMessageHandler) addPayloadTasks(payload *ecsacs.PayloadM

// Add the app mesh information to task struct.
if task.ProxyConfiguration != nil {
appmesh, err := apiappmesh.AppMeshFromACS(task.ProxyConfiguration)
appmesh, err := nlappmesh.AppMeshFromACS(task.ProxyConfiguration)
if err != nil {
pmHandler.handleInvalidTask(task, err, payload)
allTasksOK = false
Expand Down
4 changes: 2 additions & 2 deletions agent/api/ecsclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import (
"github.com/aws/amazon-ecs-agent/agent/config"
"github.com/aws/amazon-ecs-agent/agent/ec2"
mock_ec2 "github.com/aws/amazon-ecs-agent/agent/ec2/mocks"
apieni "github.com/aws/amazon-ecs-agent/ecs-agent/api/eni"
"github.com/aws/amazon-ecs-agent/ecs-agent/ecs_client/model/ecs"
ni "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/networkinterface"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials"
Expand Down Expand Up @@ -1085,7 +1085,7 @@ func TestSubmitTaskStateChangeWithAttachments(t *testing.T) {

err := client.SubmitTaskStateChange(api.TaskStateChange{
TaskARN: "task_arn",
Attachment: &apieni.ENIAttachment{
Attachment: &ni.ENIAttachment{
AttachmentInfo: attachmentinfo.AttachmentInfo{
AttachmentARN: "eni_arn",
Status: status.AttachmentAttached,
Expand Down
8 changes: 4 additions & 4 deletions agent/api/statechange.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
apitask "github.com/aws/amazon-ecs-agent/agent/api/task"
apitaskstatus "github.com/aws/amazon-ecs-agent/agent/api/task/status"
"github.com/aws/amazon-ecs-agent/agent/statechange"
apieni "github.com/aws/amazon-ecs-agent/ecs-agent/api/eni"
"github.com/aws/amazon-ecs-agent/ecs-agent/logger"
ni "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/networkinterface"
"github.com/pkg/errors"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -73,7 +73,7 @@ type ManagedAgentStateChange struct {
// SubmitTaskStateChange API
type TaskStateChange struct {
// Attachment is the eni attachment object to send
Attachment *apieni.ENIAttachment
Attachment *ni.ENIAttachment
// TaskArn is the unique identifier for the task
TaskARN string
// Status is the status to send
Expand All @@ -99,7 +99,7 @@ type TaskStateChange struct {
// SubmitAttachmentStateChanges API
type AttachmentStateChange struct {
// Attachment is the eni attachment object to send
Attachment *apieni.ENIAttachment
Attachment *ni.ENIAttachment
}

type ErrShouldNotSendEvent struct {
Expand Down Expand Up @@ -218,7 +218,7 @@ func NewManagedAgentChangeEvent(task *apitask.Task, cont *apicontainer.Container
}

// NewAttachmentStateChangeEvent creates a new attachment state change event
func NewAttachmentStateChangeEvent(eniAttachment *apieni.ENIAttachment) AttachmentStateChange {
func NewAttachmentStateChangeEvent(eniAttachment *ni.ENIAttachment) AttachmentStateChange {
return AttachmentStateChange{
Attachment: eniAttachment,
}
Expand Down
23 changes: 11 additions & 12 deletions agent/api/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
"sync"
"time"

apiappmesh "github.com/aws/amazon-ecs-agent/agent/api/appmesh"
"github.com/aws/amazon-ecs-agent/agent/api/container"
apicontainer "github.com/aws/amazon-ecs-agent/agent/api/container"
apicontainerstatus "github.com/aws/amazon-ecs-agent/agent/api/container/status"
"github.com/aws/amazon-ecs-agent/agent/api/serviceconnect"
Expand All @@ -45,12 +43,13 @@ import (
taskresourcevolume "github.com/aws/amazon-ecs-agent/agent/taskresource/volume"
"github.com/aws/amazon-ecs-agent/agent/utils"
"github.com/aws/amazon-ecs-agent/ecs-agent/acs/model/ecsacs"
apieni "github.com/aws/amazon-ecs-agent/ecs-agent/api/eni"
apierrors "github.com/aws/amazon-ecs-agent/ecs-agent/api/errors"
"github.com/aws/amazon-ecs-agent/ecs-agent/credentials"
"github.com/aws/amazon-ecs-agent/ecs-agent/ecs_client/model/ecs"
"github.com/aws/amazon-ecs-agent/ecs-agent/logger"
"github.com/aws/amazon-ecs-agent/ecs-agent/logger/field"
nlappmesh "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/appmesh"
ni "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/networkinterface"
"github.com/aws/amazon-ecs-agent/ecs-agent/utils/arn"
"github.com/aws/amazon-ecs-agent/ecs-agent/utils/ttime"

Expand Down Expand Up @@ -251,7 +250,7 @@ type Task struct {
ENIs TaskENIs `json:"ENI"`

// AppMesh is the service mesh specified by the task
AppMesh *apiappmesh.AppMesh
AppMesh *nlappmesh.AppMesh

// MemoryCPULimitsEnabled to determine if task supports CPU, memory limits
MemoryCPULimitsEnabled bool `json:"MemoryCPULimitsEnabled,omitempty"`
Expand Down Expand Up @@ -2770,18 +2769,18 @@ func (task *Task) SetSentStatus(status apitaskstatus.TaskStatus) {
}

// AddTaskENI adds ENI information to the task.
func (task *Task) AddTaskENI(eni *apieni.ENI) {
func (task *Task) AddTaskENI(eni *ni.NetworkInterface) {
task.lock.Lock()
defer task.lock.Unlock()

if task.ENIs == nil {
task.ENIs = make([]*apieni.ENI, 0)
task.ENIs = make([]*ni.NetworkInterface, 0)
}
task.ENIs = append(task.ENIs, eni)
}

// GetTaskENIs returns the list of ENIs for the task.
func (task *Task) GetTaskENIs() []*apieni.ENI {
func (task *Task) GetTaskENIs() []*ni.NetworkInterface {
// TODO: what's the point of locking if we are returning a pointer?
task.lock.RLock()
defer task.lock.RUnlock()
Expand All @@ -2791,7 +2790,7 @@ func (task *Task) GetTaskENIs() []*apieni.ENI {

// GetPrimaryENI returns the primary ENI of the task. Since ACS can potentially send
// multiple ENIs to the agent, the first ENI in the list is considered as the primary ENI.
func (task *Task) GetPrimaryENI() *apieni.ENI {
func (task *Task) GetPrimaryENI() *ni.NetworkInterface {
task.lock.RLock()
defer task.lock.RUnlock()

Expand All @@ -2803,15 +2802,15 @@ func (task *Task) GetPrimaryENI() *apieni.ENI {
}

// SetAppMesh sets the app mesh config of the task
func (task *Task) SetAppMesh(appMesh *apiappmesh.AppMesh) {
func (task *Task) SetAppMesh(appMesh *nlappmesh.AppMesh) {
task.lock.Lock()
defer task.lock.Unlock()

task.AppMesh = appMesh
}

// GetAppMesh returns the app mesh config of the task
func (task *Task) GetAppMesh() *apiappmesh.AppMesh {
func (task *Task) GetAppMesh() *nlappmesh.AppMesh {
task.lock.RLock()
defer task.lock.RUnlock()

Expand Down Expand Up @@ -3595,9 +3594,9 @@ func (task *Task) ToHostResources() map[string]*ecs.Resource {
for _, port := range c.Ports {
hostPort := port.HostPort
protocol := port.Protocol
if hostPort > 0 && protocol == container.TransportProtocolTCP {
if hostPort > 0 && protocol == apicontainer.TransportProtocolTCP {
tcpPortSet = append(tcpPortSet, hostPort)
} else if hostPort > 0 && protocol == container.TransportProtocolUDP {
} else if hostPort > 0 && protocol == apicontainer.TransportProtocolUDP {
udpPortSet = append(udpPortSet, hostPort)
}
}
Expand Down
Loading