mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(docdb): isolate container identity by account and region (#8888)
A DocumentDB cluster's MongoDB container was named after the cluster identifier alone, and the manager kept its live handles under that identifier too. Creating a same-named cluster in another account or Region removed the first cluster's container and replaced its handle, so a later delete or shutdown could no longer reach it. Container names now carry the account and Region (floci-aws-docdb-<account>-<region>-<cluster>), and live handles are kept by Docker ID. Deleting a cluster closes the log stream its container was started with, which the handle DeleteDBCluster rebuilds from the stored record does not carry. Ported from #5724. Co-authored-by: Daniël van Ziel <159726064+danielvanza@users.noreply.github.com>
This commit is contained in:
1 parent
6afd82c9fb
commit
1df1af297d
5 files changed
+78
-6
No files matched your search
@@ -110,6 +110,13 @@ public final class ContainerStorageHelper {
|
||||
return dockerName(config, service + "-" + (volumeId != null ? volumeId : fallbackId));
|
||||
}
|
||||
|
||||
/** Scopes name-based resources without changing the identity of an existing data volume. */
|
||||
public static String resourceName(EmulatorConfig config, String service, String volumeId, String fallbackId,
|
||||
String accountId, String region) {
|
||||
return resourceName(config, service, volumeId,
|
||||
sanitizeNamePart(accountId) + "-" + sanitizeNamePart(region) + "-" + fallbackId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefixes {@code baseName} with {@code floci-aws-} and the configured resource namespace,
|
||||
* which lands after the cloud token: {@code floci-aws-<namespace>-<base>}.
|
||||
|
||||
@@ -108,7 +108,9 @@ public class DocDbContainerManager {
|
||||
String region) {
|
||||
LOG.infov("Starting DocumentDB container for cluster: {0}", clusterId);
|
||||
|
||||
String containerName = ContainerStorageHelper.resourceName(config, "docdb", null, clusterId);
|
||||
String accountId = regionResolver.getAccountId();
|
||||
String containerName = ContainerStorageHelper.resourceName(config, "docdb", null, clusterId,
|
||||
accountId, region);
|
||||
lifecycleManager.removeIfExists(containerName);
|
||||
|
||||
List<String> envVars = List.of(
|
||||
@@ -122,7 +124,7 @@ public class DocDbContainerManager {
|
||||
.withLogRotation()
|
||||
.withEnv(envVars)
|
||||
.withLabels(ContainerStorageHelper.resourceIdentityLabels(
|
||||
"docdb", clusterId, regionResolver.getAccountId(), region));
|
||||
"docdb", clusterId, accountId, region));
|
||||
|
||||
if (!containerDetector.isRunningInContainer()) {
|
||||
specBuilder.withDynamicPort(MONGO_PORT);
|
||||
@@ -139,7 +141,8 @@ public class DocDbContainerManager {
|
||||
|
||||
DocDbContainerHandle handle = new DocDbContainerHandle(
|
||||
info.containerId(), clusterId, endpoint.host(), endpoint.port());
|
||||
activeContainers.put(clusterId, handle);
|
||||
// Docker IDs remain unique across accounts, regions, and same-named cluster replacements.
|
||||
activeContainers.put(info.containerId(), handle);
|
||||
|
||||
String shortId = info.containerId().length() >= 8
|
||||
? info.containerId().substring(0, 8)
|
||||
@@ -160,8 +163,9 @@ public class DocDbContainerManager {
|
||||
if (handle == null) {
|
||||
return;
|
||||
}
|
||||
activeContainers.remove(handle.getClusterId());
|
||||
lifecycleManager.stopAndRemove(handle.getContainerId(), handle.getLogStream());
|
||||
DocDbContainerHandle active = activeContainers.remove(handle.getContainerId());
|
||||
lifecycleManager.stopAndRemove(handle.getContainerId(),
|
||||
active == null ? handle.getLogStream() : active.getLogStream());
|
||||
}
|
||||
|
||||
public void stopAll() {
|
||||
|
||||
Reference in new issue
Block a user