feat(rds): add mock mode to create clusters and instances without Docker (#1655)

* feat(rds): add mock mode to create clusters/instances without Docker

Floci backs RDS clusters and instances with real Docker containers and an
auth proxy. In CI or environments without access to the Docker socket,
CreateDBCluster/CreateDBInstance fail, so the resources never reach an
available state.

Add FLOCI_SERVICES_RDS_MOCK (default false), mirroring the existing
mock mode of EC2/EKS/ECS/OpenSearch/MSK. When enabled, cluster and
instance creation skip the container and proxy and are registered as
AVAILABLE immediately with a localhost endpoint; delete and runtime
restoration likewise skip all Docker calls. Non-mock behavior is
unchanged.

* fix(rds): make rebootDbInstance mock-aware

In mock mode, reboot skipped the container restart (guarded by a null
containerId) but still started a real TCP auth proxy, breaking the
no-container/no-proxy invariant. Gate the container restart and proxy
start on !mock so a mock reboot only flips status back to AVAILABLE.

* fix(rds): give mock resources unique ports and gate delete proxy stop

Address PR review: mock mode hardcoded proxyBasePort for every cluster and
instance, collapsing all endpoints onto localhost:7001 and leaving usedPorts
unreserved. Allocate a unique proxy port even in mock mode (still skipping the
container and auth proxy), and preserve/reserve the persisted port on restore
instead of resetting it. Also gate proxyManager.stopProxy on !mock in the
delete paths, matching the reboot path. Add tests for standalone-instance
deletion in mock mode and for distinct mock endpoint ports.

* fix(rds): skip Docker volume name for mock cluster members and document mode switching

Review feedback from #1655:
- Cluster member instances created in mock mode no longer persist a
  volume name fabricated from the cluster's null volume id, which a
  later non-mock restore could try to reference.
- Document RDS mock mode on the service page, including that switching
  FLOCI_SERVICES_RDS_MOCK over persisted state is best-effort in both
  directions, matching the other mock-capable services.
This commit is contained in:
David Lopes authored and GitHub committed 2026-07-05 08:43:41 -05:00
1 parent 4a198fd29b
commit f490bbefad
8 files changed
+246 -67

No files matched your search

@@ -14,6 +14,7 @@ import io.github.hectorvent.floci.services.rds.model.DbClusterParameterGroup;
import io.github.hectorvent.floci.services.rds.container.RdsContainerHandle;
import io.github.hectorvent.floci.services.rds.container.RdsContainerManager;
import io.github.hectorvent.floci.services.rds.model.DbInstance;
import io.github.hectorvent.floci.services.rds.model.DbInstanceStatus;
import io.github.hectorvent.floci.services.rds.model.DbParameterGroup;
import io.github.hectorvent.floci.services.rds.model.DbSubnetGroup;
import io.github.hectorvent.floci.services.rds.proxy.RdsProxyManager;
@@ -341,6 +342,108 @@ class RdsServiceTest {
assertTrue(exception.getMessage().contains("still has DB instances"));
}
@Test
void mockModeCreatesClusterAvailableWithoutContainerOrProxy() {
when(config.services().rds().mock()).thenReturn(true);
DbCluster cluster = rdsService.createDbCluster("cluster1", "aurora-postgresql", "16.3",
"admin", "password", "dbname", false, null);
assertEquals(DbInstanceStatus.AVAILABLE, cluster.getStatus());
assertEquals("localhost", cluster.getEndpoint().address());
assertTrue(cluster.getEndpoint().port() > 0);
assertNull(cluster.getContainerId());
verify(containerManager, never()).start(any(), any(), any(), any(), any(), any(), any());
verify(proxyManager, never()).startProxy(any(), any(), anyBoolean(), anyInt(), any(), anyInt(),
any(), any(), any(), any());
}
@Test
void mockModeCreatesClusterInstanceAvailableWithoutContainer() {
when(config.services().rds().mock()).thenReturn(true);
rdsService.createDbCluster("cluster1", "aurora-postgresql", "16.3",
"admin", "password", "dbname", false, null);
DbInstance instance = rdsService.createDbInstance("inst1", "aurora-postgresql", "16.3",
"admin", "password", "dbname", "db.serverless",
0, false, null, null, "cluster1");
assertEquals(DbInstanceStatus.AVAILABLE, instance.getStatus());
assertEquals("localhost", instance.getEndpoint().address());
// No Docker volume name may be persisted: the mock cluster has a null volume id, so the
// fallback would fabricate a name that a later non-mock restore could try to reference.
assertNull(instance.getDockerVolumeName());
verify(containerManager, never()).start(any(), any(), any(), any(), any(), any(), any());
verify(proxyManager, never()).startProxy(any(), any(), anyBoolean(), anyInt(), any(), anyInt(),
any(), any(), any(), any());
}
@Test
void mockModeCreatesStandaloneInstanceAvailableWithoutContainer() {
when(config.services().rds().mock()).thenReturn(true);
DbInstance instance = rdsService.createDbInstance("standalone", "postgres", "16",
"admin", "password", "dbname", "db.t3.micro",
20, false, null, null, null);
assertEquals(DbInstanceStatus.AVAILABLE, instance.getStatus());
assertNull(instance.getContainerId());
verify(containerManager, never()).start(any(), any(), any(), any(), any(), any(), any());
}
@Test
void mockModeDeleteClusterSkipsDockerCleanup() {
when(config.services().rds().mock()).thenReturn(true);
rdsService.createDbCluster("cluster1", "aurora-postgresql", "16.3",
"admin", "password", "dbname", false, null);
rdsService.deleteDbCluster("cluster1");
verify(containerManager, never()).stop(any());
verify(containerManager, never()).removeVolume(any(), any());
}
@Test
void mockModeDeleteStandaloneInstanceSkipsDockerCleanup() {
when(config.services().rds().mock()).thenReturn(true);
rdsService.createDbInstance("standalone", "postgres", "16",
"admin", "password", "dbname", "db.t3.micro",
20, false, null, null, null);
rdsService.deleteDbInstance("standalone");
verify(containerManager, never()).stop(any());
verify(containerManager, never()).removeVolume(any(), any());
}
@Test
void mockModeAssignsDistinctEndpointPorts() {
when(config.services().rds().mock()).thenReturn(true);
DbCluster a = rdsService.createDbCluster("cluster-a", "aurora-postgresql", "16.3",
"admin", "password", "dbname", false, null);
DbCluster b = rdsService.createDbCluster("cluster-b", "aurora-postgresql", "16.3",
"admin", "password", "dbname", false, null);
assertNotEquals(a.getEndpoint().port(), b.getEndpoint().port());
}
@Test
void mockModeRebootSkipsContainerAndProxy() {
when(config.services().rds().mock()).thenReturn(true);
rdsService.createDbInstance("standalone", "postgres", "16",
"admin", "password", "dbname", "db.t3.micro",
20, false, null, null, null);
DbInstance rebooted = rdsService.rebootDbInstance("standalone");
assertEquals(DbInstanceStatus.AVAILABLE, rebooted.getStatus());
verify(containerManager, never()).start(any(), any(), any(), any(), any(), any(), any());
verify(containerManager, never()).stop(any());
verify(proxyManager, never()).startProxy(any(), any(), anyBoolean(), anyInt(), any(), anyInt(),
any(), any(), any(), any());
}
@Test
void createDbClusterRejectsUnknownClusterParameterGroup() {
AwsException exception = assertThrows(AwsException.class, () -> rdsService.createDbCluster("cluster1", "aurora-postgresql", "16.3",