mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(rds): resolve AWS-managed default DB cluster parameter groups on reference (#1805)
* fix(rds): resolve AWS-managed default DB cluster parameter groups on reference AWS ships a managed default DB cluster parameter group per engine family (e.g. default.aurora-postgresql16) that always exists. A cluster that uses the engine default — as the CDK emits when no cluster parameter group is specified — referenced default.<family>, which getDbClusterParameterGroup rejected with DBClusterParameterGroupNotFound, so CreateDBCluster failed. Materialize a default.<family> cluster parameter group on first reference (family = the segment after "default."), reproducing AWS's always-present managed defaults. Non-default unknown names still raise DBClusterParameterGroupNotFound. * fix(rds): materialize named default cluster groups * fix(rds): catalog managed cluster parameter groups * fix(rds): validate managed cluster parameter families * fix(rds): protect managed cluster parameter groups * test(rds): lock cluster listing error message * chore: re-run CI The Build and Test failure on the previous head was RuntimeApiServerTest's extension/stop race, a pre-existing flake unrelated to this change — it also failed on #1820, #1823 and on #2131's own branch (the PR that tried to de-flake it). Reproduced locally under `--cpus=1` and fixed separately.
This commit is contained in:
1 parent
ee15447ba4
commit
b31cbb9231
2 files changed
+315
-8
No files matched your search
@@ -22,6 +22,8 @@ import io.github.hectorvent.floci.services.secretsmanager.SecretsManagerService;
|
||||
import io.github.hectorvent.floci.services.secretsmanager.model.Secret;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -42,6 +44,27 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
class RdsServiceTest {
|
||||
|
||||
private static final List<String> CURRENT_MANAGED_CLUSTER_PARAMETER_GROUP_FAMILIES = List.of(
|
||||
"aurora-mysql5.7",
|
||||
"aurora-mysql8.0",
|
||||
"aurora-mysql8.4",
|
||||
"aurora-postgresql11",
|
||||
"aurora-postgresql12",
|
||||
"aurora-postgresql13",
|
||||
"aurora-postgresql14",
|
||||
"aurora-postgresql15",
|
||||
"aurora-postgresql16",
|
||||
"aurora-postgresql17",
|
||||
"aurora-postgresql18",
|
||||
"mysql8.0",
|
||||
"mysql8.4",
|
||||
"postgres13",
|
||||
"postgres14",
|
||||
"postgres15",
|
||||
"postgres16",
|
||||
"postgres17",
|
||||
"postgres18");
|
||||
|
||||
private RdsService rdsService;
|
||||
private RdsContainerManager containerManager;
|
||||
private RdsProxyManager proxyManager;
|
||||
@@ -574,6 +597,103 @@ class RdsServiceTest {
|
||||
assertEquals("DBClusterParameterGroupName doesn't refer to an existing DB cluster parameter group.", exception.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"aurora-mysql, 5.7.mysql_aurora.2.12.4, aurora-mysql5.7",
|
||||
"aurora-mysql, 8.0.mysql_aurora.3.10.0, aurora-mysql8.0",
|
||||
"aurora-mysql, 8.4.mysql_aurora.8.4.7, aurora-mysql8.4",
|
||||
"aurora-postgresql, 11.21, aurora-postgresql11",
|
||||
"aurora-postgresql, 12.22, aurora-postgresql12",
|
||||
"aurora-postgresql, 13.18, aurora-postgresql13",
|
||||
"aurora-postgresql, 14.15, aurora-postgresql14",
|
||||
"aurora-postgresql, 15.10, aurora-postgresql15",
|
||||
"aurora-postgresql, 16.4, aurora-postgresql16",
|
||||
"aurora-postgresql, 17.4, aurora-postgresql17",
|
||||
"aurora-postgresql, 18.3, aurora-postgresql18",
|
||||
"mysql, 8.0.36, mysql8.0",
|
||||
"mysql, 8.4.7, mysql8.4",
|
||||
"postgres, 13.20, postgres13",
|
||||
"postgres, 14.17, postgres14",
|
||||
"postgres, 15.12, postgres15",
|
||||
"postgres, 16.8, postgres16",
|
||||
"postgres, 17.4, postgres17",
|
||||
"postgres, 18.1, postgres18"
|
||||
})
|
||||
void createDbClusterAcceptsCurrentAwsDefaultClusterParameterGroups(
|
||||
String engine, String engineVersion, String family) {
|
||||
String groupName = "default." + family;
|
||||
|
||||
DbCluster cluster = rdsService.createDbCluster("cluster", engine, engineVersion,
|
||||
"admin", "password", "coredb", false, groupName);
|
||||
|
||||
assertEquals("cluster", cluster.getDbClusterIdentifier());
|
||||
assertEquals(family, rdsService.getDbClusterParameterGroup(groupName).getDbParameterGroupFamily());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbClusterRejectsUnsupportedAwsDefaultClusterParameterGroup() {
|
||||
AwsException exception = assertThrows(AwsException.class, () ->
|
||||
rdsService.createDbCluster("aurora-cluster", "aurora-postgresql", "16.4",
|
||||
"admin", "password", "coredb", false,
|
||||
"default.aurora-postgresql999"));
|
||||
|
||||
assertEquals("DBClusterParameterGroupNotFound", exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listDbClusterParameterGroupsAlwaysIncludesStableManagedDefaults() {
|
||||
List<String> before = rdsService.listDbClusterParameterGroups(null).stream()
|
||||
.map(group -> group.getDbClusterParameterGroupName()
|
||||
+ ":" + group.getDbParameterGroupFamily())
|
||||
.toList();
|
||||
|
||||
Collection<DbClusterParameterGroup> groups =
|
||||
rdsService.listDbClusterParameterGroups("default.aurora-postgresql16");
|
||||
|
||||
assertEquals(1, groups.size());
|
||||
DbClusterParameterGroup group = groups.iterator().next();
|
||||
assertEquals("default.aurora-postgresql16", group.getDbClusterParameterGroupName());
|
||||
assertEquals("aurora-postgresql16", group.getDbParameterGroupFamily());
|
||||
assertEquals("Default cluster parameter group", group.getDescription());
|
||||
List<String> after = rdsService.listDbClusterParameterGroups(null).stream()
|
||||
.map(item -> item.getDbClusterParameterGroupName()
|
||||
+ ":" + item.getDbParameterGroupFamily())
|
||||
.toList();
|
||||
assertEquals(CURRENT_MANAGED_CLUSTER_PARAMETER_GROUP_FAMILIES.stream()
|
||||
.map(family -> "default." + family + ":" + family)
|
||||
.toList(), before);
|
||||
assertEquals(before, after);
|
||||
}
|
||||
|
||||
@Test
|
||||
void unsupportedManagedDefaultNamesAreNotFabricatedByReads() {
|
||||
List<String> before = rdsService.listDbClusterParameterGroups(null).stream()
|
||||
.map(DbClusterParameterGroup::getDbClusterParameterGroupName)
|
||||
.toList();
|
||||
|
||||
for (String name : List.of("default.", "default.not-a-real-family",
|
||||
"default.aurora-postgresql999", "default.mariadb11.2")) {
|
||||
AwsException exception = assertThrows(
|
||||
AwsException.class, () -> rdsService.getDbClusterParameterGroup(name));
|
||||
assertEquals("DBClusterParameterGroupNotFound", exception.getErrorCode());
|
||||
}
|
||||
|
||||
assertEquals(before, rdsService.listDbClusterParameterGroups(null).stream()
|
||||
.map(DbClusterParameterGroup::getDbClusterParameterGroupName)
|
||||
.toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void namedClusterParameterGroupListingUsesAwsNotFoundCode() {
|
||||
AwsException exception = assertThrows(AwsException.class, () ->
|
||||
rdsService.listDbClusterParameterGroups("default.not-a-real-family"));
|
||||
|
||||
assertEquals("DBParameterGroupNotFound", exception.getErrorCode());
|
||||
assertEquals("DBParameterGroupName doesn't refer to an existing DB parameter group.",
|
||||
exception.getMessage());
|
||||
assertEquals(404, exception.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbClusterRejectsIncompatibleClusterParameterGroupFamily() {
|
||||
rdsService.createDbClusterParameterGroup("cpg1", "aurora-mysql8.0", "test group");
|
||||
@@ -586,6 +706,22 @@ class RdsServiceTest {
|
||||
exception.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"aurora-postgresql, 16.4, default.aurora-postgresql15",
|
||||
"aurora-mysql, 8.0.mysql_aurora.3.10.0, default.aurora-mysql5.7",
|
||||
"postgres, 16.8, default.postgres15",
|
||||
"mysql, 8.4.7, default.mysql8.0"
|
||||
})
|
||||
void createDbClusterRejectsManagedDefaultFromAnotherMajorVersion(
|
||||
String engine, String engineVersion, String groupName) {
|
||||
AwsException exception = assertThrows(AwsException.class, () ->
|
||||
rdsService.createDbCluster("cluster", engine, engineVersion,
|
||||
"admin", "password", "coredb", false, groupName));
|
||||
|
||||
assertEquals("InvalidParameterCombination", exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbClusterParameterGroupRoundTrip() {
|
||||
DbClusterParameterGroup created = rdsService.createDbClusterParameterGroup(
|
||||
@@ -598,7 +734,42 @@ class RdsServiceTest {
|
||||
assertEquals("cpg1", fetched.getDbClusterParameterGroupName());
|
||||
|
||||
Collection<DbClusterParameterGroup> listed = rdsService.listDbClusterParameterGroups(null);
|
||||
assertEquals(1, listed.size());
|
||||
List<String> names = listed.stream()
|
||||
.map(DbClusterParameterGroup::getDbClusterParameterGroupName)
|
||||
.toList();
|
||||
assertEquals(CURRENT_MANAGED_CLUSTER_PARAMETER_GROUP_FAMILIES.size() + 1, names.size());
|
||||
assertTrue(names.containsAll(CURRENT_MANAGED_CLUSTER_PARAMETER_GROUP_FAMILIES.stream()
|
||||
.map(family -> "default." + family)
|
||||
.toList()));
|
||||
assertTrue(names.contains("cpg1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbClusterParameterGroupRejectsManagedDefaultName() {
|
||||
AwsException exception = assertThrows(AwsException.class, () ->
|
||||
rdsService.createDbClusterParameterGroup(
|
||||
"default.aurora-postgresql16", "aurora-postgresql16", "shadow"));
|
||||
|
||||
assertEquals("DBParameterGroupAlreadyExists", exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void persistedManagedDefaultOverridesCatalogWithoutDuplication() {
|
||||
StorageBackend<String, DbClusterParameterGroup> clusterGroups = new InMemoryStorage<>();
|
||||
clusterGroups.put("default.aurora-postgresql16", new DbClusterParameterGroup(
|
||||
"default.aurora-postgresql16", "aurora-postgresql16", "persisted default"));
|
||||
RdsService service = newService(containerManager, proxyManager,
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),
|
||||
clusterGroups, new InMemoryStorage<>());
|
||||
|
||||
List<DbClusterParameterGroup> listed = List.copyOf(service.listDbClusterParameterGroups(null));
|
||||
assertEquals(CURRENT_MANAGED_CLUSTER_PARAMETER_GROUP_FAMILIES.size(), listed.size());
|
||||
List<DbClusterParameterGroup> matching = listed.stream()
|
||||
.filter(group -> "default.aurora-postgresql16".equals(
|
||||
group.getDbClusterParameterGroupName()))
|
||||
.toList();
|
||||
assertEquals(1, matching.size());
|
||||
assertEquals("persisted default", matching.getFirst().getDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -744,6 +915,31 @@ class RdsServiceTest {
|
||||
assertEquals("pg_stat_statements", modified.getParameters().get("shared_preload_libraries"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyManagedDefaultClusterParameterGroupIsRejectedWithoutPersistingChanges() {
|
||||
String name = "default.aurora-postgresql16";
|
||||
|
||||
AwsException exception = assertThrows(AwsException.class, () ->
|
||||
rdsService.modifyDbClusterParameterGroup(
|
||||
name, Map.of("log_statement", "all")));
|
||||
|
||||
assertEquals("InvalidDBParameterGroupState", exception.getErrorCode());
|
||||
assertEquals(400, exception.getHttpStatus());
|
||||
assertTrue(rdsService.getDbClusterParameterGroup(name).getParameters().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteManagedDefaultClusterParameterGroupIsRejectedAndGroupRemainsResolvable() {
|
||||
String name = "default.aurora-postgresql16";
|
||||
|
||||
AwsException exception = assertThrows(AwsException.class, () ->
|
||||
rdsService.deleteDbClusterParameterGroup(name));
|
||||
|
||||
assertEquals("InvalidDBParameterGroupState", exception.getErrorCode());
|
||||
assertEquals(400, exception.getHttpStatus());
|
||||
assertEquals(name, rdsService.getDbClusterParameterGroup(name).getDbClusterParameterGroupName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteDbClusterParameterGroupMissingThrows() {
|
||||
AwsException exception = assertThrows(AwsException.class, () ->
|
||||
|
||||
Reference in new issue
Block a user