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: ECS service replacement regression #22978

Merged
merged 3 commits into from
Nov 18, 2022
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
13 changes: 10 additions & 3 deletions packages/@aws-cdk/aws-ecs/lib/base/base-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,16 @@ export abstract class BaseService extends Resource
const disableCircuitBreakerEcsDeploymentControllerFeatureFlag =
FeatureFlags.of(this).isEnabled(cxapi.ECS_DISABLE_EXPLICIT_DEPLOYMENT_CONTROLLER_FOR_CIRCUIT_BREAKER);

return disableCircuitBreakerEcsDeploymentControllerFeatureFlag ? undefined : {
type: DeploymentControllerType.ECS,
};
if (!disableCircuitBreakerEcsDeploymentControllerFeatureFlag && props.circuitBreaker) {
// This is undesirable behavior (the controller is implicitly ECS anyway when left
// undefined, so specifying it is not necessary but DOES trigger a CFN replacement)
// but we leave it in for backwards compat.
return {
type: DeploymentControllerType.ECS,
};
}

return undefined;
}

private executeCommandLogConfiguration() {
Expand Down
50 changes: 45 additions & 5 deletions packages/@aws-cdk/aws-ecs/test/base-service.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { Template, Match } from '@aws-cdk/assertions';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as cdk from '@aws-cdk/core';
import { App, Stack } from '@aws-cdk/core';
import * as ecs from '../lib';

let stack: cdk.Stack;
describe('When import an ECS Service', () => {
let stack: cdk.Stack;

beforeEach(() => {
stack = new cdk.Stack();
});
beforeEach(() => {
stack = new cdk.Stack();
});

describe('When import an ECS Service', () => {
test('with serviceArnWithCluster', () => {
// GIVEN
const clusterName = 'cluster-name';
Expand Down Expand Up @@ -42,3 +45,40 @@ describe('When import an ECS Service', () => {
}).toThrowError(/is not using the ARN cluster format/);
});
});

test.each([
/* breaker, flag => controller in template */
/* Flag off => value present if circuitbreaker */
[false, false, false],
[true, false, true],
/* Flag on => value never present */
[false, true, false],
[true, true, false],
])('circuitbreaker is %p /\\ flag is %p => DeploymentController in output: %p', (circuitBreaker, flagValue, controllerInTemplate) => {
// GIVEN
const app = new App({
context: {
'@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker': flagValue,
},
});
const stack = new Stack(app, 'Stack');
const vpc = new ec2.Vpc(stack, 'Vpc');
const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });
const taskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDef');
taskDefinition.addContainer('web', {
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
});

// WHEN
new ecs.FargateService(stack, 'FargateService', {
cluster,
taskDefinition,
circuitBreaker: circuitBreaker ? { } : undefined,
});

// THEN
const template = Template.fromStack(stack);
template.hasResourceProperties('AWS::ECS::Service', {
DeploymentController: controllerInTemplate ? { Type: 'ECS' } : Match.absent(),
});
});