mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(rds): advertise the configured endpoint host on DB proxies (#9024)
This commit is contained in:
1 parent
b8a74a2a67
commit
b6af0646d5
2 files changed
+34
-2
No files matched your search
@@ -7253,7 +7253,7 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
}
|
||||
proxy.setTags(tags);
|
||||
proxy.setProxyPort(proxyPort);
|
||||
proxy.setEndpointHost(mock ? "localhost" : proxyEndpointHost());
|
||||
proxy.setEndpointHost(mock ? "localhost" : dbProxyEndpointHost());
|
||||
proxy.setStatus("available");
|
||||
Instant now = Instant.now();
|
||||
proxy.setCreatedAt(now);
|
||||
@@ -9337,6 +9337,13 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
return dockerHostResolver != null ? dockerHostResolver.resolve() : "localhost";
|
||||
}
|
||||
|
||||
/** The host a DB proxy advertises: the configured endpoint host when set, as for instances. */
|
||||
private String dbProxyEndpointHost() {
|
||||
return config.services().rds().endpointHost()
|
||||
.filter(host -> !host.isBlank())
|
||||
.orElseGet(this::proxyEndpointHost);
|
||||
}
|
||||
|
||||
private void validateDbProxyCreate(String name, String engineFamily, String roleArn,
|
||||
List<String> subnetIds, List<DbProxyAuth> auth,
|
||||
String defaultAuthScheme, int idleClientTimeout) {
|
||||
@@ -10332,7 +10339,7 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
ensureRestoredDefaultTargetGroup(proxy);
|
||||
continue;
|
||||
}
|
||||
proxy.setEndpointHost(proxyEndpointHost());
|
||||
proxy.setEndpointHost(dbProxyEndpointHost());
|
||||
persistRestoredProxy(proxy);
|
||||
DbProxyTargetGroup targetGroup = ensureRestoredDefaultTargetGroup(proxy);
|
||||
if (targetGroup.getTargets().isEmpty()) {
|
||||
|
||||
@@ -3992,6 +3992,31 @@ class RdsServiceTest {
|
||||
assertEquals("floci.local", instance.getEndpoint().address());
|
||||
}
|
||||
|
||||
@Test
|
||||
void dbProxyEndpointUsesConfiguredEndpointHostOnCreateAndRestore() {
|
||||
DockerHostResolver dockerHostResolver = mock(DockerHostResolver.class);
|
||||
when(dockerHostResolver.resolve()).thenReturn("floci.local");
|
||||
when(config.services().rds().endpointHost()).thenReturn(Optional.of("db.local"));
|
||||
StorageBackend<String, DbProxy> proxies = new InMemoryStorage<>();
|
||||
StorageBackend<String, DbProxyTargetGroup> proxyTargetGroups = new InMemoryStorage<>();
|
||||
RdsService service = new RdsService(containerManager, proxyManager, ec2Service, regionResolver, config,
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>(), null, dockerHostResolver,
|
||||
proxies, proxyTargetGroups);
|
||||
|
||||
DbProxy created = service.createDbProxy("app-proxy", "POSTGRESQL", true, false, PROXY_ROLE_ARN,
|
||||
PROXY_SUBNET_IDS, List.of(), PROXY_AUTH, Map.of());
|
||||
assertEquals("db.local", created.getEndpoint());
|
||||
|
||||
RdsService restarted = new RdsService(containerManager, proxyManager, ec2Service, regionResolver, config,
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>(), null, dockerHostResolver,
|
||||
proxies, proxyTargetGroups);
|
||||
restarted.restorePersistedRuntime();
|
||||
|
||||
assertEquals("db.local", restarted.getDbProxy("app-proxy").getEndpoint());
|
||||
}
|
||||
|
||||
@Test
|
||||
void dbInstanceEndpointUsesPublishedProxyPort() {
|
||||
CurrentContainerNetworkResolver currentContainerNetworkResolver = mock(CurrentContainerNetworkResolver.class);
|
||||
|
||||
Reference in new issue
Block a user