mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(storage): create a host bind directory only on the Docker host, MemoryDB included (#8247)
* refactor(storage): create a host bind directory only on the Docker host, in one place * fix(memorydb): leave the bind directory to Docker when Floci runs in a container * test(memorydb): build each test's container manager through one helper
This commit is contained in:
1 parent
235179313b
commit
5cf3c780d4
11 files changed
+119
-77
No files matched your search
@@ -407,8 +407,23 @@ public final class ContainerStorageHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the host data directory exists for host-path mode (absolute paths only).
|
||||
* Called by managers in their legacy host-path code paths.
|
||||
* Ensures each host data directory exists for host-path mode, when Floci runs on the Docker
|
||||
* host. The paths name directories on the Docker host: inside a container Floci cannot reach
|
||||
* them, so it leaves a missing bind source for the daemon to create. Managers call this in their
|
||||
* legacy host-path code paths.
|
||||
*/
|
||||
public static void ensureHostDir(ContainerDetector containerDetector, String... hostDataPaths) {
|
||||
if (containerDetector.isRunningInContainer()) {
|
||||
return;
|
||||
}
|
||||
for (String hostDataPath : hostDataPaths) {
|
||||
ensureHostDir(hostDataPath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the host data directory exists for host-path mode (absolute paths only), wherever
|
||||
* Floci runs; managers go through {@link #ensureHostDir(ContainerDetector, String...)}.
|
||||
*/
|
||||
public static void ensureHostDir(String hostDataPath) {
|
||||
try {
|
||||
|
||||
@@ -141,9 +141,7 @@ public class RabbitMqManager {
|
||||
} else {
|
||||
String hostDataPath = ContainerStorageHelper.hostResourcePath(config, "amazonmq", broker.getBrokerId())
|
||||
.toAbsolutePath().toString();
|
||||
if (!containerDetector.isRunningInContainer()) {
|
||||
ContainerStorageHelper.ensureHostDir(hostDataPath);
|
||||
}
|
||||
ContainerStorageHelper.ensureHostDir(containerDetector, hostDataPath);
|
||||
specBuilder.withBind(hostDataPath, "/var/lib/rabbitmq");
|
||||
}
|
||||
|
||||
|
||||
@@ -78,9 +78,7 @@ public class DsqlDatabases {
|
||||
spec.withNamedVolume(name, DATA_PATH);
|
||||
} else {
|
||||
String hostPath = ContainerStorageHelper.hostResourcePath(config, "dsql", cluster.getIdentifier()).toString();
|
||||
if (!containerDetector.isRunningInContainer()) {
|
||||
ContainerStorageHelper.ensureHostDir(hostPath);
|
||||
}
|
||||
ContainerStorageHelper.ensureHostDir(containerDetector, hostPath);
|
||||
spec.withBind(hostPath, DATA_PATH);
|
||||
}
|
||||
if (containerDetector.isRunningInContainer()) {
|
||||
|
||||
@@ -495,13 +495,9 @@ public class Ec2VolumeBlockDeviceManager implements ContainerTeardown, Resettabl
|
||||
String volumeName = ContainerStorageHelper.dockerName(config, "ec2-volumes");
|
||||
ContainerStorageHelper.applyNamedVolume(builder, lifecycleManager, volumeName, "/volumes");
|
||||
} else {
|
||||
// The host path names a directory on the Docker host. Inside a container Floci
|
||||
// cannot reach it, so the daemon creates the missing bind source instead.
|
||||
String hostPath = ContainerStorageHelper.hostResourcePath(config, "ec2", "volumes")
|
||||
.toAbsolutePath().toString();
|
||||
if (!containerDetector.isRunningInContainer()) {
|
||||
ContainerStorageHelper.ensureHostDir(hostPath);
|
||||
}
|
||||
ContainerStorageHelper.ensureHostDir(containerDetector, hostPath);
|
||||
builder.withBind(hostPath, "/volumes");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -167,7 +167,7 @@ public class MemoryDbContainerManager {
|
||||
ContainerStorageHelper.applyNamedVolume(specBuilder, lifecycleManager, volumeName, "/data");
|
||||
} else {
|
||||
String path = ContainerStorageHelper.hostResourcePath(config, "memorydb", volumeId).toString();
|
||||
ContainerStorageHelper.ensureHostDir(path);
|
||||
ContainerStorageHelper.ensureHostDir(containerDetector, path);
|
||||
specBuilder.withBind(path, "/data");
|
||||
}
|
||||
specBuilder.withCmd(List.of("--appendonly", "yes", "--appendfsync", "always"));
|
||||
|
||||
@@ -262,9 +262,7 @@ public class RedpandaManager {
|
||||
} else {
|
||||
// Legacy host-path mode: host-persistent-path is an absolute path
|
||||
String hostDataPath = legacyCompatibleHostPath(cluster).toAbsolutePath().toString();
|
||||
if (!containerDetector.isRunningInContainer()) {
|
||||
ContainerStorageHelper.ensureHostDir(hostDataPath);
|
||||
}
|
||||
ContainerStorageHelper.ensureHostDir(containerDetector, hostDataPath);
|
||||
specBuilder.withBind(hostDataPath, "/var/lib/redpanda/data");
|
||||
}
|
||||
|
||||
|
||||
@@ -166,9 +166,7 @@ public class OpenSearchDomainManager {
|
||||
} else {
|
||||
// Legacy host-path mode: host-persistent-path is an absolute path
|
||||
Path dataPath = legacyCompatibleHostDataPath(domain);
|
||||
if (!containerDetector.isRunningInContainer()) {
|
||||
ContainerStorageHelper.ensureHostDir(dataPath.toString());
|
||||
}
|
||||
ContainerStorageHelper.ensureHostDir(containerDetector, dataPath.toString());
|
||||
String dataPathStr = dataPath.toAbsolutePath().normalize().toString();
|
||||
String persistentPathStr = Path.of(config.storage().persistentPath()).toAbsolutePath().normalize().toString();
|
||||
String hostDataPath = dataPathStr.replace(persistentPathStr, config.storage().hostPersistentPath());
|
||||
@@ -331,9 +329,7 @@ public class OpenSearchDomainManager {
|
||||
Path domainDataPath = namespace.isBlank()
|
||||
? Path.of(dataVolume, arn.accountId(), arn.region(), domain.getDomainName())
|
||||
: Path.of(dataVolume, namespace, arn.accountId(), arn.region(), domain.getDomainName());
|
||||
if (!containerDetector.isRunningInContainer()) {
|
||||
ContainerStorageHelper.ensureHostDir(domainDataPath.toString());
|
||||
}
|
||||
ContainerStorageHelper.ensureHostDir(containerDetector, domainDataPath.toString());
|
||||
hostPath = domainDataPath.toAbsolutePath().normalize().toString();
|
||||
}
|
||||
lifecycleManager.ensureBindDirectory(hostPath, image, CONTAINER_DATA_PATH);
|
||||
|
||||
@@ -841,9 +841,7 @@ public class RdsContainerManager implements RdsBackendGate, RdsBackendEndpointRe
|
||||
// Legacy host-path mode: host-persistent-path is an absolute path
|
||||
String hostDataPath = ContainerStorageHelper.hostResourcePath(
|
||||
config, "rds", storageResourceId).toString();
|
||||
if (!containerDetector.isRunningInContainer()) {
|
||||
ContainerStorageHelper.ensureHostDir(hostDataPath);
|
||||
}
|
||||
ContainerStorageHelper.ensureHostDir(containerDetector, hostDataPath);
|
||||
specBuilder.withBind(hostDataPath, engineDefaultDataPath(engine, image));
|
||||
}
|
||||
|
||||
|
||||
+1
-4
@@ -327,10 +327,7 @@ public class TimestreamInfluxDbContainerManager implements ContainerTeardown {
|
||||
Path base = ContainerStorageHelper.hostResourcePath(config, SERVICE, resourceId);
|
||||
String dataDir = base.resolve("data").toAbsolutePath().toString();
|
||||
String configDir = base.resolve("config").toAbsolutePath().toString();
|
||||
if (!containerDetector.isRunningInContainer()) {
|
||||
ContainerStorageHelper.ensureHostDir(dataDir);
|
||||
ContainerStorageHelper.ensureHostDir(configDir);
|
||||
}
|
||||
ContainerStorageHelper.ensureHostDir(containerDetector, dataDir, configDir);
|
||||
builder.withBind(dataDir, DATA_PATH).withBind(configDir, CONFIG_PATH);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user