Skip to content

Commit 0292d3f

Browse files
authored
fix: ECS service replacement regression (#22978)
The behavior introduced in #22467 was too eager, changing the no-feature flag behavior for all services, not just services with a circuit breaker. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent ba4896a commit 0292d3f

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

packages/@aws-cdk/aws-ecs/lib/base/base-service.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,16 @@ export abstract class BaseService extends Resource
532532
const disableCircuitBreakerEcsDeploymentControllerFeatureFlag =
533533
FeatureFlags.of(this).isEnabled(cxapi.ECS_DISABLE_EXPLICIT_DEPLOYMENT_CONTROLLER_FOR_CIRCUIT_BREAKER);
534534

535-
return disableCircuitBreakerEcsDeploymentControllerFeatureFlag ? undefined : {
536-
type: DeploymentControllerType.ECS,
537-
};
535+
if (!disableCircuitBreakerEcsDeploymentControllerFeatureFlag && props.circuitBreaker) {
536+
// This is undesirable behavior (the controller is implicitly ECS anyway when left
537+
// undefined, so specifying it is not necessary but DOES trigger a CFN replacement)
538+
// but we leave it in for backwards compat.
539+
return {
540+
type: DeploymentControllerType.ECS,
541+
};
542+
}
543+
544+
return undefined;
538545
}
539546

540547
private executeCommandLogConfiguration() {

packages/@aws-cdk/aws-ecs/test/base-service.test.ts

+45-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
import { Template, Match } from '@aws-cdk/assertions';
2+
import * as ec2 from '@aws-cdk/aws-ec2';
13
import * as cdk from '@aws-cdk/core';
4+
import { App, Stack } from '@aws-cdk/core';
25
import * as ecs from '../lib';
36

4-
let stack: cdk.Stack;
7+
describe('When import an ECS Service', () => {
8+
let stack: cdk.Stack;
59

6-
beforeEach(() => {
7-
stack = new cdk.Stack();
8-
});
10+
beforeEach(() => {
11+
stack = new cdk.Stack();
12+
});
913

10-
describe('When import an ECS Service', () => {
1114
test('with serviceArnWithCluster', () => {
1215
// GIVEN
1316
const clusterName = 'cluster-name';
@@ -42,3 +45,40 @@ describe('When import an ECS Service', () => {
4245
}).toThrowError(/is not using the ARN cluster format/);
4346
});
4447
});
48+
49+
test.each([
50+
/* breaker, flag => controller in template */
51+
/* Flag off => value present if circuitbreaker */
52+
[false, false, false],
53+
[true, false, true],
54+
/* Flag on => value never present */
55+
[false, true, false],
56+
[true, true, false],
57+
])('circuitbreaker is %p /\\ flag is %p => DeploymentController in output: %p', (circuitBreaker, flagValue, controllerInTemplate) => {
58+
// GIVEN
59+
const app = new App({
60+
context: {
61+
'@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker': flagValue,
62+
},
63+
});
64+
const stack = new Stack(app, 'Stack');
65+
const vpc = new ec2.Vpc(stack, 'Vpc');
66+
const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });
67+
const taskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDef');
68+
taskDefinition.addContainer('web', {
69+
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
70+
});
71+
72+
// WHEN
73+
new ecs.FargateService(stack, 'FargateService', {
74+
cluster,
75+
taskDefinition,
76+
circuitBreaker: circuitBreaker ? { } : undefined,
77+
});
78+
79+
// THEN
80+
const template = Template.fromStack(stack);
81+
template.hasResourceProperties('AWS::ECS::Service', {
82+
DeploymentController: controllerInTemplate ? { Type: 'ECS' } : Match.absent(),
83+
});
84+
});

0 commit comments

Comments
 (0)