fix(ecs): preserve omitted deployment settings on update (#9369)

This commit is contained in:
Jimmy Liu Jia authored and GitHub committed 2026-11-24 14:28:32 -04:00
1 parent 2bcde72f1e
commit 0b12f31467
5 files changed
+112 -4

No files matched your search

@@ -381,6 +381,10 @@ public class EcsCfnProvisioner implements CfnResourceProvisioner {
boolean restoredDeploymentConfiguration = restoreDeploymentConfiguration;
Map<String, Object> priorConfiguration = priorDeploymentConfiguration;
try {
if (deploymentConfiguration != null) {
ecsService.replaceServiceDeploymentConfiguration(
clusterRef, service, deploymentConfiguration, ctx.region());
}
if (clearedDeploymentConfiguration) {
ecsService.replaceServiceDeploymentConfiguration(clusterRef, service, null, ctx.region());
}
@@ -3327,7 +3327,19 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
svc.setHealthCheckGracePeriodSeconds(request.getHealthCheckGracePeriodSeconds());
}
if (request.getDeploymentConfiguration() != null) {
svc.setDeploymentConfiguration(request.getDeploymentConfiguration());
Map<String, Object> configuration = new LinkedHashMap<>();
if (svc.getDeploymentConfiguration() != null) {
configuration.putAll(svc.getDeploymentConfiguration());
}
for (Map.Entry<String, Object> entry : request.getDeploymentConfiguration().entrySet()) {
if ("deploymentCircuitBreaker".equals(entry.getKey())
&& entry.getValue() instanceof Map<?, ?> breaker && breaker.isEmpty()) {
configuration.remove(entry.getKey());
} else {
configuration.put(entry.getKey(), entry.getValue());
}
}
svc.setDeploymentConfiguration(configuration);
}
if (request.getLoadBalancers() != null) {
rollingChange |= loadBalancersChanged(svc.getLoadBalancers(), request.getLoadBalancers());
@@ -326,6 +326,20 @@ class CloudFormationEcsForwardedSettingsIntegrationTest {
describeService(name).body("services[0]", not(hasKey("deploymentConfiguration")));
}
@Test
void updateStack_omittedDeploymentCircuitBreaker_removesItFromTheDeclaredConfiguration() {
String name = stackName();
createServiceStack(name, "\"DeploymentConfiguration\": {\"MaximumPercent\": 150,"
+ " \"MinimumHealthyPercent\": 0, \"DeploymentCircuitBreaker\": "
+ "{\"Enable\": true, \"Rollback\": true}}");
updateServiceStack(name, 1, DEPLOYMENT_SETTING);
describeService(name)
.body("services[0].deploymentConfiguration.maximumPercent", equalTo(150))
.body("services[0].deploymentConfiguration", not(hasKey("deploymentCircuitBreaker")));
}
@Test
void updateStack_settingsSetThroughTheApi_surviveAnUpdateThatStillDoesNotDeclareThem() {
String name = stackName();
@@ -1465,6 +1465,8 @@ class EcsCfnProvisionerTest {
assertEquals(REGISTRIES, request.getValue().getServiceRegistries());
assertEquals(DEPLOYMENT_CONFIGURATION, request.getValue().getDeploymentConfiguration());
assertEquals(STRATEGY, request.getValue().getCapacityProviderStrategy());
verify(ecs).replaceServiceDeploymentConfiguration(
eq("web"), eq("front"), eq(DEPLOYMENT_CONFIGURATION), eq(REGION));
}
@Test
@@ -1560,6 +1562,47 @@ class EcsCfnProvisionerTest {
assertNull(r.getAttributes().get(CfnRollback.UPDATE_ROLLBACK_FAILURE_ATTR));
}
@Test
void aFailedDeploymentConfigurationReplacementRestoresThePriorService() {
Map<String, Object> priorConfiguration = Map.of("maximumPercent", 100);
EcsServiceModel stored = service("front");
stored.setTaskDefinition(TASK_DEF_ARN);
stored.setDesiredCount(1);
stored.setDeploymentConfiguration(priorConfiguration);
when(ecs.serviceByArn(SERVICE_ARN)).thenReturn(stored);
EcsServiceModel updated = service("front");
EcsServiceModel restored = service("front");
when(ecs.updateService(any(UpdateServiceRequest.class), eq(REGION))).thenAnswer(inv -> {
UpdateServiceRequest request = inv.getArgument(0);
if (request.getDesiredCount() != null) {
stored.setDesiredCount(request.getDesiredCount());
}
if (request.getDeploymentConfiguration() != null) {
stored.setDeploymentConfiguration(request.getDeploymentConfiguration());
}
return Integer.valueOf(3).equals(request.getDesiredCount()) ? updated : restored;
});
AwsException failure = new AwsException("StorageError", "deployment configuration write failed", 500);
when(ecs.replaceServiceDeploymentConfiguration(any(), any(), any(), any()))
.thenThrow(failure)
.thenAnswer(inv -> {
stored.setDeploymentConfiguration(inv.getArgument(2));
return stored;
});
StackResource r = existingService();
AwsException thrown = assertThrows(AwsException.class, () -> provisioner.provision(r,
declaring(DEPLOYMENT_CONFIGURATION_PROPERTY).put("DesiredCount", "3"),
ctx(SERVICE_ARN, declaring(DEPLOYMENT_CONFIGURATION_PROPERTY))));
assertSame(failure, thrown);
assertEquals(1, stored.getDesiredCount());
assertEquals(priorConfiguration, stored.getDeploymentConfiguration());
verify(ecs, times(2)).updateService(any(UpdateServiceRequest.class), eq(REGION));
verify(ecs).awaitServiceStable(restored);
assertNull(r.getAttributes().get(CfnRollback.UPDATE_ROLLBACK_FAILURE_ATTR));
}
@Test
void aRestoreAfterAnUpdateThatSentNoDesiredCountSendsNoneEither() {
EcsServiceModel prior = service("front");
@@ -1729,7 +1772,7 @@ class EcsCfnProvisionerTest {
UpdateServiceRequest request = updateFrom(declaring(DEPLOYMENT_CONFIGURATION_PROPERTY), props);
assertEquals(Map.of(), request.getDeploymentConfiguration());
verifyNoDeploymentConfigurationReplacement();
verify(ecs).replaceServiceDeploymentConfiguration(eq("web"), eq("front"), eq(Map.of()), eq(REGION));
}
@Test
@@ -1755,7 +1798,8 @@ class EcsCfnProvisionerTest {
assertEquals(REGISTRIES, request.getServiceRegistries());
assertEquals(DEPLOYMENT_CONFIGURATION, request.getDeploymentConfiguration());
assertEquals(STRATEGY, request.getCapacityProviderStrategy());
verifyNoDeploymentConfigurationReplacement();
verify(ecs).replaceServiceDeploymentConfiguration(
eq("web"), eq("front"), eq(DEPLOYMENT_CONFIGURATION), eq(REGION));
}
@ParameterizedTest
@@ -1772,7 +1816,8 @@ class EcsCfnProvisionerTest {
if (!DEPLOYMENT_CONFIGURATION_PROPERTY.equals(dropped)) {
assertEquals(DEPLOYMENT_CONFIGURATION, request.getDeploymentConfiguration(),
"deployment configuration stays as declared");
verifyNoDeploymentConfigurationReplacement();
verify(ecs).replaceServiceDeploymentConfiguration(
eq("web"), eq("front"), eq(DEPLOYMENT_CONFIGURATION), eq(REGION));
} else {
verify(ecs).replaceServiceDeploymentConfiguration(eq("web"), eq("front"), isNull(), eq(REGION));
}
@@ -292,6 +292,39 @@ class EcsFargateTaskIntegrationTest {
.body("services[0].deploymentConfiguration.minimumHealthyPercent", equalTo(100));
}
@Test
void updateServiceKeepsUnspecifiedDeploymentConfigurationMembers() {
String family = seed("fargate-config-update");
String serviceName = "fargate-config-update-svc";
call("CreateService", "{\"cluster\":\"" + CLUSTER + "\",\"serviceName\":\"" + serviceName + "\","
+ "\"taskDefinition\":\"" + family + "\",\"desiredCount\":0,\"launchType\":\"FARGATE\","
+ NETWORK + ",\"deploymentConfiguration\":{\"maximumPercent\":150,"
+ "\"minimumHealthyPercent\":50,\"deploymentCircuitBreaker\":{\"enable\":true,"
+ "\"rollback\":true},\"alarms\":{\"alarmNames\":[\"deployment-alarm\"],"
+ "\"enable\":true,\"rollback\":false}}}", 200);
call("UpdateService", "{\"cluster\":\"" + CLUSTER + "\",\"service\":\"" + serviceName + "\","
+ "\"deploymentConfiguration\":{\"maximumPercent\":175,\"minimumHealthyPercent\":25}}", 200)
.then()
.body("service.deploymentConfiguration.maximumPercent", equalTo(175))
.body("service.deploymentConfiguration.minimumHealthyPercent", equalTo(25))
.body("service.deploymentConfiguration.deploymentCircuitBreaker.enable", equalTo(true))
.body("service.deploymentConfiguration.deploymentCircuitBreaker.rollback", equalTo(true))
.body("service.deploymentConfiguration.alarms.alarmNames[0]", equalTo("deployment-alarm"));
call("DescribeServices", "{\"cluster\":\"" + CLUSTER + "\",\"services\":[\"" + serviceName + "\"]}", 200)
.then()
.body("services[0].deploymentConfiguration.deploymentCircuitBreaker.enable", equalTo(true))
.body("services[0].deploymentConfiguration.alarms.enable", equalTo(true));
call("UpdateService", "{\"cluster\":\"" + CLUSTER + "\",\"service\":\"" + serviceName + "\","
+ "\"deploymentConfiguration\":{\"deploymentCircuitBreaker\":{}}}", 200)
.then()
.body("service.deploymentConfiguration.deploymentCircuitBreaker", nullValue())
.body("service.deploymentConfiguration.maximumPercent", equalTo(175))
.body("service.deploymentConfiguration.alarms.alarmNames[0]", equalTo("deployment-alarm"));
}
@Test
void createServiceOnACapacityProviderStrategyStartsTasksAndReportsTheProvider() {
String family = seed("fargate-service-strategy");