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): don't emit DesiredCount in daemon mode #1199

Merged
merged 1 commit into from
Nov 18, 2018
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
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ecs/lib/base/base-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export abstract class BaseService extends cdk.Construct
this.taskDefinition = taskDefinition;

this.resource = new cloudformation.ServiceResource(this, "Service", {
desiredCount: props.desiredCount || 1,
desiredCount: props.desiredCount,
serviceName: props.serviceName,
loadBalancers: new cdk.Token(() => this.loadBalancers),
deploymentConfiguration: {
Expand Down
7 changes: 6 additions & 1 deletion packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ export class Ec2Service extends BaseService implements elb.ILoadBalancerTarget {
throw new Error('Supplied TaskDefinition is not configured for compatibility with EC2');
}

super(parent, name, props, {
super(parent, name, {
...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,
},
{
cluster: props.cluster.clusterName,
taskDefinition: props.taskDefinition.taskDefinitionArn,
launchType: 'EC2',
Expand Down
5 changes: 4 additions & 1 deletion packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ export class FargateService extends BaseService {
throw new Error('Supplied TaskDefinition is not configured for compatibility with Fargate');
}

super(parent, name, props, {
super(parent, name, {
...props,
desiredCount: props.desiredCount !== undefined ? props.desiredCount : 1,
}, {
cluster: props.cluster.clusterName,
taskDefinition: props.taskDefinition.taskDefinitionArn,
launchType: 'FARGATE',
Expand Down
31 changes: 31 additions & 0 deletions packages/@aws-cdk/aws-ecs/test/ec2/test.ec2-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export = {
const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });
cluster.addDefaultAutoScalingGroupCapacity({ instanceType: new ec2.InstanceType('t2.micro') });
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef');
taskDefinition.addContainer('BaseContainer', {
image: ecs.ContainerImage.fromDockerHub('test'),
memoryReservationMiB: 10,
});

// THEN
test.throws(() => {
Expand All @@ -65,8 +69,35 @@ export = {
daemon: true,
desiredCount: 2
});
}, /Don't supply desiredCount/);

test.done();
},

'Output does not contain DesiredCount if daemon mode is set'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.VpcNetwork(stack, 'MyVpc', {});
const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });
cluster.addDefaultAutoScalingGroupCapacity({ instanceType: new ec2.InstanceType('t2.micro') });
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef');
taskDefinition.addContainer('BaseContainer', {
image: ecs.ContainerImage.fromDockerHub('test'),
memoryReservationMiB: 10,
});

// WHEN
new ecs.Ec2Service(stack, "Ec2Service", {
cluster,
taskDefinition,
daemon: true,
});

// THEN
expect(stack).to(haveResource('AWS::ECS::Service', (service: any) => {
return service.LaunchType === 'EC2' && service.DesiredCount === undefined;
}));

test.done();
},

Expand Down