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

Revert "revert the following commits to exclude from release v1.78.1:" #3997

Merged
merged 1 commit into from
Oct 26, 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
2 changes: 1 addition & 1 deletion agent/acs/session/attach_eni_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (eniHandler *eniHandler) removeENIAttachmentData(mac string) {
seelog.Errorf("Unable to retrieve ENI Attachment for mac address %s: ", mac)
return
}
attachmentId, err := utils.GetENIAttachmentId(attachmentToRemove.AttachmentARN)
attachmentId, err := utils.GetAttachmentId(attachmentToRemove.AttachmentARN)
if err != nil {
seelog.Errorf("Failed to get attachment id for %s: %v", attachmentToRemove.AttachmentARN, err)
} else {
Expand Down
10 changes: 5 additions & 5 deletions agent/acs/session/attach_eni_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/aws/amazon-ecs-agent/agent/data"
"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"
"github.com/aws/amazon-ecs-agent/ecs-agent/api/attachment"
ni "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/networkinterface"
)

Expand All @@ -53,7 +53,7 @@ func testENIAckTimeout(t *testing.T, attachmentType string) {

expiresAt := time.Now().Add(time.Millisecond * testconst.WaitTimeoutMillis)
eniAttachment := &ni.ENIAttachment{
AttachmentInfo: attachmentinfo.AttachmentInfo{
AttachmentInfo: attachment.AttachmentInfo{
TaskARN: testconst.TaskARN,
AttachmentARN: attachmentArn,
ExpiresAt: expiresAt,
Expand Down Expand Up @@ -99,7 +99,7 @@ func testENIAckWithinTimeout(t *testing.T, attachmentType string) {
dataClient := data.NewNoopClient()
expiresAt := time.Now().Add(time.Millisecond * testconst.WaitTimeoutMillis)
eniAttachment := &ni.ENIAttachment{
AttachmentInfo: attachmentinfo.AttachmentInfo{
AttachmentInfo: attachment.AttachmentInfo{
TaskARN: testconst.TaskARN,
AttachmentARN: attachmentArn,
ExpiresAt: expiresAt,
Expand Down Expand Up @@ -141,7 +141,7 @@ func testHandleENIAttachment(t *testing.T, attachmentType, taskArn string) {
taskEngineState := dockerstate.NewTaskEngineState()
expiresAt := time.Now().Add(time.Millisecond * testconst.WaitTimeoutMillis)
eniAttachment := &ni.ENIAttachment{
AttachmentInfo: attachmentinfo.AttachmentInfo{
AttachmentInfo: attachment.AttachmentInfo{
TaskARN: taskArn,
AttachmentARN: attachmentArn,
ExpiresAt: expiresAt,
Expand Down Expand Up @@ -188,7 +188,7 @@ func testHandleExpiredENIAttachment(t *testing.T, attachmentType, taskArn string
dataClient := data.NewNoopClient()

eniAttachment := &ni.ENIAttachment{
AttachmentInfo: attachmentinfo.AttachmentInfo{
AttachmentInfo: attachment.AttachmentInfo{
TaskARN: taskArn,
AttachmentARN: attachmentArn,
ExpiresAt: expiresAt,
Expand Down
4 changes: 2 additions & 2 deletions agent/acs/session/attach_instance_eni_responder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/aws/amazon-ecs-agent/ecs-agent/acs/model/ecsacs"
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"
"github.com/aws/amazon-ecs-agent/ecs-agent/api/attachment"
ni "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/networkinterface"
)

Expand Down Expand Up @@ -113,7 +113,7 @@ func TestInstanceENIAckSingleMessageWithDuplicateENIAttachment(t *testing.T) {
mockState.EXPECT().
ENIByMac(testconst.RandomMAC).
Return(&ni.ENIAttachment{
AttachmentInfo: attachmentinfo.AttachmentInfo{
AttachmentInfo: attachment.AttachmentInfo{
ExpiresAt: expiresAt,
},
}, true).
Expand Down
4 changes: 2 additions & 2 deletions agent/acs/session/attach_task_eni_responder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/aws/amazon-ecs-agent/ecs-agent/acs/model/ecsacs"
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"
"github.com/aws/amazon-ecs-agent/ecs-agent/api/attachment"
ni "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/networkinterface"
)

Expand Down Expand Up @@ -113,7 +113,7 @@ func TestTaskENIAckSingleMessageWithDuplicateENIAttachment(t *testing.T) {
mockState.EXPECT().
ENIByMac(testconst.RandomMAC).
Return(&ni.ENIAttachment{
AttachmentInfo: attachmentinfo.AttachmentInfo{
AttachmentInfo: attachment.AttachmentInfo{
ExpiresAt: expiresAt,
},
}, true).
Expand Down
36 changes: 35 additions & 1 deletion agent/acs/session/payload_responder.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"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"
apiresource "github.com/aws/amazon-ecs-agent/ecs-agent/api/attachment/resource"
apitaskstatus "github.com/aws/amazon-ecs-agent/ecs-agent/api/task/status"
"github.com/aws/amazon-ecs-agent/ecs-agent/credentials"
"github.com/aws/amazon-ecs-agent/ecs-agent/logger"
Expand Down Expand Up @@ -106,6 +107,16 @@ func (pmHandler *payloadMessageHandler) addPayloadTasks(payload *ecsacs.PayloadM
allTasksOK = false
continue
}

// Note: If we receive an EBS-backed task, we'll also received an incomplete volume configuration in the list of Volumes
// To accomodate this, we'll first check if the task IS EBS-backed then we'll mark the corresponding Volume object to be
// of type "attachment". This volume object will be replaced by the newly created EBS volume configuration when we parse
// through the task attachments.
volName, ok := hasEBSAttachment(task)
if ok {
initializeAttachmentTypeVolume(task, volName)
}

apiTask, err := apitask.TaskFromACS(task, payload)
if err != nil {
pmHandler.handleInvalidTask(task, err, payload)
Expand Down Expand Up @@ -140,7 +151,7 @@ func (pmHandler *payloadMessageHandler) addPayloadTasks(payload *ecsacs.PayloadM

// Add ENI information to the task struct.
for _, acsENI := range task.ElasticNetworkInterfaces {
eni, err := ni.ENIFromACS(acsENI)
eni, err := ni.InterfaceFromACS(acsENI)
if err != nil {
pmHandler.handleInvalidTask(task, err, payload)
allTasksOK = false
Expand Down Expand Up @@ -306,3 +317,26 @@ func isTaskStatusStopped(status apitaskstatus.TaskStatus) bool {
func isTaskStatusNotStopped(status apitaskstatus.TaskStatus) bool {
return status != apitaskstatus.TaskStopped
}

func hasEBSAttachment(acsTask *ecsacs.Task) (string, bool) {
// TODO: This will only work if there's one EBS volume per task. If we there is a case where we have multi-attach for a task, this needs to be modified
for _, attachment := range acsTask.Attachments {
if *attachment.AttachmentType == apiresource.EBSTaskAttach {
for _, property := range attachment.AttachmentProperties {
if *property.Name == apiresource.VolumeNameKey {
return *property.Value, true
}
}
}
}
return "", false
}

func initializeAttachmentTypeVolume(acsTask *ecsacs.Task, volName string) {
for _, volume := range acsTask.Volumes {
if *volume.Name == volName && volume.Type == nil {
newType := "attachment"
volume.Type = &newType
}
}
}
14 changes: 10 additions & 4 deletions agent/acs/session/payload_responder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ import (
"github.com/aws/amazon-ecs-agent/ecs-agent/acs/model/ecsacs"
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/eni"
apiresource "github.com/aws/amazon-ecs-agent/ecs-agent/api/resource"
apiresource "github.com/aws/amazon-ecs-agent/ecs-agent/api/attachment/resource"
apitaskstatus "github.com/aws/amazon-ecs-agent/ecs-agent/api/task/status"
"github.com/aws/amazon-ecs-agent/ecs-agent/credentials"
ni "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/networkinterface"
"github.com/aws/amazon-ecs-agent/ecs-agent/wsclient"
"github.com/aws/aws-sdk-go/aws"
"github.com/golang/mock/gomock"
Expand Down Expand Up @@ -725,6 +725,12 @@ func TestHandlePayloadMessageAddedEBSToTask(t *testing.T) {
AttachmentType: aws.String(apiresource.EBSTaskAttach),
},
},
Volumes: []*ecsacs.Volume{
{
Name: aws.String(taskresourcevolume.TestVolumeName),
Type: aws.String(apitask.AttachmentType),
},
},
},
}

Expand Down Expand Up @@ -858,7 +864,7 @@ func TestHandlePayloadMessageAddedENITrunkToTask(t *testing.T) {
Arn: aws.String(testconst.TaskARN),
ElasticNetworkInterfaces: []*ecsacs.ElasticNetworkInterface{
{
InterfaceAssociationProtocol: aws.String(eni.VLANInterfaceAssociationProtocol),
InterfaceAssociationProtocol: aws.String(ni.VLANInterfaceAssociationProtocol),
AttachmentArn: aws.String(attachmentARN),
Ec2Id: aws.String(ec2ID),
Ipv4Addresses: []*ecsacs.IPv4AddressAssignment{
Expand Down Expand Up @@ -890,7 +896,7 @@ func TestHandlePayloadMessageAddedENITrunkToTask(t *testing.T) {

// Validate the added task has the ENI trunk information as expected.
taskeni := addedTask.GetPrimaryENI()
assert.Equal(t, eni.VLANInterfaceAssociationProtocol, taskeni.InterfaceAssociationProtocol)
assert.Equal(t, ni.VLANInterfaceAssociationProtocol, taskeni.InterfaceAssociationProtocol)
assert.Equal(t, testconst.RandomMAC, taskeni.InterfaceVlanProperties.TrunkInterfaceMacAddress)
assert.Equal(t, vlanID, taskeni.InterfaceVlanProperties.VlanID)
}
Expand Down
5 changes: 3 additions & 2 deletions agent/acs/updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ import (
"github.com/aws/amazon-ecs-agent/agent/data"
"github.com/aws/amazon-ecs-agent/agent/engine"
"github.com/aws/amazon-ecs-agent/agent/engine/dockerstate"
"github.com/aws/amazon-ecs-agent/agent/httpclient"
"github.com/aws/amazon-ecs-agent/agent/sighandlers"
"github.com/aws/amazon-ecs-agent/agent/sighandlers/exitcodes"
"github.com/aws/amazon-ecs-agent/agent/utils"
agentversion "github.com/aws/amazon-ecs-agent/agent/version"
"github.com/aws/amazon-ecs-agent/ecs-agent/acs/model/ecsacs"
"github.com/aws/amazon-ecs-agent/ecs-agent/httpclient"
"github.com/aws/amazon-ecs-agent/ecs-agent/utils/ttime"
"github.com/aws/amazon-ecs-agent/ecs-agent/wsclient"

Expand Down Expand Up @@ -79,7 +80,7 @@ func NewUpdater(cfg *config.Config, state dockerstate.TaskEngineState, dataClien
taskEngine engine.TaskEngine) *updater {
return &updater{
config: cfg,
httpclient: httpclient.New(updateDownloadTimeout, false),
httpclient: httpclient.New(updateDownloadTimeout, false, agentversion.String(), config.OSType),
state: state,
dataClient: dataClient,
taskEngine: taskEngine,
Expand Down
7 changes: 4 additions & 3 deletions agent/acs/updater/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ import (
"github.com/aws/amazon-ecs-agent/agent/data"
"github.com/aws/amazon-ecs-agent/agent/engine"
"github.com/aws/amazon-ecs-agent/agent/engine/dockerstate"
"github.com/aws/amazon-ecs-agent/agent/httpclient"
mock_http "github.com/aws/amazon-ecs-agent/agent/httpclient/mock"
agentversion "github.com/aws/amazon-ecs-agent/agent/version"
"github.com/aws/amazon-ecs-agent/ecs-agent/acs/model/ecsacs"
"github.com/aws/amazon-ecs-agent/ecs-agent/httpclient"
mock_http "github.com/aws/amazon-ecs-agent/ecs-agent/httpclient/mock"
mock_client "github.com/aws/amazon-ecs-agent/ecs-agent/wsclient/mock"

"github.com/golang/mock/gomock"
Expand All @@ -58,7 +59,7 @@ func mocks(t *testing.T, cfg *config.Config) (*updater, *gomock.Controller, *moc

mockacs := mock_client.NewMockClientServer(ctrl)
mockhttp := mock_http.NewMockRoundTripper(ctrl)
httpClient := httpclient.New(updateDownloadTimeout, false)
httpClient := httpclient.New(updateDownloadTimeout, false, agentversion.String(), config.OSType)
httpClient.Transport.(httpclient.OverridableTransport).SetTransport(mockhttp)

u := NewUpdater(cfg, dockerstate.NewTaskEngineState(), data.NewNoopClient(),
Expand Down
13 changes: 13 additions & 0 deletions agent/api/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -1508,3 +1508,16 @@ func (c *Container) GetContainerPortRangeMap() map[string]string {
defer c.lock.RUnlock()
return c.ContainerPortRangeMap
}

func (c *Container) IsManagedDaemonContainer() bool {
c.lock.RLock()
defer c.lock.RUnlock()
return c.Type == ContainerManagedDaemon
}

func (c *Container) GetImageName() string {
c.lock.RLock()
defer c.lock.RUnlock()
containerImage := strings.Split(c.Image, ":")[0]
return containerImage
}
42 changes: 41 additions & 1 deletion agent/api/container/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,53 @@ func TestIsInternal(t *testing.T) {
}

for _, tc := range testCases {
t.Run(fmt.Sprintf("IsInternal shoukd return %t for %s", tc.internal, tc.container.String()),
t.Run(fmt.Sprintf("IsInternal should return %t for %s", tc.internal, tc.container.String()),
func(t *testing.T) {
assert.Equal(t, tc.internal, tc.container.IsInternal())
})
}
}

func TestIsManagedDaemonContainer(t *testing.T) {
testCases := []struct {
container *Container
internal bool
isManagedDaemon bool
}{
{&Container{}, false, false},
{&Container{Type: ContainerNormal, Image: "someImage:latest"}, false, false},
{&Container{Type: ContainerManagedDaemon, Image: "someImage:latest"}, true, true},
}

for _, tc := range testCases {
t.Run(fmt.Sprintf("IsManagedDaemonContainer should return %t for %s", tc.isManagedDaemon, tc.container.String()),
func(t *testing.T) {
assert.Equal(t, tc.internal, tc.container.IsInternal())
ok := tc.container.IsManagedDaemonContainer()
assert.Equal(t, tc.isManagedDaemon, ok)
})
}
}

func TestGetImageName(t *testing.T) {
testCases := []struct {
container *Container
imageName string
}{
{&Container{}, ""},
{&Container{Image: "someImage:latest"}, "someImage"},
{&Container{Image: "someImage"}, "someImage"},
}

for _, tc := range testCases {
t.Run(fmt.Sprintf("GetImageName should return %s for %s", tc.imageName, tc.container.String()),
func(t *testing.T) {
imageName := tc.container.GetImageName()
assert.Equal(t, tc.imageName, imageName)
})
}
}

// TestSetupExecutionRoleFlag tests whether or not the container appropriately
// sets the flag for using execution roles
func TestSetupExecutionRoleFlag(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions agent/api/container/containertype.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var stringToContainerType = map[string]ContainerType{
"EMPTY_HOST_VOLUME": ContainerEmptyHostVolume,
"CNI_PAUSE": ContainerCNIPause,
"NAMESPACE_PAUSE": ContainerNamespacePause,
"MANAGED_DAEMON": ContainerManagedDaemon,
}

// String converts the container type enum to a string
Expand Down
Loading