Skip to content

Commit

Permalink
Merge branch 'feature/fsx_windows_fileserver' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
singholt committed Oct 21, 2020
2 parents 089d89e + 618d770 commit bd5f916
Show file tree
Hide file tree
Showing 54 changed files with 8,774 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ GOFILES:=$(shell go list -f '{{$$p := .}}{{range $$f := .GoFiles}}{{$$p.Dir}}/{{
.PHONY: gocyclo
gocyclo:
# Run gocyclo over all .go files
gocyclo -over 15 ${GOFILES}
gocyclo -over 17 ${GOFILES}

# same as gofiles above, but without the `-f`
.PHONY: govet
Expand Down
4 changes: 3 additions & 1 deletion agent/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions agent/acs/model/api/api-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,21 @@
"message":{"shape":"String"}
}
},
"FSxWindowsFileServerAuthorizationConfig":{
"type":"structure",
"members":{
"credentialsParameter":{"shape":"String"},
"domain":{"shape":"String"}
}
},
"FSxWindowsFileServerVolumeConfiguration":{
"type":"structure",
"members":{
"fileSystemId":{"shape":"String"},
"rootDirectory":{"shape":"String"},
"authorizationConfig":{"shape":"FSxWindowsFileServerAuthorizationConfig"}
}
},
"HealthCheckType":{
"type":"string",
"enum":["docker"]
Expand Down Expand Up @@ -720,7 +735,8 @@
"type":{"shape":"VolumeType"},
"host":{"shape":"HostVolumeProperties"},
"dockerVolumeConfiguration":{"shape":"DockerVolumeConfiguration"},
"efsVolumeConfiguration":{"shape":"EFSVolumeConfiguration"}
"efsVolumeConfiguration":{"shape":"EFSVolumeConfiguration"},
"fsxWindowsFileServerVolumeConfiguration":{"shape":"FSxWindowsFileServerVolumeConfiguration"}
}
},
"VolumeFrom":{
Expand All @@ -743,7 +759,8 @@
"enum":[
"host",
"docker",
"efs"
"efs",
"fsxWindowsFileServer"
]
},
"TaskIdentifier": {
Expand Down
40 changes: 40 additions & 0 deletions agent/acs/model/ecsacs/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion agent/api/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,14 @@ func (task *Task) PostUnmarshalTask(cfg *config.Config,
}
task.populateTaskARN()

// fsxWindowsFileserver is the product type -- it is technically "agnostic" ie it should apply to both Windows and Linux tasks
if task.requiresFSxWindowsFileServerResource() {
if err := task.initializeFSxWindowsFileServerResource(cfg, credentialsManager, resourceFields); err != nil {
seelog.Errorf("Task [%s]: could not initialize FSx for Windows File Server resource: %v", task.Arn, err)
return apierrors.NewResourceInitError(task.Arn, err)
}
}

return nil
}

Expand Down Expand Up @@ -1316,7 +1324,7 @@ func (task *Task) HostVolumeByName(name string) (taskresourcevolume.Volume, bool
// volume feature.
func (task *Task) UpdateMountPoints(cont *apicontainer.Container, vols []types.MountPoint) {
for _, mountPoint := range cont.MountPoints {
containerPath := getCanonicalPath(mountPoint.ContainerPath)
containerPath := utils.GetCanonicalPath(mountPoint.ContainerPath)
for _, vol := range vols {
if strings.Compare(vol.Destination, containerPath) == 0 ||
// /path/ -> /path or \path\ -> \path
Expand Down
14 changes: 12 additions & 2 deletions agent/api/task/task_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ func (task *Task) initializeCgroupResourceSpec(cgroupPath string, cGroupCPUPerio
return nil
}

func getCanonicalPath(path string) string { return path }

// BuildCgroupRoot helps build the task cgroup prefix
// Example: /ecs/task-id
func (task *Task) BuildCgroupRoot() (string, error) {
Expand Down Expand Up @@ -241,3 +239,15 @@ func enableIPv6SysctlSetting(hostConfig *dockercontainer.HostConfig) {
}
hostConfig.Sysctls[disableIPv6SysctlKey] = sysctlValueOff
}

// requiresFSxWindowsFileServerResource returns true if at least one volume in the task
// is of type 'fsxWindowsFileServer'
func (task *Task) requiresFSxWindowsFileServerResource() bool {
return false
}

// initializeFSxWindowsFileServerResource builds the resource dependency map for the fsxwindowsfileserver resource
func (task *Task) initializeFSxWindowsFileServerResource(cfg *config.Config, credentialsManager credentials.Manager,
resourceFields *taskresource.ResourceFields) error {
return errors.New("task with FSx for Windows File Server volumes is only supported on Windows container instance")
}
14 changes: 12 additions & 2 deletions agent/api/task/task_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ func (task *Task) adjustForPlatform(cfg *config.Config) {
task.MemoryCPULimitsEnabled = cfg.TaskCPUMemLimit.Enabled()
}

func getCanonicalPath(path string) string { return path }

func (task *Task) initializeCgroupResourceSpec(cgroupPath string, cGroupCPUPeriod time.Duration, resourceFields *taskresource.ResourceFields) error {
return nil
}
Expand Down Expand Up @@ -80,3 +78,15 @@ func (task *Task) GetCredentialSpecResource() ([]taskresource.TaskResource, bool
func enableIPv6SysctlSetting(hostConfig *dockercontainer.HostConfig) {
return
}

// requiresFSxWindowsFileServerResource returns true if at least one volume in the task
// is of type 'fsxWindowsFileServer'
func (task *Task) requiresFSxWindowsFileServerResource() bool {
return false
}

// initializeFSxWindowsFileServerResource builds the resource dependency map for the fsxwindowsfileserver resource
func (task *Task) initializeFSxWindowsFileServerResource(cfg *config.Config, credentialsManager credentials.Manager,
resourceFields *taskresource.ResourceFields) error {
return errors.New("task with FSx for Windows File Server volumes is only supported on Windows container instance")
}
111 changes: 73 additions & 38 deletions agent/api/task/task_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ package task

import (
"errors"
"path/filepath"
"regexp"
"runtime"
"strings"
"time"

"github.com/aws/amazon-ecs-agent/agent/utils"
Expand All @@ -30,7 +27,9 @@ import (
"github.com/aws/amazon-ecs-agent/agent/credentials"
"github.com/aws/amazon-ecs-agent/agent/taskresource"
"github.com/aws/amazon-ecs-agent/agent/taskresource/credentialspec"
"github.com/aws/amazon-ecs-agent/agent/taskresource/fsxwindowsfileserver"
resourcestatus "github.com/aws/amazon-ecs-agent/agent/taskresource/status"
resourcetype "github.com/aws/amazon-ecs-agent/agent/taskresource/types"
taskresourcevolume "github.com/aws/amazon-ecs-agent/agent/taskresource/volume"
"github.com/cihub/seelog"
dockercontainer "github.com/docker/docker/api/types/container"
Expand Down Expand Up @@ -71,51 +70,18 @@ func (task *Task) adjustForPlatform(cfg *config.Config) {
func (task *Task) downcaseAllVolumePaths() {
for _, volume := range task.Volumes {
if hostVol, ok := volume.Volume.(*taskresourcevolume.FSHostVolume); ok {
hostVol.FSSourcePath = getCanonicalPath(hostVol.FSSourcePath)
hostVol.FSSourcePath = utils.GetCanonicalPath(hostVol.FSSourcePath)
}
}
for _, container := range task.Containers {
for i, mountPoint := range container.MountPoints {
// container.MountPoints is a slice of values, not a slice of pointers so
// we need to mutate the actual value instead of the copied value
container.MountPoints[i].ContainerPath = getCanonicalPath(mountPoint.ContainerPath)
container.MountPoints[i].ContainerPath = utils.GetCanonicalPath(mountPoint.ContainerPath)
}
}
}

func getCanonicalPath(path string) string {
lowercasedPath := strings.ToLower(path)
// if the path is a bare drive like "d:", don't filepath.Clean it because it will add a '.'.
// this is to fix the case where mounting from D:\ to D: is supported by docker but not ecs
if isBareDrive(lowercasedPath) {
return lowercasedPath
}

if isNamedPipesPath(lowercasedPath) {
return lowercasedPath
}

return filepath.Clean(lowercasedPath)
}

func isBareDrive(path string) bool {
if filepath.VolumeName(path) == path {
return true
}

return false
}

func isNamedPipesPath(path string) bool {
matched, err := regexp.MatchString(`\\{2}\.[\\]pipe[\\].+`, path)

if err != nil {
return false
}

return matched
}

// platformHostConfigOverride provides an entry point to set up default HostConfig options to be
// passed to Docker API.
func (task *Task) platformHostConfigOverride(hostConfig *dockercontainer.HostConfig) error {
Expand Down Expand Up @@ -217,3 +183,72 @@ func (task *Task) GetCredentialSpecResource() ([]taskresource.TaskResource, bool
func enableIPv6SysctlSetting(hostConfig *dockercontainer.HostConfig) {
return
}

// requiresFSxWindowsFileServerResource returns true if at least one volume in the task
// is of type 'fsxWindowsFileServer'
func (task *Task) requiresFSxWindowsFileServerResource() bool {
for _, volume := range task.Volumes {
if volume.Type == FSxWindowsFileServerVolumeType {
return true
}
}
return false
}

// initializeFSxWindowsFileServerResource builds the resource dependency map for the fsxwindowsfileserver resource
func (task *Task) initializeFSxWindowsFileServerResource(cfg *config.Config, credentialsManager credentials.Manager,
resourceFields *taskresource.ResourceFields) error {
for i, vol := range task.Volumes {
if vol.Type != FSxWindowsFileServerVolumeType {
continue
}

fsxWindowsFileServerVol, ok := vol.Volume.(*fsxwindowsfileserver.FSxWindowsFileServerVolumeConfig)
if !ok {
return errors.New("task volume: volume configuration does not match the type 'fsxWindowsFileServer'")
}

err := task.addFSxWindowsFileServerResource(cfg, credentialsManager, resourceFields, &task.Volumes[i], fsxWindowsFileServerVol)
if err != nil {
return err
}
}
return nil
}

// addFSxWindowsFileServerResource creates a fsxwindowsfileserver resource for every fsxwindowsfileserver task volume
// and updates container dependency
func (task *Task) addFSxWindowsFileServerResource(
cfg *config.Config,
credentialsManager credentials.Manager,
resourceFields *taskresource.ResourceFields,
vol *TaskVolume,
fsxWindowsFileServerVol *fsxwindowsfileserver.FSxWindowsFileServerVolumeConfig,
) error {
hostPath, err := utils.FindUnusedDriveLetter()
if err != nil {
return err
}

fsxwindowsfileserverResource, err := fsxwindowsfileserver.NewFSxWindowsFileServerResource(
task.Arn,
cfg.AWSRegion,
vol.Name,
FSxWindowsFileServerVolumeType,
fsxWindowsFileServerVol,
hostPath,
task.ExecutionCredentialsID,
credentialsManager,
resourceFields.SSMClientCreator,
resourceFields.ASMClientCreator,
resourceFields.FSxClientCreator)
if err != nil {
return err
}

vol.Volume = &fsxwindowsfileserverResource.VolumeConfig
task.AddResource(resourcetype.FSxWindowsFileServerKey, fsxwindowsfileserverResource)
task.updateContainerVolumeDependency(vol.Name)

return nil
}
Loading

0 comments on commit bd5f916

Please sign in to comment.