Skip to content

Commit

Permalink
fix(aws-ecs): update desired count to be optional (aws#12223)
Browse files Browse the repository at this point in the history
----
Fixes aws#11951. Update `desiredCount` to be optional in compliance with aws/containers-roadmap#493 (comment).
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
iamhopaul123 authored Jan 4, 2021
1 parent 8f74169 commit 455540b
Show file tree
Hide file tree
Showing 21 changed files with 8 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@
"MaximumPercent": 200,
"MinimumHealthyPercent": 50
},
"DesiredCount": 1,
"EnableECSManagedTags": false,
"LaunchType": "FARGATE",
"NetworkConfiguration": {
Expand Down Expand Up @@ -1044,4 +1043,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1854,7 +1854,6 @@
"MaximumPercent": 200,
"MinimumHealthyPercent": 50
},
"DesiredCount": 1,
"EnableECSManagedTags": false,
"LaunchType": "FARGATE",
"NetworkConfiguration": {
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-ecs/lib/base/base-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ export interface BaseServiceOptions {
/**
* The desired number of instantiations of the task definition to keep running on the service.
*
* @default 1
* @default - When creating the service, default is 1; when updating the service, default uses
* the current task number.
*/
readonly desiredCount?: number;

Expand Down
3 changes: 1 addition & 2 deletions packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ export class Ec2Service extends BaseService implements IEc2Service {

super(scope, id, {
...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,
desiredCount: props.desiredCount,
maxHealthyPercent: props.daemon && props.maxHealthyPercent === undefined ? 100 : props.maxHealthyPercent,
minHealthyPercent: props.daemon && props.minHealthyPercent === undefined ? 0 : props.minHealthyPercent,
launchType: LaunchType.EC2,
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class FargateService extends BaseService implements IFargateService {

super(scope, id, {
...props,
desiredCount: props.desiredCount !== undefined ? props.desiredCount : 1,
desiredCount: props.desiredCount,
launchType: LaunchType.FARGATE,
propagateTags: propagateTagsFromSource,
enableECSManagedTags: props.enableECSManagedTags,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@
},
{
"Essential": true,
"Image": "envoyproxy/envoy",
"Image": "envoyproxy/envoy:v1.16.2",
"Memory": 256,
"Name": "envoy"
}
Expand Down Expand Up @@ -923,7 +923,6 @@
"MaximumPercent": 200,
"MinimumHealthyPercent": 50
},
"DesiredCount": 1,
"EnableECSManagedTags": false,
"LaunchType": "EC2",
"NetworkConfiguration": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ taskDefinition.addContainer('web', {
});

taskDefinition.addContainer('envoy', {
image: ecs.ContainerImage.fromRegistry('envoyproxy/envoy'),
// envoyproxy/envoy:latest tag gone from docker hub: https://github.com/envoyproxy/envoy/issues/6344
image: ecs.ContainerImage.fromRegistry('envoyproxy/envoy:v1.16.2'),
memoryLimitMiB: 256,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,6 @@
"MaximumPercent": 200,
"MinimumHealthyPercent": 50
},
"DesiredCount": 1,
"EnableECSManagedTags": false,
"HealthCheckGracePeriodSeconds": 60,
"LaunchType": "EC2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,6 @@
"MaximumPercent": 200,
"MinimumHealthyPercent": 50
},
"DesiredCount": 1,
"EnableECSManagedTags": false,
"LaunchType": "EC2",
"NetworkConfiguration": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,6 @@
"MaximumPercent": 200,
"MinimumHealthyPercent": 50
},
"DesiredCount": 1,
"EnableECSManagedTags": false,
"LaunchType": "EC2",
"NetworkConfiguration": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,6 @@
"MaximumPercent": 200,
"MinimumHealthyPercent": 50
},
"DesiredCount": 1,
"EnableECSManagedTags": false,
"HealthCheckGracePeriodSeconds": 60,
"LaunchType": "EC2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,6 @@
"MaximumPercent": 200,
"MinimumHealthyPercent": 50
},
"DesiredCount": 1,
"EnableECSManagedTags": false,
"HealthCheckGracePeriodSeconds": 60,
"LaunchType": "EC2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,6 @@
"MaximumPercent": 200,
"MinimumHealthyPercent": 50
},
"DesiredCount": 1,
"EnableECSManagedTags": false,
"LaunchType": "EC2",
"NetworkConfiguration": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,6 @@
"MaximumPercent": 200,
"MinimumHealthyPercent": 50
},
"DesiredCount": 1,
"EnableECSManagedTags": false,
"LaunchType": "EC2",
"SchedulingStrategy": "REPLICA",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1379,7 +1379,6 @@
"MaximumPercent": 200,
"MinimumHealthyPercent": 50
},
"DesiredCount": 1,
"EnableECSManagedTags": false,
"LaunchType": "EC2",
"SchedulingStrategy": "REPLICA",
Expand Down
29 changes: 0 additions & 29 deletions packages/@aws-cdk/aws-ecs/test/ec2/test.ec2-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export = {
MaximumPercent: 200,
MinimumHealthyPercent: 50,
},
DesiredCount: 1,
LaunchType: LaunchType.EC2,
SchedulingStrategy: 'REPLICA',
EnableECSManagedTags: false,
Expand Down Expand Up @@ -452,7 +451,6 @@ export = {
MaximumPercent: 200,
MinimumHealthyPercent: 50,
},
DesiredCount: 1,
SchedulingStrategy: 'REPLICA',
EnableECSManagedTags: false,
}));
Expand Down Expand Up @@ -536,33 +534,6 @@ export = {
test.done();
},

'Output does not contain DesiredCount if daemon mode is set'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(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,
});

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

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

test.done();
},

'errors if no container definitions'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@
"MaximumPercent": 200,
"MinimumHealthyPercent": 50
},
"DesiredCount": 1,
"EnableECSManagedTags": false,
"LaunchType": "FARGATE",
"NetworkConfiguration": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@
"MaximumPercent": 200,
"MinimumHealthyPercent": 50
},
"DesiredCount": 1,
"EnableECSManagedTags": false,
"HealthCheckGracePeriodSeconds": 60,
"LaunchType": "FARGATE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@
"MaximumPercent": 200,
"MinimumHealthyPercent": 50
},
"DesiredCount": 1,
"EnableECSManagedTags": false,
"HealthCheckGracePeriodSeconds": 60,
"LaunchType": "FARGATE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export = {
MaximumPercent: 200,
MinimumHealthyPercent: 50,
},
DesiredCount: 1,
LaunchType: LaunchType.FARGATE,
EnableECSManagedTags: false,
NetworkConfiguration: {
Expand Down Expand Up @@ -364,7 +363,6 @@ export = {
DeploymentController: {
Type: 'EXTERNAL',
},
DesiredCount: 1,
EnableECSManagedTags: false,
NetworkConfiguration: {
AwsvpcConfiguration: {
Expand Down Expand Up @@ -543,7 +541,6 @@ export = {
MaximumPercent: 200,
MinimumHealthyPercent: 50,
},
DesiredCount: 1,
LaunchType: LaunchType.FARGATE,
EnableECSManagedTags: false,
NetworkConfiguration: {
Expand Down
1 change: 0 additions & 1 deletion packages/decdk/test/__snapshots__/synth.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,6 @@ Object {
"MaximumPercent": 200,
"MinimumHealthyPercent": 50,
},
"DesiredCount": 1,
"EnableECSManagedTags": false,
"LaunchType": "FARGATE",
"NetworkConfiguration": Object {
Expand Down

0 comments on commit 455540b

Please sign in to comment.