-
Notifications
You must be signed in to change notification settings - Fork 619
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
Fixing task volumes in task payload for EBS-backed tasks #3975
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/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" | ||
|
@@ -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) | ||
} | ||
Comment on lines
+115
to
+118
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this tested in any unit tests? The test update seems to be in the input and not in assertions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not directly, I was hoping to do this in a follow up. A lot of the testing was mostly done through manual testing. |
||
|
||
apiTask, err := apitask.TaskFromACS(task, payload) | ||
if err != nil { | ||
pmHandler.handleInvalidTask(task, err, payload) | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit just leave this comment at "// TODO: This will only work if there's one EBS volume per task. " |
||
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 | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,6 +110,7 @@ func handleTaskAttachments(acsTask *ecsacs.Task, task *Task) error { | |
task.ServiceConnectConfig = scHandler.(*ServiceConnectAttachmentHandler).scConfig | ||
} | ||
if len(ebsVolumeAttachments) > 0 { | ||
ebsVolumes := make(map[string]bool) | ||
for _, attachment := range ebsVolumeAttachments { | ||
ebs, err := taskresourcevolume.ParseEBSTaskVolumeAttachment(attachment) | ||
if err != nil { | ||
|
@@ -120,8 +121,17 @@ func handleTaskAttachments(acsTask *ecsacs.Task, task *Task) error { | |
Type: apiresource.EBSTaskAttach, | ||
Volume: ebs, | ||
} | ||
ebsVolumes[ebs.VolumeName] = true | ||
task.Volumes = append(task.Volumes, taskVolume) | ||
} | ||
// We're removing all incorrect volume configuration that were intially passed over from ACS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: "all incorrect volume configurations" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are saying that the task payload we get from ECS backend is incorrect? That reads very odd to me. Is there a better way to put it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. er sorry perhaps we can say "incomplete" here or "temporary" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even incomplete sounds wrong... non-blocking but let's rethink to prevent future confusion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. completely agree |
||
for index, tv := range task.Volumes { | ||
volumeName := tv.Name | ||
volumeType := tv.Type | ||
if ebsVolumes[volumeName] && volumeType != apiresource.EBSTaskAttach { | ||
task.RemoveVolume(index) | ||
} | ||
} | ||
} | ||
} | ||
return nil | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ const ( | |
DockerVolumeType = "docker" | ||
EFSVolumeType = "efs" | ||
FSxWindowsFileServerVolumeType = "fsxWindowsFileServer" | ||
AttachmentType = "attachment" | ||
) | ||
|
||
// TaskVolume is a definition of all the volumes available for containers to | ||
|
@@ -78,6 +79,9 @@ func (tv *TaskVolume) UnmarshalJSON(b []byte) error { | |
return tv.unmarshalFSxWindowsFileServerVolume(intermediate["fsxWindowsFileServerVolumeConfiguration"]) | ||
case apiresource.EBSTaskAttach: | ||
return tv.unmarshalEBSVolume(intermediate["ebsVolumeConfiguration"]) | ||
case AttachmentType: | ||
seelog.Warn("Obtaining the volume configuration from task attachments.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this an expected path? if so can this be Debug or Info level? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trying to understand, why is this no-op for AttachmentType? will this be updated in future PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question, so we want this to be a noop for volume of type We originally thought to try to have a special edge case for volumes defined in the list of task attachments here in |
||
return nil | ||
default: | ||
return errors.Errorf("unrecognized volume type: %q", tv.Type) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This issue is ebs-specific today but will probably be true for other volumes in future.
Can we just say "// To accommodate new volume patterns, we'll first check if the attachment properties include volume configuration then we'll mark the corresponding volume object to be of type attachment to designate source of truth.