mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(ecs): resolve a service only in the request's cluster and Region (#8546)
This commit is contained in:
1 parent
2d6d122419
commit
66c5c98406
2 files changed
+53
-5
No files matched your search
@@ -6459,12 +6459,20 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
return task;
|
||||
}
|
||||
|
||||
/**
|
||||
* ECS services are cluster and Region specific: a name resolves only in the request's cluster
|
||||
* and Region, and an ARN only when it is that service's own ARN, so an ARN naming another
|
||||
* cluster or Region resolves to nothing rather than to a service elsewhere.
|
||||
*/
|
||||
private EcsServiceModel resolveService(String clusterName, String serviceId, String region) {
|
||||
EcsServiceModel svc = services.get(serviceKey(region, clusterName, serviceId));
|
||||
if (svc != null) { return svc; }
|
||||
return services.values().stream()
|
||||
.filter(s -> s.getServiceArn().equals(serviceId) || s.getServiceName().equals(serviceId))
|
||||
.findFirst().orElse(null);
|
||||
if (serviceId == null) {
|
||||
return null;
|
||||
}
|
||||
if (AwsArnUtils.looksLikeArn(serviceId)) {
|
||||
EcsServiceModel svc = services.get(serviceKey(region, clusterName, extractServiceName(serviceId)));
|
||||
return svc != null && serviceId.equals(svc.getServiceArn()) ? svc : null;
|
||||
}
|
||||
return services.get(serviceKey(region, clusterName, serviceId));
|
||||
}
|
||||
|
||||
private EcsServiceModel resolveServiceOrThrow(String clusterName, String serviceId, String region) {
|
||||
|
||||
@@ -297,6 +297,46 @@ class EcsDescribeServicesIntegrationTest {
|
||||
.body("failures[0].reason", equalTo("MISSING"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sameNamedServicesInTwoClustersEachResolveOnlyInTheirOwnCluster() {
|
||||
// ECS services are cluster and Region specific (botocore ServiceNotFoundException docs):
|
||||
// a name or an ARN must never resolve to a service in another cluster.
|
||||
seedClusterAndTaskDef("dep-cluster-30a", "dep-td-30");
|
||||
call("CreateCluster", "{\"clusterName\":\"dep-cluster-30b\"}");
|
||||
String arnA = call("CreateService", "{\"cluster\":\"dep-cluster-30a\",\"serviceName\":\"dep-svc-30\","
|
||||
+ "\"taskDefinition\":\"dep-td-30\",\"desiredCount\":0}").path("service.serviceArn");
|
||||
String arnB = call("CreateService", "{\"cluster\":\"dep-cluster-30b\",\"serviceName\":\"dep-svc-30\","
|
||||
+ "\"taskDefinition\":\"dep-td-30\",\"desiredCount\":0}").path("service.serviceArn");
|
||||
try {
|
||||
describe("dep-cluster-30a", "dep-svc-30").then()
|
||||
.body("services", hasSize(1))
|
||||
.body("services[0].serviceArn", equalTo(arnA));
|
||||
describe("dep-cluster-30b", "dep-svc-30").then()
|
||||
.body("services", hasSize(1))
|
||||
.body("services[0].serviceArn", equalTo(arnB));
|
||||
describe("dep-cluster-30a", arnA).then()
|
||||
.body("services", hasSize(1))
|
||||
.body("services[0].serviceArn", equalTo(arnA));
|
||||
|
||||
describe("dep-cluster-30a", arnB).then()
|
||||
.body("services", hasSize(0))
|
||||
.body("failures", hasSize(1))
|
||||
.body("failures[0].arn", equalTo(arnB))
|
||||
.body("failures[0].reason", equalTo("MISSING"));
|
||||
|
||||
given().contentType(CT).header("X-Amz-Target", TARGET + "DescribeTaskSets")
|
||||
.body("{\"cluster\":\"dep-cluster-30a\",\"service\":\"" + arnB + "\"}")
|
||||
.when().post("/")
|
||||
.then().body("__type", containsString("ServiceNotFoundException"));
|
||||
} finally {
|
||||
call("DeleteService", "{\"cluster\":\"dep-cluster-30a\",\"service\":\"dep-svc-30\",\"force\":true}");
|
||||
call("DeleteService", "{\"cluster\":\"dep-cluster-30b\",\"service\":\"dep-svc-30\",\"force\":true}");
|
||||
call("DeleteCluster", "{\"cluster\":\"dep-cluster-30a\"}");
|
||||
call("DeleteCluster", "{\"cluster\":\"dep-cluster-30b\"}");
|
||||
call("DeregisterTaskDefinition", "{\"taskDefinition\":\"dep-td-30:1\"}");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletedServiceReportsAnEmptyDeploymentListRatherThanOmittingIt() {
|
||||
// AWS's ServicesStable waiter fails an INACTIVE service on status, so an empty list is
|
||||
|
||||
Reference in new issue
Block a user