-
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
Added EFSVolumeConfiguration #2234
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1b9fe2f
Added EFSVolumeConfiguration models
sparrc 998a7a1
Translate EFS volumes from ACS to Docker volume type
sparrc ee837e9
fix gocyclo failure
sparrc b2bc440
code review comments
sparrc 2c47bde
remove readonly config
sparrc c0d0398
remove readonly options from code
sparrc 0d62719
code review comments
sparrc 06df0b0
code review
sparrc 0eaa692
naming is hard
sparrc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -285,6 +285,22 @@ func TaskFromACS(acsTask *ecsacs.Task, envelope *ecsacs.PayloadMessage) (*Task, | |
return task, nil | ||
} | ||
|
||
func (task *Task) initializeVolumes(cfg *config.Config, dockerClient dockerapi.DockerClient, ctx context.Context) error { | ||
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. this had to be factored out to make gocyclo happy |
||
err := task.initializeDockerLocalVolumes(dockerClient, ctx) | ||
if err != nil { | ||
return apierrors.NewResourceInitError(task.Arn, err) | ||
} | ||
err = task.initializeDockerVolumes(cfg.SharedVolumeMatchFullConfig, dockerClient, ctx) | ||
if err != nil { | ||
return apierrors.NewResourceInitError(task.Arn, err) | ||
} | ||
err = task.initializeEFSVolumes(cfg, dockerClient, ctx) | ||
if err != nil { | ||
return apierrors.NewResourceInitError(task.Arn, err) | ||
} | ||
return nil | ||
} | ||
|
||
// PostUnmarshalTask is run after a task has been unmarshalled, but before it has been | ||
// run. It is possible it will be subsequently called after that and should be | ||
// able to handle such an occurrence appropriately (e.g. behave idempotently). | ||
|
@@ -326,14 +342,10 @@ func (task *Task) PostUnmarshalTask(cfg *config.Config, | |
task.initializeASMSecretResource(credentialsManager, resourceFields) | ||
} | ||
|
||
err = task.initializeDockerLocalVolumes(dockerClient, ctx) | ||
if err != nil { | ||
return apierrors.NewResourceInitError(task.Arn, err) | ||
} | ||
err = task.initializeDockerVolumes(cfg.SharedVolumeMatchFullConfig, dockerClient, ctx) | ||
if err != nil { | ||
return apierrors.NewResourceInitError(task.Arn, err) | ||
if err := task.initializeVolumes(cfg, dockerClient, ctx); err != nil { | ||
return err | ||
} | ||
|
||
if cfg.GPUSupportEnabled { | ||
err = task.addGPUResource() | ||
if err != nil { | ||
|
@@ -500,6 +512,68 @@ func (task *Task) initializeDockerVolumes(sharedVolumeMatchFullConfig bool, dock | |
return nil | ||
} | ||
|
||
// initializeEFSVolumes inspects the volume definitions in the task definition. | ||
// If it finds EFS volumes in the task definition, then it converts it to a docker | ||
// volume definition. | ||
func (task *Task) initializeEFSVolumes(cfg *config.Config, dockerClient dockerapi.DockerClient, ctx context.Context) error { | ||
for i, vol := range task.Volumes { | ||
// No need to do this for non-efs volume, eg: host bind/empty volume | ||
if vol.Type != EFSVolumeType { | ||
continue | ||
} | ||
|
||
efsvol, ok := vol.Volume.(*taskresourcevolume.EFSVolumeConfig) | ||
if !ok { | ||
return errors.New("task volume: volume configuration does not match the type 'efs'") | ||
} | ||
|
||
err := task.addEFSVolumes(ctx, cfg, dockerClient, &task.Volumes[i], efsvol) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// addEFSVolumes converts the EFS task definition into an internal docker 'local' volume | ||
// mounted with NFS struct and updates container dependency | ||
func (task *Task) addEFSVolumes( | ||
ctx context.Context, | ||
cfg *config.Config, | ||
dockerClient dockerapi.DockerClient, | ||
vol *TaskVolume, | ||
efsvol *taskresourcevolume.EFSVolumeConfig, | ||
) error { | ||
// TODO CN and gov partition logic | ||
// These are the NFS options recommended by EFS, see: | ||
// https://docs.aws.amazon.com/efs/latest/ug/mounting-fs-mount-cmd-general.html | ||
ostr := fmt.Sprintf("addr=%s.efs.%s.amazonaws.com,nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport", efsvol.Filesystem, cfg.AWSRegion) | ||
sparrc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
devstr := fmt.Sprintf(":%s", efsvol.RootDirectory) | ||
volumeResource, err := taskresourcevolume.NewVolumeResource( | ||
ctx, | ||
vol.Name, | ||
task.volumeName(vol.Name), | ||
"task", | ||
false, | ||
"local", | ||
map[string]string{ | ||
"type": "nfs", | ||
"device": devstr, | ||
"o": ostr, | ||
}, | ||
map[string]string{}, | ||
dockerClient, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
vol.Volume = &volumeResource.VolumeConfig | ||
task.AddResource(resourcetype.DockerVolumeKey, volumeResource) | ||
task.updateContainerVolumeDependency(vol.Name) | ||
return nil | ||
} | ||
|
||
// addTaskScopedVolumes adds the task scoped volume into task resources and updates container dependency | ||
func (task *Task) addTaskScopedVolumes(ctx context.Context, dockerClient dockerapi.DockerClient, | ||
vol *TaskVolume) error { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
In our PRFAQ, this attribute is defined as filesystem, ACS will keep the consistency and use filesystem. Just a reminder that we may want to wait for ACS model get finalized and regenerate the file again.
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.
yep, the exact shape of this is subject to change, we'll keep this code in a feature branch until the ACS model is finalized