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

Update desired count behavior #194

Open
wants to merge 1 commit into
base: cdk2
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"timestamp":1643739695237,"files":[{"filename":"ecs-deployment-group/index.js","previous":148006,"size":147762,"diff":-244},{"filename":"ecs-service/index.js","previous":147514,"size":147469,"diff":-45}]},{"timestamp":1643739156615,"files":[{"filename":"ecs-deployment-group/index.js","previous":147762,"size":148006,"diff":244},{"filename":"ecs-service/index.js","previous":147469,"size":147514,"diff":45}]},{"timestamp":1643738715672,"files":[{"filename":"ecs-deployment-group/index.js","previous":148006,"size":147762,"diff":-244},{"filename":"ecs-service/index.js","previous":147514,"size":147469,"diff":-45}]},{"timestamp":1643738518282,"files":[{"filename":"ecs-deployment-group/index.js","previous":0,"size":148006,"diff":148006},{"filename":"ecs-service/index.js","previous":0,"size":147514,"diff":147514}]},{"timestamp":1643732386377,"files":[{"filename":"ecs-deployment-group/index.js","previous":147762,"size":0,"diff":-147762},{"filename":"ecs-service/index.js","previous":147469,"size":0,"diff":-147469}]},{"timestamp":1642109009944,"files":[{"filename":"ecs-deployment-group/index.js","previous":145598,"size":147762,"diff":2164},{"filename":"ecs-service/index.js","previous":145304,"size":147469,"diff":2165}]},{"timestamp":1639256487176,"files":[{"filename":"ecs-deployment-group/index.js","previous":145308,"size":145598,"diff":290},{"filename":"ecs-service/index.js","previous":145014,"size":145304,"diff":290}]},{"timestamp":1637794842477,"files":[{"filename":"ecs-deployment-group/index.js","previous":145307,"size":145308,"diff":1},{"filename":"ecs-service/index.js","previous":145016,"size":145014,"diff":-2}]},{"timestamp":1637781788109,"files":[{"filename":"ecs-deployment-group/index.js","previous":144989,"size":145307,"diff":318},{"filename":"ecs-service/index.js","previous":144998,"size":145016,"diff":18}]},{"timestamp":1637708323927,"files":[{"filename":"ecs-deployment-group/index.js","previous":0,"size":144989,"diff":144989},{"filename":"ecs-service/index.js","previous":0,"size":144998,"diff":144998}]}]
[{"timestamp":1674711096157,"files":[{"filename":"ecs-deployment-group/index.js","previous":147762,"size":147762,"diff":0},{"filename":"ecs-service/index.js","previous":147469,"size":147475,"diff":6}]},{"timestamp":1643739695237,"files":[{"filename":"ecs-deployment-group/index.js","previous":148006,"size":147762,"diff":-244},{"filename":"ecs-service/index.js","previous":147514,"size":147469,"diff":-45}]},{"timestamp":1643739156615,"files":[{"filename":"ecs-deployment-group/index.js","previous":147762,"size":148006,"diff":244},{"filename":"ecs-service/index.js","previous":147469,"size":147514,"diff":45}]},{"timestamp":1643738715672,"files":[{"filename":"ecs-deployment-group/index.js","previous":148006,"size":147762,"diff":-244},{"filename":"ecs-service/index.js","previous":147514,"size":147469,"diff":-45}]},{"timestamp":1643738518282,"files":[{"filename":"ecs-deployment-group/index.js","previous":0,"size":148006,"diff":148006},{"filename":"ecs-service/index.js","previous":0,"size":147514,"diff":147514}]},{"timestamp":1643732386377,"files":[{"filename":"ecs-deployment-group/index.js","previous":147762,"size":0,"diff":-147762},{"filename":"ecs-service/index.js","previous":147469,"size":0,"diff":-147469}]},{"timestamp":1642109009944,"files":[{"filename":"ecs-deployment-group/index.js","previous":145598,"size":147762,"diff":2164},{"filename":"ecs-service/index.js","previous":145304,"size":147469,"diff":2165}]},{"timestamp":1639256487176,"files":[{"filename":"ecs-deployment-group/index.js","previous":145308,"size":145598,"diff":290},{"filename":"ecs-service/index.js","previous":145014,"size":145304,"diff":290}]},{"timestamp":1637794842477,"files":[{"filename":"ecs-deployment-group/index.js","previous":145307,"size":145308,"diff":1},{"filename":"ecs-service/index.js","previous":145016,"size":145014,"diff":-2}]},{"timestamp":1637781788109,"files":[{"filename":"ecs-deployment-group/index.js","previous":144989,"size":145307,"diff":318},{"filename":"ecs-service/index.js","previous":144998,"size":145016,"diff":18}]},{"timestamp":1637708323927,"files":[{"filename":"ecs-deployment-group/index.js","previous":0,"size":144989,"diff":144989},{"filename":"ecs-service/index.js","previous":0,"size":144998,"diff":144998}]}]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect as expectCDK, haveResource } from '@aws-cdk/assert';
import { anything, expect as expectCDK, haveResource } from '@aws-cdk/assert';
import * as cdk from 'aws-cdk-lib';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import * as elb from 'aws-cdk-lib/aws-elasticloadbalancingv2';
Expand Down Expand Up @@ -32,6 +32,40 @@ describe('EcsService', () => {
}),
);
});

test('Creates a BlueGreenService custom resource without a DesiredCount', () => {
expectCDK(stack).notTo(
haveResource('Custom::BlueGreenService', {
DesiredCount: anything(),
}),
);
});
});

describe('with desiredCount', () => {
const stack = new cdk.Stack(app, 'MyStackWithDesiredCount');
const cluster = new ecs.Cluster(stack, 'Cluster');
const prodTargetGroup = new elb.ApplicationTargetGroup(stack, 'ProdTargetGroup', { vpc: cluster.vpc });
const testTargetGroup = new elb.ApplicationTargetGroup(stack, 'TestTargetGroup', { vpc: cluster.vpc });
const taskDefinition = new DummyTaskDefinition(stack, 'DummyTaskDefinition', { image: 'nginx' });

new EcsService(stack, 'Service', {
cluster,
serviceName: 'My Service',
prodTargetGroup,
testTargetGroup,
taskDefinition,
propagateTags: PropagateTags.SERVICE,
desiredCount: 3,
});

test('sets the desired count', () => {
expectCDK(stack).to(
haveResource('Custom::BlueGreenService', {
DesiredCount: 3,
}),
);
});
});

describe('with tag propagation', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,44 @@ describe('createHandler', () => {
},
});
});

describe('with desired count', () => {
test('sends the specified desired count', async () => {
await handleCreate(
{
...defaultEvent,
RequestType: 'Create',
ResourceProperties: {
...defaultEcsServiceResourceProperties,
DesiredCount: 4,
},
},
defaultContext,
defaultLogger,
);

expect(mockCreateRequest).toHaveBeenCalledWith(expect.objectContaining({ desiredCount: 4 }));
});
});

describe('without desired count', () => {
test('sends 1 (default) as the desired count', async () => {
await handleCreate(
{
...defaultEvent,
RequestType: 'Create',
ResourceProperties: {
...defaultEcsServiceResourceProperties,
desiredCount: undefined,
},
},
defaultContext,
defaultLogger,
);

expect(mockCreateRequest).toHaveBeenCalledWith(expect.objectContaining({ desiredCount: 1 }));
});
});
});

describe('updateHandler', () => {
Expand Down Expand Up @@ -222,4 +260,61 @@ describe('updateHandler', () => {

expect(mockTagResourceRequest).not.toHaveBeenCalled();
});

describe('with desired count', () => {
test('sends the desired count', async () => {
await handleUpdate(
{
...defaultEvent,
RequestType: 'Update',
PhysicalResourceId: 'foo',
ResourceProperties: {
...defaultEcsServiceResourceProperties,
DesiredCount: 3,
},
OldResourceProperties: {
...defaultEcsServiceResourceProperties,
DesiredCount: 2,
},
},
defaultContext,
defaultLogger,
);
expect(mockUpdateRequest).toHaveBeenCalledWith(
expect.objectContaining({
cluster: 'foo',
deploymentConfiguration: {},
desiredCount: 3,
healthCheckGracePeriodSeconds: 3,
service: 'foo',
}),
);
});
});

describe('without desired count', () => {
test('does not send the desired count', async () => {
await handleUpdate(
{
...defaultEvent,
RequestType: 'Update',
PhysicalResourceId: 'foo',
ResourceProperties: {
...defaultEcsServiceResourceProperties,
DesiredCount: undefined,
},
OldResourceProperties: {
...defaultEcsServiceResourceProperties,
},
},
defaultContext,
defaultLogger,
);
expect(mockUpdateRequest).toHaveBeenCalledWith(
expect.objectContaining({
desiredCount: undefined,
}),
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class EcsService extends Construct implements IConnectable, IEcsService,
serviceName,
launchType = LaunchType.FARGATE,
platformVersion = '1.4.0',
desiredCount = 1,
desiredCount,
prodTargetGroup,
testTargetGroup,
taskDefinition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface BlueGreenServiceProps {
taskDefinition: string;
launchType: string;
platformVersion: string;
desiredCount: number;
desiredCount?: number;
subnets: string[];
securityGroups: string[];
targetGroupArn: string;
Expand Down Expand Up @@ -81,7 +81,7 @@ export const handleCreate: OnCreateHandler = async (event): Promise<ResourceHand
taskDefinition,
launchType,
platformVersion,
desiredCount,
desiredCount: desiredCount || 1,
schedulingStrategy,
propagateTags,
deploymentController: {
Expand Down