From 99e242a040ee9524c5b43f7c30c9aa3fe807e6f3 Mon Sep 17 00:00:00 2001 From: Ray Allan Date: Wed, 11 Oct 2023 23:30:26 +0000 Subject: [PATCH] add missing changes from feature branch --- agent/app/agent.go | 2 +- agent/ebs/watcher.go | 13 ++++++++++--- agent/engine/docker_task_engine.go | 11 +++++++++++ .../engine/dockerstate/docker_task_engine_state.go | 4 ++-- agent/eventhandler/attachment_handler.go | 12 ++++++------ 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/agent/app/agent.go b/agent/app/agent.go index a232fc7088d..11ef156952f 100644 --- a/agent/app/agent.go +++ b/agent/app/agent.go @@ -1041,7 +1041,7 @@ func (agent *ecsAgent) startACSSession( taskComparer, sequenceNumberAccessor, taskStopper, - nil, + agent.ebsWatcher, updater.NewUpdater(agent.cfg, state, agent.dataClient, taskEngine).AddAgentUpdateHandlers, ) logger.Info("Beginning Polling for updates") diff --git a/agent/ebs/watcher.go b/agent/ebs/watcher.go index 8fd2a0d9caf..3bc4ac03a2d 100644 --- a/agent/ebs/watcher.go +++ b/agent/ebs/watcher.go @@ -17,7 +17,9 @@ import ( "context" "errors" "fmt" + "path/filepath" "strconv" + "strings" "time" ecsapi "github.com/aws/amazon-ecs-agent/agent/api" @@ -193,7 +195,10 @@ func (w *EBSWatcher) StageAll(foundVolumes map[string]string) error { log.Debugf("EBS status is already attached, skipping: %v.", ebsAttachment.EBSToString()) continue } - hostPath := ebsAttachment.GetAttachmentProperties(apiebs.SourceVolumeHostPathKey) + + preHostPath := ebsAttachment.GetAttachmentProperties(apiebs.SourceVolumeHostPathKey) + hostPath := filepath.Join("/mnt/ecs/ebs", preHostPath[strings.LastIndex(preHostPath, "/")+1:]) + filesystemType := ebsAttachment.GetAttachmentProperties(apiebs.FileSystemTypeName) // CSI NodeStage stub required fields @@ -314,10 +319,12 @@ func (w *EBSWatcher) emitEBSAttachedEvent(ebsvol *apiebs.ResourceAttachment) { ClusterARN: ebsvol.GetClusterARN(), ContainerInstanceARN: ebsvol.GetContainerInstanceARN(), } + eniWrapper := apieni.ENIAttachment{AttachmentInfo: attachmentInfo} + eniWrapper.AttachmentType = apieni.ENIAttachmentTypeTaskENI attachmentChange := ecsapi.AttachmentStateChange{ - Attachment: &apieni.ENIAttachment{AttachmentInfo: attachmentInfo}, + Attachment: &eniWrapper, } - log.Debugf("Emitting EBS volume attached event for: %v", ebsvol) + log.Debugf("Emitting EBS volume attached event for: %v, change event: %v", ebsvol, eniWrapper) w.taskEngine.StateChangeEvents() <- attachmentChange } diff --git a/agent/engine/docker_task_engine.go b/agent/engine/docker_task_engine.go index 92a7fcd2304..8216dd42c21 100644 --- a/agent/engine/docker_task_engine.go +++ b/agent/engine/docker_task_engine.go @@ -1215,6 +1215,11 @@ func (engine *DockerTaskEngine) GetTaskByArn(arn string) (*apitask.Task, bool) { func (engine *DockerTaskEngine) GetDaemonTask(daemonName string) *apitask.Task { engine.daemonTasksLock.RLock() defer engine.daemonTasksLock.RUnlock() + + logger.Info("getting daemon task", logger.Fields{ + field.Container: daemonName, + }) + if daemon, ok := engine.daemonTasks[daemonName]; ok { return daemon } @@ -1223,6 +1228,12 @@ func (engine *DockerTaskEngine) GetDaemonTask(daemonName string) *apitask.Task { func (engine *DockerTaskEngine) SetDaemonTask(daemonName string, task *apitask.Task) { engine.daemonTasksLock.Lock() + + logger.Info("setting daemon task", logger.Fields{ + field.Container: daemonName, + field.TaskID: task.GetID(), + }) + defer engine.daemonTasksLock.Unlock() engine.daemonTasks[daemonName] = task } diff --git a/agent/engine/dockerstate/docker_task_engine_state.go b/agent/engine/dockerstate/docker_task_engine_state.go index c64f090707b..bdbaa5f99a2 100644 --- a/agent/engine/dockerstate/docker_task_engine_state.go +++ b/agent/engine/dockerstate/docker_task_engine_state.go @@ -300,7 +300,7 @@ func (state *DockerTaskEngineState) GetAllPendingEBSAttachments() []*apiresource func (state *DockerTaskEngineState) allPendingEBSAttachmentsUnsafe() []*apiresource.ResourceAttachment { var pendingEBSAttachments []*apiresource.ResourceAttachment for _, v := range state.ebsAttachments { - if !v.IsAttached() && !v.IsSent() { + if !v.IsAttached() || !v.IsSent() { pendingEBSAttachments = append(pendingEBSAttachments, v) } } @@ -319,7 +319,7 @@ func (state *DockerTaskEngineState) GetAllPendingEBSAttachmentsWithKey() map[str func (state *DockerTaskEngineState) allPendingEBSAttachmentsWithKeyUnsafe() map[string]*apiresource.ResourceAttachment { pendingEBSAttachments := make(map[string]*apiresource.ResourceAttachment) for k, v := range state.ebsAttachments { - if !v.IsAttached() && !v.IsSent() { + if !v.IsAttached() || !v.IsSent() { pendingEBSAttachments[k] = v } } diff --git a/agent/eventhandler/attachment_handler.go b/agent/eventhandler/attachment_handler.go index e9947e0269c..9ffaa555ef2 100644 --- a/agent/eventhandler/attachment_handler.go +++ b/agent/eventhandler/attachment_handler.go @@ -140,13 +140,13 @@ func (handler *attachmentHandler) submitAttachmentEventOnce(attachmentChange *ap } seelog.Debugf("AttachmentHandler: submitted attachment state change: %s", attachmentChange.String()) - attachmentChange.Attachment.SetSentStatus() - attachmentChange.Attachment.StopAckTimer() + //attachmentChange.Attachment.SetSentStatus() + //attachmentChange.Attachment.StopAckTimer() - err := handler.dataClient.SaveENIAttachment(attachmentChange.Attachment) - if err != nil { - seelog.Errorf("AttachmentHandler: error saving state after submitted attachment state change [%s]: %v", attachmentChange.String(), err) - } + //err := handler.dataClient.SaveENIAttachment(attachmentChange.Attachment) + //if err != nil { + // seelog.Errorf("AttachmentHandler: error saving state after submitted attachment state change [%s]: %v", attachmentChange.String(), err) + // } return nil }