Skip to content

Commit

Permalink
No SetPlacementStrategy needed when SchedulingStrategy = DAEMON (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
wardviaene authored Jul 7, 2019
2 parents 68247a8 + 4de21b1 commit c834430
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cmd/ecs-client/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func TestGetDeployDataWithService(t *testing.T) {
var resultJson = `{"services":[{"cluster":"mycluster","loadBalancer":"","serviceName":"testservice-worker","servicePort":0,"serviceProtocol":"none","desiredCount":1,"minimumHealthyPercent":0,"maximumPercent":0,"containers":[{"containerName":"testservice-worker","containerTag":"","containerPort":0,"containerCommand":null,"containerImage":"echoserver","containerURI":"gcr.io/google_containers/echoserver:1.4","containerEntryPoint":null,"essential":true,"memory":0,"memoryReservation":64,"cpu":0,"cpuReservation":0,"dockerLabels":null,"healthCheck":{"command":null,"interval":0,"timeout":0,"retries":0,"startPeriod":0},"environment":null,"mountPoints":null,"ulimits":null,"links":null,"logConfiguration":{"logDriver":"","options":{"max-size":"","max-file":""}}}],"healthCheck":{"healthyThreshold":0,"unhealthyThreshold":0,"path":"","port":"","protocol":"","interval":0,"matcher":"","timeout":0,"gracePeriodSeconds":0},"ruleConditions":null,"networkMode":"","networkConfiguration":{"assignPublicIp":"","securityGroups":null,"subnets":null},"placementConstraints":null,"launchType":"","deregistrationDelay":-1,"stickiness":{"enabled":false,"duration":-1},"volumes":null,"envNamespace":"","serviceRegistry":"","schedulingStrategy":""},{"cluster":"mycluster","loadBalancer":"","serviceName":"testservice","servicePort":80,"serviceProtocol":"HTTP","desiredCount":1,"minimumHealthyPercent":0,"maximumPercent":0,"containers":[{"containerName":"testservice","containerTag":"","containerPort":80,"containerCommand":null,"containerImage":"nginx","containerURI":"index.docker.io/nginx:alpine","containerEntryPoint":null,"essential":true,"memory":0,"memoryReservation":128,"cpu":0,"cpuReservation":0,"dockerLabels":null,"healthCheck":{"command":null,"interval":0,"timeout":0,"retries":0,"startPeriod":0},"environment":null,"mountPoints":null,"ulimits":null,"links":null,"logConfiguration":{"logDriver":"","options":{"max-size":"","max-file":""}}}],"healthCheck":{"healthyThreshold":3,"unhealthyThreshold":3,"path":"/","port":"","protocol":"","interval":60,"matcher":"200,301","timeout":0,"gracePeriodSeconds":0},"ruleConditions":[{"listeners":["http","https"],"pathPattern":"","hostname":"testservice","cognitoAuth":{"userPoolName":"","clientName":""}}],"networkMode":"","networkConfiguration":{"assignPublicIp":"","securityGroups":null,"subnets":null},"placementConstraints":null,"launchType":"","deregistrationDelay":30,"stickiness":{"enabled":false,"duration":-1},"volumes":null,"envNamespace":"","serviceRegistry":"","schedulingStrategy":""}]}`
var resultJson = `{"services":[{"cluster":"mycluster","loadBalancer":"","serviceName":"testservice-worker","servicePort":0,"serviceProtocol":"none","desiredCount":1,"minimumHealthyPercent":0,"maximumPercent":0,"containers":[{"containerName":"testservice-worker","containerTag":"","containerPort":0,"containerCommand":null,"containerImage":"echoserver","containerURI":"gcr.io/google_containers/echoserver:1.4","containerEntryPoint":null,"essential":true,"memory":0,"memoryReservation":64,"cpu":0,"cpuReservation":0,"dockerLabels":null,"healthCheck":{"command":null,"interval":0,"timeout":0,"retries":0,"startPeriod":0},"environment":null,"mountPoints":null,"ulimits":null,"links":null,"logConfiguration":{"logDriver":"","options":{"max-size":"","max-file":""}},"portMappings":null}],"healthCheck":{"healthyThreshold":0,"unhealthyThreshold":0,"path":"","port":"","protocol":"","interval":0,"matcher":"","timeout":0,"gracePeriodSeconds":0},"ruleConditions":null,"networkMode":"","networkConfiguration":{"assignPublicIp":"","securityGroups":null,"subnets":null},"placementConstraints":null,"launchType":"","deregistrationDelay":-1,"stickiness":{"enabled":false,"duration":-1},"volumes":null,"envNamespace":"","serviceRegistry":"","schedulingStrategy":""},{"cluster":"mycluster","loadBalancer":"","serviceName":"testservice","servicePort":80,"serviceProtocol":"HTTP","desiredCount":1,"minimumHealthyPercent":0,"maximumPercent":0,"containers":[{"containerName":"testservice","containerTag":"","containerPort":80,"containerCommand":null,"containerImage":"nginx","containerURI":"index.docker.io/nginx:alpine","containerEntryPoint":null,"essential":true,"memory":0,"memoryReservation":128,"cpu":0,"cpuReservation":0,"dockerLabels":null,"healthCheck":{"command":null,"interval":0,"timeout":0,"retries":0,"startPeriod":0},"environment":null,"mountPoints":null,"ulimits":null,"links":null,"logConfiguration":{"logDriver":"","options":{"max-size":"","max-file":""}},"portMappings":null}],"healthCheck":{"healthyThreshold":3,"unhealthyThreshold":3,"path":"/","port":"","protocol":"","interval":60,"matcher":"200,301","timeout":0,"gracePeriodSeconds":0},"ruleConditions":[{"listeners":["http","https"],"pathPattern":"","hostname":"testservice","cognitoAuth":{"userPoolName":"","clientName":""}}],"networkMode":"","networkConfiguration":{"assignPublicIp":"","securityGroups":null,"subnets":null},"placementConstraints":null,"launchType":"","deregistrationDelay":30,"stickiness":{"enabled":false,"duration":-1},"volumes":null,"envNamespace":"","serviceRegistry":"","schedulingStrategy":""}]}`

deployServices, err := getDeployDataWithService("testservice", "testdata")
if err != nil {
Expand All @@ -21,7 +21,7 @@ func TestGetDeployDataWithService(t *testing.T) {
}
}
func TestGetDeployDataWithoutService(t *testing.T) {
var resultJson = `{"services":[{"cluster":"mycluster","loadBalancer":"","serviceName":"nginx","servicePort":80,"serviceProtocol":"HTTP","desiredCount":1,"minimumHealthyPercent":0,"maximumPercent":0,"containers":[{"containerName":"nginx","containerTag":"","containerPort":80,"containerCommand":null,"containerImage":"nginx","containerURI":"index.docker.io/nginx:alpine","containerEntryPoint":null,"essential":true,"memory":0,"memoryReservation":128,"cpu":0,"cpuReservation":0,"dockerLabels":null,"healthCheck":{"command":null,"interval":0,"timeout":0,"retries":0,"startPeriod":0},"environment":null,"mountPoints":null,"ulimits":null,"links":null,"logConfiguration":{"logDriver":"","options":{"max-size":"","max-file":""}}}],"healthCheck":{"healthyThreshold":3,"unhealthyThreshold":3,"path":"/","port":"","protocol":"","interval":60,"matcher":"200,301","timeout":0,"gracePeriodSeconds":0},"ruleConditions":null,"networkMode":"","networkConfiguration":{"assignPublicIp":"","securityGroups":null,"subnets":null},"placementConstraints":null,"launchType":"","deregistrationDelay":-1,"stickiness":{"enabled":false,"duration":-1},"volumes":null,"envNamespace":"","serviceRegistry":"","schedulingStrategy":""},{"cluster":"mycluster","loadBalancer":"","serviceName":"echoserver","servicePort":8080,"serviceProtocol":"HTTP","desiredCount":1,"minimumHealthyPercent":0,"maximumPercent":0,"containers":[{"containerName":"echoserver","containerTag":"","containerPort":8080,"containerCommand":null,"containerImage":"echoserver","containerURI":"gcr.io/google_containers/echoserver:1.4","containerEntryPoint":null,"essential":true,"memory":0,"memoryReservation":64,"cpu":0,"cpuReservation":0,"dockerLabels":null,"healthCheck":{"command":null,"interval":0,"timeout":0,"retries":0,"startPeriod":0},"environment":null,"mountPoints":null,"ulimits":null,"links":null,"logConfiguration":{"logDriver":"","options":{"max-size":"","max-file":""}}}],"healthCheck":{"healthyThreshold":3,"unhealthyThreshold":3,"path":"/","port":"","protocol":"","interval":60,"matcher":"200,301","timeout":0,"gracePeriodSeconds":0},"ruleConditions":null,"networkMode":"","networkConfiguration":{"assignPublicIp":"","securityGroups":null,"subnets":null},"placementConstraints":null,"launchType":"","deregistrationDelay":-1,"stickiness":{"enabled":false,"duration":-1},"volumes":null,"envNamespace":"","serviceRegistry":"","schedulingStrategy":""}]}`
var resultJson = `{"services":[{"cluster":"mycluster","loadBalancer":"","serviceName":"nginx","servicePort":80,"serviceProtocol":"HTTP","desiredCount":1,"minimumHealthyPercent":0,"maximumPercent":0,"containers":[{"containerName":"nginx","containerTag":"","containerPort":80,"containerCommand":null,"containerImage":"nginx","containerURI":"index.docker.io/nginx:alpine","containerEntryPoint":null,"essential":true,"memory":0,"memoryReservation":128,"cpu":0,"cpuReservation":0,"dockerLabels":null,"healthCheck":{"command":null,"interval":0,"timeout":0,"retries":0,"startPeriod":0},"environment":null,"mountPoints":null,"ulimits":null,"links":null,"logConfiguration":{"logDriver":"","options":{"max-size":"","max-file":""}},"portMappings":null}],"healthCheck":{"healthyThreshold":3,"unhealthyThreshold":3,"path":"/","port":"","protocol":"","interval":60,"matcher":"200,301","timeout":0,"gracePeriodSeconds":0},"ruleConditions":null,"networkMode":"","networkConfiguration":{"assignPublicIp":"","securityGroups":null,"subnets":null},"placementConstraints":null,"launchType":"","deregistrationDelay":-1,"stickiness":{"enabled":false,"duration":-1},"volumes":null,"envNamespace":"","serviceRegistry":"","schedulingStrategy":""},{"cluster":"mycluster","loadBalancer":"","serviceName":"echoserver","servicePort":8080,"serviceProtocol":"HTTP","desiredCount":1,"minimumHealthyPercent":0,"maximumPercent":0,"containers":[{"containerName":"echoserver","containerTag":"","containerPort":8080,"containerCommand":null,"containerImage":"echoserver","containerURI":"gcr.io/google_containers/echoserver:1.4","containerEntryPoint":null,"essential":true,"memory":0,"memoryReservation":64,"cpu":0,"cpuReservation":0,"dockerLabels":null,"healthCheck":{"command":null,"interval":0,"timeout":0,"retries":0,"startPeriod":0},"environment":null,"mountPoints":null,"ulimits":null,"links":null,"logConfiguration":{"logDriver":"","options":{"max-size":"","max-file":""}},"portMappings":null}],"healthCheck":{"healthyThreshold":3,"unhealthyThreshold":3,"path":"/","port":"","protocol":"","interval":60,"matcher":"200,301","timeout":0,"gracePeriodSeconds":0},"ruleConditions":null,"networkMode":"","networkConfiguration":{"assignPublicIp":"","securityGroups":null,"subnets":null},"placementConstraints":null,"launchType":"","deregistrationDelay":-1,"stickiness":{"enabled":false,"duration":-1},"volumes":null,"envNamespace":"","serviceRegistry":"","schedulingStrategy":""}]}`

deployServices, err := getDeployDataWithoutService("", "testdata/multiple-services.yaml")
if err != nil {
Expand Down
42 changes: 33 additions & 9 deletions provider/ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,34 @@ func (e *ECS) CreateTaskDefinitionInput(d service.Deploy, secrets map[string]str
}
// set containerPort if not empty
if container.ContainerPort > 0 {
containerDefinition.SetPortMappings([]*ecs.PortMapping{
{
ContainerPort: aws.Int64(container.ContainerPort),
},
})
if len(container.PortMappings) > 0 {
var portMapping []*ecs.PortMapping
for _, v := range container.PortMappings {
protocol := "tcp"
if v.Protocol != "" {
protocol = v.Protocol
}
if v.HostPort > 0 {
portMapping = append(portMapping, &ecs.PortMapping{
ContainerPort: aws.Int64(v.ContainerPort),
HostPort: aws.Int64(v.HostPort),
Protocol: aws.String(protocol),
})
} else {
portMapping = append(portMapping, &ecs.PortMapping{
ContainerPort: aws.Int64(v.ContainerPort),
Protocol: aws.String(protocol),
})
}
}
containerDefinition.SetPortMappings(portMapping)
} else {
containerDefinition.SetPortMappings([]*ecs.PortMapping{
{
ContainerPort: aws.Int64(container.ContainerPort),
},
})
}
}
// set containerCommand if not empty
if len(container.ContainerCommand) > 0 {
Expand Down Expand Up @@ -691,7 +714,10 @@ func (e *ECS) CreateService(d service.Deploy) error {
Cluster: aws.String(d.Cluster),
ServiceName: aws.String(e.ServiceName),
TaskDefinition: aws.String(*e.TaskDefArn),
PlacementStrategy: []*ecs.PlacementStrategy{
}

if d.SchedulingStrategy != "DAEMON" {
input.SetPlacementStrategy([]*ecs.PlacementStrategy{
{
Field: aws.String("attribute:ecs.availability-zone"),
Type: aws.String("spread"),
Expand All @@ -701,9 +727,7 @@ func (e *ECS) CreateService(d service.Deploy) error {
Type: aws.String("binpack"),
},
},
}

if d.SchedulingStrategy != "DAEMON" {
)
input.SetDesiredCount(d.DesiredCount)
}

Expand Down
6 changes: 6 additions & 0 deletions service/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ type DeployContainer struct {
Ulimits []*DeployContainerUlimit `json:"ulimits" yaml:"ulimits"`
Links []*string `json:"links" yaml:"links"`
LogConfiguration DeployLogConfiguration `json:"logConfiguration" yaml:"logConfiguration"`
PortMappings []DeployContainerPortMapping `json:"portMappings" yaml:"portMappings"`
}
type DeployContainerPortMapping struct {
Protocol string `json:"protocol" yaml:"protocol"`
HostPort int64 `json:"hostPort" yaml:"hostPort"`
ContainerPort int64 `json:"containerPort" yaml:"containerPort"`
}
type DeployLogConfiguration struct {
LogDriver string `json:"logDriver" yaml:"logDriver"`
Expand Down

0 comments on commit c834430

Please sign in to comment.