Skip to content
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

fix(aws-ecs): fix default daemon deploymentConfig values #2210

Merged
merged 2 commits into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-ecs/lib/base/base-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface BaseServiceProps {
* service's DesiredCount value, that can run in a service during a
* deployment.
*
* @default 200
* @default 100 if daemon, otherwise 200
*/
readonly maximumPercent?: number;

Expand All @@ -47,7 +47,7 @@ export interface BaseServiceProps {
* the Amazon ECS service's DesiredCount value, that must
* continue to run and remain healthy during a deployment.
*
* @default 50
* @default 0 if daemon, otherwise 50
*/
readonly minimumHealthyPercent?: number;

Expand Down
10 changes: 10 additions & 0 deletions packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ export class Ec2Service extends BaseService implements elb.ILoadBalancerTarget {
throw new Error('Daemon mode launches one task on every instance. Don\'t supply desiredCount.');
}

if (props.daemon && props.maximumPercent !== undefined && props.maximumPercent !== 100) {
SoManyHs marked this conversation as resolved.
Show resolved Hide resolved
throw new Error('Maximum percent must be 100 for daemon mode.');
}

if (props.daemon && props.minimumHealthyPercent !== undefined && props.minimumHealthyPercent !== 0) {
throw new Error('Minimum healthy percent must be 0 for daemon mode.');
}

if (!isEc2Compatible(props.taskDefinition.compatibility)) {
throw new Error('Supplied TaskDefinition is not configured for compatibility with EC2');
}
Expand All @@ -78,6 +86,8 @@ export class Ec2Service extends BaseService implements elb.ILoadBalancerTarget {
...props,
// If daemon, desiredCount must be undefined and that's what we want. Otherwise, default to 1.
desiredCount: props.daemon || props.desiredCount !== undefined ? props.desiredCount : 1,
maximumPercent: props.daemon && props.maximumPercent === undefined ? 100 : props.maximumPercent,
minimumHealthyPercent: props.daemon && props.minimumHealthyPercent === undefined ? 0 : props.minimumHealthyPercent ,
},
{
cluster: props.cluster.clusterName,
Expand Down
56 changes: 55 additions & 1 deletion packages/@aws-cdk/aws-ecs/test/ec2/test.ec2-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,56 @@ export = {
test.done();
},

"errors if daemon and maximumPercent not 100"(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.VpcNetwork(stack, 'MyVpc', {});
const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });
cluster.addCapacity('DefaultAutoScalingGroup', { instanceType: new ec2.InstanceType('t2.micro') });
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef');
taskDefinition.addContainer('BaseContainer', {
image: ecs.ContainerImage.fromRegistry('test'),
memoryReservationMiB: 10,
});

// THEN
test.throws(() => {
new ecs.Ec2Service(stack, "Ec2Service", {
cluster,
taskDefinition,
daemon: true,
maximumPercent: 300
});
}, /Maximum percent must be 100 for daemon mode./);

test.done();
},

"errors if daemon and minimum not 0"(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.VpcNetwork(stack, 'MyVpc', {});
const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });
cluster.addCapacity('DefaultAutoScalingGroup', { instanceType: new ec2.InstanceType('t2.micro') });
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef');
taskDefinition.addContainer('BaseContainer', {
image: ecs.ContainerImage.fromRegistry('test'),
memoryReservationMiB: 10,
});

// THEN
test.throws(() => {
new ecs.Ec2Service(stack, "Ec2Service", {
cluster,
taskDefinition,
daemon: true,
minimumHealthyPercent: 50
});
}, /Minimum healthy percent must be 0 for daemon mode./);

test.done();
},

'Output does not contain DesiredCount if daemon mode is set'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand Down Expand Up @@ -141,7 +191,11 @@ export = {

// THEN
expect(stack).to(haveResource("AWS::ECS::Service", {
SchedulingStrategy: "DAEMON"
SchedulingStrategy: "DAEMON",
DeploymentConfiguration: {
MaximumPercent: 100,
MinimumHealthyPercent: 0
},
}));

test.done();
Expand Down