mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
Subnets, EFS file systems and mount targets persisted before zone ids took AWS's shape (#5486) still carried the old <region>-az<n> id, so DescribeSubnets reported an id DescribeAvailabilityZones --zone-ids rejects. The id is a function of the zone name and region, so the models now derive it from the stored zone name on read instead of trusting the stored value.
This commit is contained in:
1 parent
3e8369664e
commit
d7911da436
7 files changed
+223
-3
No files matched your search
@@ -218,6 +218,37 @@ class Ec2ServicePersistenceTest {
|
||||
assertEquals("10.0.1.0/24", subnets.get(0).getCidrBlock());
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue #5580: a subnet persisted before zone ids took AWS's shape stored
|
||||
* {@code ap-southeast-1-az1}, which DescribeAvailabilityZones no longer publishes.
|
||||
*/
|
||||
@Test
|
||||
void legacySubnetZoneIdReadsBackAsTheIdDescribeAvailabilityZonesPublishes(@TempDir Path dir)
|
||||
throws IOException {
|
||||
Files.writeString(dir.resolve("ec2-subnets.json"), """
|
||||
{
|
||||
"ap-southeast-1::subnet-legacy": {
|
||||
"subnetId": "subnet-legacy",
|
||||
"vpcId": "vpc-legacy",
|
||||
"cidrBlock": "172.31.0.0/20",
|
||||
"state": "available",
|
||||
"availabilityZone": "ap-southeast-1b",
|
||||
"availabilityZoneId": "ap-southeast-1-az2",
|
||||
"region": "ap-southeast-1"
|
||||
}
|
||||
}
|
||||
""");
|
||||
|
||||
Ec2Service restarted = newService(dir);
|
||||
|
||||
Subnet subnet = restarted.describeSubnets("ap-southeast-1", List.of("subnet-legacy"), Map.of())
|
||||
.getFirst();
|
||||
assertEquals("apse1-az2", subnet.getAvailabilityZoneId());
|
||||
List<Map<String, String>> zones = restarted.describeAvailabilityZones("ap-southeast-1", List.of(),
|
||||
List.of(subnet.getAvailabilityZoneId()), List.of());
|
||||
assertEquals("ap-southeast-1b", zones.getFirst().get("zoneName"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void registeredImageAndSnapshotSurviveRestart(@TempDir Path dir) {
|
||||
Ec2Service first = newService(dir);
|
||||
|
||||
+40
@@ -1,13 +1,17 @@
|
||||
package io.github.hectorvent.floci.services.ec2;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.path.xml.XmlPath;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
/**
|
||||
* CreateSubnet never read AvailabilityZoneId and hardcoded every new subnet's zone id to the
|
||||
@@ -110,6 +114,42 @@ class Ec2SubnetAvailabilityZoneIdIntegrationTest {
|
||||
hasItem("use1-az3"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue #5580: the AWS Load Balancer Controller resolves each subnet's zone by passing its
|
||||
* AvailabilityZoneId to DescribeAvailabilityZones --zone-ids, the default VPC's subnets
|
||||
* included, so every id a subnet reports has to be accepted there.
|
||||
*/
|
||||
@Test
|
||||
void everyDefaultSubnetZoneIdCanBeLookedUpByZoneId() {
|
||||
String auth = "AWS4-HMAC-SHA256 Credential=test/20260205/ap-southeast-1/ec2/aws4_request";
|
||||
XmlPath subnets = given()
|
||||
.formParam("Action", "DescribeSubnets")
|
||||
.formParam("Filter.1.Name", "default-for-az")
|
||||
.formParam("Filter.1.Value.1", "true")
|
||||
.header("Authorization", auth)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().xmlPath();
|
||||
List<String> zoneNames = subnets.getList("DescribeSubnetsResponse.subnetSet.item.availabilityZone");
|
||||
List<String> zoneIds = subnets.getList("DescribeSubnetsResponse.subnetSet.item.availabilityZoneId");
|
||||
|
||||
assertFalse(zoneIds.isEmpty());
|
||||
for (int i = 0; i < zoneIds.size(); i++) {
|
||||
given()
|
||||
.formParam("Action", "DescribeAvailabilityZones")
|
||||
.formParam("ZoneId.1", zoneIds.get(i))
|
||||
.header("Authorization", auth)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeAvailabilityZonesResponse.availabilityZoneInfo.item.zoneName",
|
||||
equalTo(zoneNames.get(i)));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void aZoneAndZoneIdThatDisagreeAreRefusedRatherThanSilentlyResolved() {
|
||||
given()
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package io.github.hectorvent.floci.services.ec2.model;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Issue #5580: subnets persisted before zone ids took AWS's shape stored {@code <region>-az<n>};
|
||||
* the id is derived from the zone name, so the old form reads back as the current one.
|
||||
*/
|
||||
class SubnetZoneIdTest {
|
||||
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
void theStoredLegacyIdReadsBackAsTheCurrentId() throws Exception {
|
||||
Subnet subnet = mapper.readValue("""
|
||||
{
|
||||
"subnetId": "subnet-legacy",
|
||||
"availabilityZone": "ap-southeast-1a",
|
||||
"availabilityZoneId": "ap-southeast-1-az1",
|
||||
"region": "ap-southeast-1"
|
||||
}
|
||||
""", Subnet.class);
|
||||
|
||||
assertEquals("apse1-az1", subnet.getAvailabilityZoneId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void theRoundTripWritesTheCurrentIdAndReadsItBack() throws Exception {
|
||||
Subnet legacy = mapper.readValue("""
|
||||
{
|
||||
"availabilityZoneId": "ap-southeast-1-az3",
|
||||
"availabilityZone": "ap-southeast-1c",
|
||||
"region": "ap-southeast-1"
|
||||
}
|
||||
""", Subnet.class);
|
||||
|
||||
String written = mapper.writeValueAsString(legacy);
|
||||
Subnet reread = mapper.readValue(written, Subnet.class);
|
||||
|
||||
assertEquals("apse1-az3", mapper.readTree(written).get("availabilityZoneId").asText());
|
||||
assertEquals("apse1-az3", reread.getAvailabilityZoneId());
|
||||
assertEquals("ap-southeast-1c", reread.getAvailabilityZone());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aSubnetWithoutAZoneNameKeepsTheStoredId() throws Exception {
|
||||
Subnet subnet = mapper.readValue("""
|
||||
{"availabilityZoneId": "use1-az2", "region": "us-east-1"}
|
||||
""", Subnet.class);
|
||||
|
||||
assertEquals("use1-az2", subnet.getAvailabilityZoneId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package io.github.hectorvent.floci.services.efs.model;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
/**
|
||||
* Issue #5580: file systems and mount targets persisted before zone ids took AWS's shape stored
|
||||
* {@code <region>-az<n>}; the id is derived from the zone name, so the old form reads back as the
|
||||
* current one.
|
||||
*/
|
||||
class EfsZoneIdTest {
|
||||
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
void aLegacyFileSystemReadsBackTheCurrentId() throws Exception {
|
||||
FileSystem fs = mapper.readValue("""
|
||||
{
|
||||
"FileSystemId": "fs-legacy",
|
||||
"FileSystemArn": "arn:aws:elasticfilesystem:ap-southeast-1:000000000000:file-system/fs-legacy",
|
||||
"AvailabilityZoneName": "ap-southeast-1b",
|
||||
"AvailabilityZoneId": "ap-southeast-1-az2"
|
||||
}
|
||||
""", FileSystem.class);
|
||||
|
||||
assertEquals("apse1-az2", fs.getAvailabilityZoneId());
|
||||
|
||||
String written = mapper.writeValueAsString(fs);
|
||||
assertEquals("apse1-az2", mapper.readTree(written).get("AvailabilityZoneId").asText());
|
||||
assertEquals("apse1-az2", mapper.readValue(written, FileSystem.class).getAvailabilityZoneId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aRegionalFileSystemHasNoZoneId() throws Exception {
|
||||
FileSystem fs = mapper.readValue("""
|
||||
{"FileSystemArn": "arn:aws:elasticfilesystem:us-east-1:000000000000:file-system/fs-1"}
|
||||
""", FileSystem.class);
|
||||
|
||||
assertNull(fs.getAvailabilityZoneId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aLegacyMountTargetReadsBackTheCurrentId() throws Exception {
|
||||
MountTarget mt = mapper.readValue("""
|
||||
{
|
||||
"MountTargetId": "fsmt-legacy",
|
||||
"AvailabilityZoneName": "ap-southeast-1a",
|
||||
"AvailabilityZoneId": "ap-southeast-1-az1"
|
||||
}
|
||||
""", MountTarget.class);
|
||||
|
||||
assertEquals("apse1-az1", mt.getAvailabilityZoneId());
|
||||
|
||||
String written = mapper.writeValueAsString(mt);
|
||||
assertEquals("apse1-az1", mapper.readTree(written).get("AvailabilityZoneId").asText());
|
||||
assertEquals("apse1-az1", mapper.readValue(written, MountTarget.class).getAvailabilityZoneId());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user