Skip to content

Commit

Permalink
add missing changes from feature branch
Browse files Browse the repository at this point in the history
  • Loading branch information
fierlion committed Oct 11, 2023
1 parent a21bda4 commit 99e242a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion agent/app/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
13 changes: 10 additions & 3 deletions agent/ebs/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import (
"context"
"errors"
"fmt"
"path/filepath"
"strconv"
"strings"
"time"

ecsapi "github.com/aws/amazon-ecs-agent/agent/api"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
11 changes: 11 additions & 0 deletions agent/engine/docker_task_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions agent/engine/dockerstate/docker_task_engine_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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
}
}
Expand Down
12 changes: 6 additions & 6 deletions agent/eventhandler/attachment_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 99e242a

Please sign in to comment.