mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(core): label emulated resource containers with io.floci.* identity (#2497)
* feat(core): add io.floci.* resource-identity labels Introduces ContainerStorageHelper.resourceIdentityLabels(service, resourceId, accountId, region), so a container manager can tag its spawned container with the emulated resource's identity. Additive to the existing floci/floci_emulator/floci_namespace labels. Relates to #1818 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * feat(rds): label RDS containers with resource identity RDS backing containers now carry io.floci.service=rds, io.floci.resource-id=<instanceId>, io.floci.account, and io.floci.region so a spawned container can be mapped back to the DBInstanceIdentifier it emulates without empirical docker exec probing. Account/region reuse the same ARN parsing already done for log-stream routing; extracted into resolveRuntimeIdentity so both call sites share one source of truth. Closes #1818 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * feat(docdb): label DocDB containers with resource identity DocDB backing containers now carry io.floci.service=docdb and io.floci.resource-id=<clusterId> alongside account/region. Relates to #1818 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * feat(elasticache): label ElastiCache Redis/Valkey containers with resource identity Backing containers now carry io.floci.service=elasticache and io.floci.resource-id=<groupId> alongside account/region. Relates to #1818 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * feat(elasticache): label ElastiCache Memcached containers with resource identity Backing containers now carry io.floci.service=elasticache and io.floci.resource-id=<clusterId> alongside account/region. Relates to #1818 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * feat(memorydb): label MemoryDB containers with resource identity Backing containers now carry io.floci.service=memorydb and io.floci.resource-id=<clusterName> alongside account/region. Relates to #1818 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * feat(neptune): label Neptune containers with resource identity Backing containers now carry io.floci.service=neptune and io.floci.resource-id=<clusterId> alongside account/region. Relates to #1818 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * feat(msk): label MSK containers with resource identity Redpanda backing containers now carry io.floci.service=msk and io.floci.resource-id=<clusterName> alongside account/region. Relates to #1818 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * feat(opensearch): label OpenSearch containers with resource identity Backing containers now carry io.floci.service=opensearch and io.floci.resource-id=<domainName> alongside account/region. RegionResolver is now injected into OpenSearchDomainManager. Relates to #1818 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * feat(ecs): label ECS task containers with resource identity Backing containers now carry io.floci.service=ecs and io.floci.resource-id=<taskId> alongside account/region. Relates to #1818 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * feat(eks): label EKS k3s containers with resource identity Backing containers now carry io.floci.service=eks and io.floci.resource-id=<clusterName> alongside account/region. RegionResolver is now injected into EksClusterManager. Relates to #1818 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * feat(amazonmq): label AmazonMQ containers with resource identity RabbitMQ backing containers now carry io.floci.service=amazonmq and io.floci.resource-id=<brokerId> alongside account/region. Relates to #1818 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * feat(mwaa): label MWAA containers with resource identity Both the Postgres metadata container and the Airflow container now carry io.floci.service=mwaa and io.floci.resource-id=<environmentName> alongside account/region. RegionResolver is now injected into MwaaEnvironmentManager. Relates to #1818 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * feat(kinesisanalytics): label Flink containers with resource identity Both the JobManager and TaskManager containers now carry io.floci.service=kinesisanalytics and io.floci.resource-id=<applicationName> alongside account/region. Relates to #1818 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * feat(batch): label Batch job containers with resource identity Job containers now carry io.floci.service=batch and io.floci.resource-id=<jobId>, using the job's own account/region (already carried on BatchJob) rather than RegionResolver. Relates to #1818 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * feat(codebuild): label CodeBuild job containers with resource identity Build containers now carry io.floci.service=codebuild and io.floci.resource-id=<buildId> alongside account/region. No new unit test: the container-spawn call site lives inside the private multi-phase runBuild() method, entangled with real filesystem and source-download side effects with no existing seam for unit testing in isolation (CodeBuild's only coverage today is the QuarkusTest-based CodeBuildIntegrationTest, which would need a real Docker daemon and a full build run to assert container labels). Relates to #1818 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * feat(lambda): label function containers with resource identity Lambda containers now carry io.floci.service=lambda and io.floci.resource-id=<functionName>, reusing the existing ARN-based region resolution and adding the equivalent account lookup. Relates to #1818 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * feat(ec2): label EC2 instance containers with resource identity Backing containers now carry io.floci.service=ec2 and io.floci.resource-id=<instanceId>, using the already-passed region parameter and a new RegionResolver dependency for the account id. Relates to #1818 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * feat(ecr): label the shared registry container with resource identity The registry:2 container carries io.floci.service=ecr with no resource-id, since it is a shared singleton, not a per-resource container. Relates to #1818 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * docs(core): document io.floci.* resource-identity labels Relates to #1818 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * style(tests): use imports instead of inline FQCN in resource-identity label tests Cleans up the Batch, EKS, and OpenSearch label tests added earlier in this branch, which used fully-qualified names inline instead of imports. Relates to #1818 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * fix(kinesisanalytics): restore Mockito import and awsEnv param in Flink label test Silently dropped by the rebase's clean auto-merge; the test no longer compiled without them. Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * docs(core): note ECR keeps every identity label except resource-id EcrRegistryManager still passes account/region for the shared registry container; only resourceId is omitted. Docs previously said the opposite. Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * test(elasticache): log swallowed IOException in label test cleanup Matches the pattern already used in the DocDB/Neptune/MemoryDB label tests. Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> --------- Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
1 parent
6f1ce9b23f
commit
824701481c
38 files changed
+972
-48
No files matched your search
+25
@@ -105,6 +105,31 @@ public final class ContainerStorageHelper {
|
||||
return labels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Labels tying a container to the specific AWS resource it emulates: {@code io.floci}
|
||||
* (cloud provider, for multi-cloud discovery), {@code io.floci.service},
|
||||
* {@code io.floci.resource-id}, {@code io.floci.account}, and {@code io.floci.region}.
|
||||
* Merged into a spec's own labels (never into {@link #defaultLabels}), so callers pass
|
||||
* this to {@link ContainerBuilder.Builder#withLabels}. A blank or null value omits that
|
||||
* key entirely, e.g. ECR's shared registry container has no per-resource id.
|
||||
*/
|
||||
public static Map<String, String> resourceIdentityLabels(
|
||||
String service, String resourceId, String accountId, String region) {
|
||||
Map<String, String> labels = new LinkedHashMap<>();
|
||||
labels.put("io.floci", CLOUD);
|
||||
putIfNotBlank(labels, "io.floci.service", service);
|
||||
putIfNotBlank(labels, "io.floci.resource-id", resourceId);
|
||||
putIfNotBlank(labels, "io.floci.account", accountId);
|
||||
putIfNotBlank(labels, "io.floci.region", region);
|
||||
return labels;
|
||||
}
|
||||
|
||||
private static void putIfNotBlank(Map<String, String> labels, String key, String value) {
|
||||
if (value != null && !value.isBlank()) {
|
||||
labels.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Path hostResourcePath(EmulatorConfig config, String service, String resourceId) {
|
||||
String namespace = resourceNamespace(config);
|
||||
Path base = Path.of(config.storage().hostPersistentPath());
|
||||
|
||||
+4
-1
@@ -83,7 +83,10 @@ public class RabbitMqManager {
|
||||
ContainerBuilder.Builder specBuilder = containerBuilder.newContainer(image)
|
||||
.withName(containerName)
|
||||
.withDockerNetwork(config.services().dockerNetwork())
|
||||
.withLogRotation();
|
||||
.withLogRotation()
|
||||
.withLabels(ContainerStorageHelper.resourceIdentityLabels(
|
||||
"amazonmq", broker.getBrokerId(), regionResolver.getAccountId(),
|
||||
regionResolver.getDefaultRegion()));
|
||||
|
||||
// Seed the broker's admin user. RabbitMQ's built-in `guest` user is
|
||||
// loopback-only, so it cannot authenticate over the mapped host port; a user
|
||||
|
||||
@@ -74,7 +74,9 @@ public class BatchDockerRunner implements ContainerTeardown {
|
||||
.withDockerNetwork(config.services().batch().dockerNetwork())
|
||||
.withHostDockerInternalOnLinux()
|
||||
.withEmbeddedDns()
|
||||
.withLogRotation();
|
||||
.withLogRotation()
|
||||
.withLabels(ContainerStorageHelper.resourceIdentityLabels(
|
||||
"batch", job.getJobId(), job.getAccountId(), job.getRegion()));
|
||||
|
||||
if (job.getResolvedCommand() != null && !job.getResolvedCommand().isEmpty()) {
|
||||
builder.withCmd(job.getResolvedCommand());
|
||||
|
||||
@@ -14,6 +14,7 @@ import io.github.hectorvent.floci.core.common.docker.ContainerDetector;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLifecycleManager;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLogStreamer;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerSpec;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerStorageHelper;
|
||||
import io.github.hectorvent.floci.services.codebuild.BuildspecParser.ParsedArtifacts;
|
||||
import io.github.hectorvent.floci.services.codebuild.BuildspecParser.ParsedBuildspec;
|
||||
import io.github.hectorvent.floci.services.codebuild.model.Build;
|
||||
@@ -220,6 +221,8 @@ public class CodeBuildRunner implements ContainerTeardown {
|
||||
.withHostDockerInternalOnLinux()
|
||||
.withPrivileged(privileged)
|
||||
.withLogRotation()
|
||||
.withLabels(ContainerStorageHelper.resourceIdentityLabels(
|
||||
"codebuild", buildId, regionResolver.getAccountId(), region))
|
||||
.build();
|
||||
|
||||
ContainerLifecycleManager.ContainerInfo info = lifecycleManager.createAndStart(spec);
|
||||
|
||||
+4
-2
@@ -115,14 +115,16 @@ public class DocDbContainerManager {
|
||||
.withName(containerName)
|
||||
.withDockerNetwork(config.services().docdb().dockerNetwork())
|
||||
.withLogRotation()
|
||||
.withEnv(envVars);
|
||||
.withEnv(envVars)
|
||||
.withLabels(ContainerStorageHelper.resourceIdentityLabels(
|
||||
"docdb", clusterId, regionResolver.getAccountId(), regionResolver.getDefaultRegion()));
|
||||
|
||||
if (!containerDetector.isRunningInContainer()) {
|
||||
specBuilder.withDynamicPort(MONGO_PORT);
|
||||
} else {
|
||||
specBuilder.withExposedPort(MONGO_PORT);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ContainerSpec spec = specBuilder.build();
|
||||
ContainerInfo info = lifecycleManager.createAndStart(spec);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.ec2;
|
||||
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerBuilder;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerDetector;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLifecycleManager;
|
||||
@@ -74,6 +75,7 @@ public class Ec2ContainerManager {
|
||||
private final EmulatorConfig config;
|
||||
private final Ec2MetadataServer metadataServer;
|
||||
private final Ec2PortForwardManager portForwardManager;
|
||||
private final RegionResolver regionResolver;
|
||||
|
||||
private final ExecutorService executor = Executors.newCachedThreadPool(r -> {
|
||||
Thread t = new Thread(r, "ec2-container-launcher");
|
||||
@@ -91,7 +93,8 @@ public class Ec2ContainerManager {
|
||||
PortAllocator portAllocator,
|
||||
EmulatorConfig config,
|
||||
Ec2MetadataServer metadataServer,
|
||||
Ec2PortForwardManager portForwardManager) {
|
||||
Ec2PortForwardManager portForwardManager,
|
||||
RegionResolver regionResolver) {
|
||||
this.containerBuilder = containerBuilder;
|
||||
this.lifecycleManager = lifecycleManager;
|
||||
this.logStreamer = logStreamer;
|
||||
@@ -100,6 +103,7 @@ public class Ec2ContainerManager {
|
||||
this.dockerClient = dockerClient;
|
||||
this.portAllocator = portAllocator;
|
||||
this.config = config;
|
||||
this.regionResolver = regionResolver;
|
||||
this.metadataServer = metadataServer;
|
||||
this.portForwardManager = portForwardManager;
|
||||
}
|
||||
@@ -309,6 +313,8 @@ public class Ec2ContainerManager {
|
||||
.withPortBinding(22, sshHostPort)
|
||||
.withHostDockerInternalOnLinux()
|
||||
.withLogRotation()
|
||||
.withLabels(ContainerStorageHelper.resourceIdentityLabels(
|
||||
"ec2", instanceId, regionResolver.getAccountId(), region))
|
||||
// EC2 instances expose IMDS on 169.254.169.254. Floci needs network administration
|
||||
// privileges in the local container to attach that link-local address.
|
||||
.withPrivileged(true)
|
||||
|
||||
+3
-1
@@ -172,7 +172,9 @@ public class EcrRegistryManager {
|
||||
.withEnv(env)
|
||||
.withPortBinding(CONTAINER_INTERNAL_PORT, chosenPort)
|
||||
.withDockerNetwork(resolveRegistryDockerNetwork())
|
||||
.withLogRotation();
|
||||
.withLogRotation()
|
||||
.withLabels(ContainerStorageHelper.resourceIdentityLabels(
|
||||
"ecr", null, regionResolver.getAccountId(), regionResolver.getDefaultRegion()));
|
||||
|
||||
// Handle persistence mounting based on storage configuration
|
||||
addPersistenceMounts(specBuilder, env);
|
||||
|
||||
+3
-1
@@ -136,7 +136,9 @@ public class EcsContainerManager {
|
||||
// own loopback.
|
||||
.withHostDockerInternalOnLinux()
|
||||
.withEmbeddedDns()
|
||||
.withLogRotation();
|
||||
.withLogRotation()
|
||||
.withLabels(ContainerStorageHelper.resourceIdentityLabels(
|
||||
"ecs", taskId, regionResolver.getAccountId(), region));
|
||||
|
||||
// Add memory limit if specified
|
||||
if (def.getMemory() != null) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.eks;
|
||||
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsRegions;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerBuilder;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerDetector;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLifecycleManager;
|
||||
@@ -60,6 +61,7 @@ public class EksClusterManager {
|
||||
private final DockerHostResolver dockerHostResolver;
|
||||
private final EcrRegistryManager ecrRegistryManager;
|
||||
private final EmulatorConfig config;
|
||||
private final RegionResolver regionResolver;
|
||||
|
||||
@Inject
|
||||
public EksClusterManager(ContainerBuilder containerBuilder,
|
||||
@@ -68,7 +70,8 @@ public class EksClusterManager {
|
||||
PortAllocator portAllocator,
|
||||
DockerHostResolver dockerHostResolver,
|
||||
EcrRegistryManager ecrRegistryManager,
|
||||
EmulatorConfig config) {
|
||||
EmulatorConfig config,
|
||||
RegionResolver regionResolver) {
|
||||
this.containerBuilder = containerBuilder;
|
||||
this.lifecycleManager = lifecycleManager;
|
||||
this.containerDetector = containerDetector;
|
||||
@@ -76,6 +79,7 @@ public class EksClusterManager {
|
||||
this.dockerHostResolver = dockerHostResolver;
|
||||
this.ecrRegistryManager = ecrRegistryManager;
|
||||
this.config = config;
|
||||
this.regionResolver = regionResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,7 +124,9 @@ public class EksClusterManager {
|
||||
.withNamedVolume(volumeName, "/var/lib/rancher/k3s")
|
||||
.withDockerNetwork(config.services().eks().dockerNetwork())
|
||||
.withPrivileged(true)
|
||||
.withLogRotation();
|
||||
.withLogRotation()
|
||||
.withLabels(ContainerStorageHelper.resourceIdentityLabels(
|
||||
"eks", cluster.getName(), regionResolver.getAccountId(), regionResolver.getDefaultRegion()));
|
||||
|
||||
// Wire a token-authentication webhook so `aws eks get-token` bearer tokens are validated by
|
||||
// Floci and mapped to cluster-admin. The k3s API server POSTs a TokenReview to Floci's
|
||||
|
||||
+3
-1
@@ -84,7 +84,9 @@ public class ElastiCacheContainerManager {
|
||||
.withName(containerName)
|
||||
.withEnv("VALKEY_EXTRA_FLAGS", "--loglevel verbose")
|
||||
.withDockerNetwork(config.services().elasticache().dockerNetwork())
|
||||
.withLogRotation();
|
||||
.withLogRotation()
|
||||
.withLabels(ContainerStorageHelper.resourceIdentityLabels(
|
||||
"elasticache", groupId, regionResolver.getAccountId(), regionResolver.getDefaultRegion()));
|
||||
|
||||
if (!containerDetector.isRunningInContainer()) {
|
||||
specBuilder.withDynamicPort(BACKEND_PORT);
|
||||
|
||||
+3
-1
@@ -74,7 +74,9 @@ public class ElastiCacheMemcachedContainerManager {
|
||||
ContainerBuilder.Builder specBuilder = containerBuilder.newContainer(image)
|
||||
.withName(containerName)
|
||||
.withDockerNetwork(config.services().elasticache().dockerNetwork())
|
||||
.withLogRotation();
|
||||
.withLogRotation()
|
||||
.withLabels(ContainerStorageHelper.resourceIdentityLabels(
|
||||
"elasticache", clusterId, regionResolver.getAccountId(), regionResolver.getDefaultRegion()));
|
||||
|
||||
if (!containerDetector.isRunningInContainer()) {
|
||||
specBuilder.withDynamicPort(BACKEND_PORT);
|
||||
|
||||
+7
-1
@@ -153,7 +153,10 @@ public class FlinkContainerManager {
|
||||
.withDockerNetwork(config.services().dockerNetwork())
|
||||
.withHostDockerInternalOnLinux()
|
||||
.withEmbeddedDns()
|
||||
.withLogRotation();
|
||||
.withLogRotation()
|
||||
.withLabels(ContainerStorageHelper.resourceIdentityLabels(
|
||||
"kinesisanalytics", app.getApplicationName(), regionResolver.getAccountId(),
|
||||
regionResolver.getDefaultRegion()));
|
||||
// Named volume (not the container's ephemeral filesystem) so snapshots survive a
|
||||
// Stop/StartApplication cycle — stopCluster() removes the JobManager container, but this
|
||||
// volume is only removed on DeleteApplication (removeSavepointsVolume), mirroring how other
|
||||
@@ -194,6 +197,9 @@ public class FlinkContainerManager {
|
||||
.withEnv("FLINK_PROPERTIES", tmProps)
|
||||
.withNetworkMode("container:" + jm.containerId())
|
||||
.withLogRotation()
|
||||
.withLabels(ContainerStorageHelper.resourceIdentityLabels(
|
||||
"kinesisanalytics", app.getApplicationName(), regionResolver.getAccountId(),
|
||||
regionResolver.getDefaultRegion()))
|
||||
.build();
|
||||
try {
|
||||
ContainerInfo tm = lifecycleManager.createAndStart(tmSpec);
|
||||
|
||||
+4
-1
@@ -251,6 +251,7 @@ public class ContainerLauncher implements LambdaRuntimeLauncher {
|
||||
String cwLogGroup = "/aws/lambda/" + fn.getFunctionName();
|
||||
String cwLogStream = LOG_STREAM_DATE_FMT.format(LocalDate.now()) + "/[$LATEST]" + shortId;
|
||||
String lambdaRegion = extractRegionFromArn(fn.getFunctionArn(), config.defaultRegion());
|
||||
String lambdaAccountId = AwsArnUtils.accountOrDefault(fn.getFunctionArn(), config.defaultAccountId());
|
||||
|
||||
// When TLS is on, the container must trust Floci's self-signed cert so HTTPS callbacks
|
||||
// to Floci succeed (e.g. a CDK custom resource's cfn-response, which hardcodes https://).
|
||||
@@ -298,7 +299,9 @@ public class ContainerLauncher implements LambdaRuntimeLauncher {
|
||||
.withMemoryMb(fn.getMemorySize())
|
||||
.withDockerNetwork(config.services().lambda().dockerNetwork())
|
||||
.withHostDockerInternalOnLinux()
|
||||
.withLogRotation();
|
||||
.withLogRotation()
|
||||
.withLabels(ContainerStorageHelper.resourceIdentityLabels(
|
||||
"lambda", fn.getFunctionName(), lambdaAccountId, lambdaRegion));
|
||||
|
||||
specBuilder.withEmbeddedDns();
|
||||
|
||||
|
||||
+3
-1
@@ -119,7 +119,9 @@ public class MemoryDbContainerManager {
|
||||
ContainerBuilder.Builder specBuilder = containerBuilder.newContainer(image)
|
||||
.withName(containerName)
|
||||
.withDockerNetwork(config.services().memorydb().dockerNetwork())
|
||||
.withLogRotation();
|
||||
.withLogRotation()
|
||||
.withLabels(ContainerStorageHelper.resourceIdentityLabels(
|
||||
"memorydb", clusterName, regionResolver.getAccountId(), regionResolver.getDefaultRegion()));
|
||||
|
||||
if (!containerDetector.isRunningInContainer()) {
|
||||
specBuilder.withDynamicPort(BACKEND_PORT);
|
||||
|
||||
@@ -103,7 +103,10 @@ public class RedpandaManager {
|
||||
ContainerBuilder.Builder specBuilder = containerBuilder.newContainer(image)
|
||||
.withName(containerName)
|
||||
.withDockerNetwork(config.services().dockerNetwork())
|
||||
.withLogRotation();
|
||||
.withLogRotation()
|
||||
.withLabels(ContainerStorageHelper.resourceIdentityLabels(
|
||||
"msk", cluster.getClusterName(), regionResolver.getAccountId(),
|
||||
regionResolver.getDefaultRegion()));
|
||||
|
||||
if (!containerDetector.isRunningInContainer()) {
|
||||
specBuilder.withPortBinding(KAFKA_PORT, kafkaHostPort).withDynamicPort(ADMIN_PORT);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.mwaa;
|
||||
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerBuilder;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerDetector;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLifecycleManager;
|
||||
@@ -65,18 +66,21 @@ public class MwaaEnvironmentManager {
|
||||
private final ContainerDetector containerDetector;
|
||||
private final EmulatorConfig config;
|
||||
private final LaunchedContainerAwsEnv awsEnv;
|
||||
private final RegionResolver regionResolver;
|
||||
|
||||
@Inject
|
||||
public MwaaEnvironmentManager(ContainerBuilder containerBuilder,
|
||||
ContainerLifecycleManager lifecycleManager,
|
||||
ContainerDetector containerDetector,
|
||||
EmulatorConfig config,
|
||||
LaunchedContainerAwsEnv awsEnv) {
|
||||
LaunchedContainerAwsEnv awsEnv,
|
||||
RegionResolver regionResolver) {
|
||||
this.containerBuilder = containerBuilder;
|
||||
this.lifecycleManager = lifecycleManager;
|
||||
this.containerDetector = containerDetector;
|
||||
this.config = config;
|
||||
this.awsEnv = awsEnv;
|
||||
this.regionResolver = regionResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,6 +113,8 @@ public class MwaaEnvironmentManager {
|
||||
.withDockerNetwork(config.services().mwaa().dockerNetwork())
|
||||
.withExposedPort(POSTGRES_PORT)
|
||||
.withLogRotation()
|
||||
.withLabels(ContainerStorageHelper.resourceIdentityLabels(
|
||||
"mwaa", name, regionResolver.getAccountId(), regionResolver.getDefaultRegion()))
|
||||
.build();
|
||||
|
||||
String dbContainerId = lifecycleManager.create(dbSpec);
|
||||
@@ -169,7 +175,9 @@ public class MwaaEnvironmentManager {
|
||||
.withNamedVolume(dagsVolume, DAGS_MOUNT)
|
||||
.withNamedVolume(logsVolume, LOGS_MOUNT)
|
||||
.withDockerNetwork(config.services().mwaa().dockerNetwork())
|
||||
.withLogRotation();
|
||||
.withLogRotation()
|
||||
.withLabels(ContainerStorageHelper.resourceIdentityLabels(
|
||||
"mwaa", name, regionResolver.getAccountId(), regionResolver.getDefaultRegion()));
|
||||
|
||||
if (!containerDetector.isRunningInContainer()) {
|
||||
specBuilder.withDynamicPort(AIRFLOW_WEBSERVER_PORT);
|
||||
|
||||
+3
-1
@@ -117,7 +117,9 @@ public class NeptuneContainerManager {
|
||||
.withName(containerName)
|
||||
.withEnv(backendEnv(dbType))
|
||||
.withDockerNetwork(config.services().neptune().dockerNetwork())
|
||||
.withLogRotation();
|
||||
.withLogRotation()
|
||||
.withLabels(ContainerStorageHelper.resourceIdentityLabels(
|
||||
"neptune", clusterId, regionResolver.getAccountId(), regionResolver.getDefaultRegion()));
|
||||
|
||||
if (!containerDetector.isRunningInContainer()) {
|
||||
specBuilder.withDynamicPort(backendPort);
|
||||
|
||||
+9
-2
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.opensearch;
|
||||
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerBuilder;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerDetector;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLifecycleManager;
|
||||
@@ -32,18 +33,21 @@ public class OpenSearchDomainManager {
|
||||
private final ContainerDetector containerDetector;
|
||||
private final PortAllocator portAllocator;
|
||||
private final EmulatorConfig config;
|
||||
private final RegionResolver regionResolver;
|
||||
|
||||
@Inject
|
||||
public OpenSearchDomainManager(ContainerBuilder containerBuilder,
|
||||
ContainerLifecycleManager lifecycleManager,
|
||||
ContainerDetector containerDetector,
|
||||
PortAllocator portAllocator,
|
||||
EmulatorConfig config) {
|
||||
EmulatorConfig config,
|
||||
RegionResolver regionResolver) {
|
||||
this.containerBuilder = containerBuilder;
|
||||
this.lifecycleManager = lifecycleManager;
|
||||
this.containerDetector = containerDetector;
|
||||
this.portAllocator = portAllocator;
|
||||
this.config = config;
|
||||
this.regionResolver = regionResolver;
|
||||
}
|
||||
|
||||
public void startDomain(Domain domain) {
|
||||
@@ -64,7 +68,10 @@ public class OpenSearchDomainManager {
|
||||
.withEnv("discovery.type", "single-node")
|
||||
.withPortBinding(OPENSEARCH_PORT, hostPort)
|
||||
.withDockerNetwork(config.services().dockerNetwork())
|
||||
.withLogRotation();
|
||||
.withLogRotation()
|
||||
.withLabels(ContainerStorageHelper.resourceIdentityLabels(
|
||||
"opensearch", domain.getDomainName(), regionResolver.getAccountId(),
|
||||
regionResolver.getDefaultRegion()));
|
||||
|
||||
applyEngineEnv(specBuilder, domain.getEngineVersion());
|
||||
|
||||
|
||||
+37
-21
@@ -130,6 +130,8 @@ public class RdsContainerManager {
|
||||
// Build environment variables
|
||||
List<String> envVars = buildEnvVars(engine, masterUsername, masterPassword, dbName);
|
||||
|
||||
RuntimeIdentity runtimeIdentity = resolveRuntimeIdentity(effectiveRuntimeId);
|
||||
|
||||
// Build container spec with bind mounts for persistence. Publish the
|
||||
// engine port to the host only in native mode; in Docker mode the auth
|
||||
// proxy reaches the DB via the container network.
|
||||
@@ -137,7 +139,9 @@ public class RdsContainerManager {
|
||||
.withName(containerName)
|
||||
.withEnv(envVars)
|
||||
.withDockerNetwork(config.services().rds().dockerNetwork())
|
||||
.withLogRotation();
|
||||
.withLogRotation()
|
||||
.withLabels(ContainerStorageHelper.resourceIdentityLabels(
|
||||
"rds", instanceId, runtimeIdentity.accountId(), runtimeIdentity.region()));
|
||||
|
||||
if (!containerDetector.isRunningInContainer()) {
|
||||
specBuilder.withDynamicPort(enginePort);
|
||||
@@ -179,29 +183,13 @@ public class RdsContainerManager {
|
||||
: info.containerId();
|
||||
String logGroup = "/aws/rds/instance/" + instanceId + "/error";
|
||||
String logStream = logStreamer.generateLogStreamName(shortId);
|
||||
String region = regionResolver.getDefaultRegion();
|
||||
String accountId = null;
|
||||
try {
|
||||
AwsArnUtils.Arn runtimeArn = AwsArnUtils.parse(effectiveRuntimeId);
|
||||
if ("rds".equals(runtimeArn.service())) {
|
||||
if (!runtimeArn.region().isBlank()) {
|
||||
region = runtimeArn.region();
|
||||
}
|
||||
if (!runtimeArn.accountId().isBlank()) {
|
||||
accountId = runtimeArn.accountId();
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
LOG.debugv("Using legacy RDS runtime identity for log routing: {0}",
|
||||
effectiveRuntimeId);
|
||||
}
|
||||
|
||||
Closeable logHandle = accountId != null
|
||||
Closeable logHandle = runtimeIdentity.arnAccountId() != null
|
||||
? logStreamer.attachForAccount(
|
||||
accountId, info.containerId(), logGroup, logStream, region,
|
||||
"rds:" + effectiveRuntimeId)
|
||||
runtimeIdentity.arnAccountId(), info.containerId(), logGroup,
|
||||
logStream, runtimeIdentity.region(), "rds:" + effectiveRuntimeId)
|
||||
: logStreamer.attach(
|
||||
info.containerId(), logGroup, logStream, region,
|
||||
info.containerId(), logGroup, logStream, runtimeIdentity.region(),
|
||||
"rds:" + effectiveRuntimeId);
|
||||
handle.setLogStream(logHandle);
|
||||
activeContainers.put(effectiveRuntimeId, handle);
|
||||
@@ -237,6 +225,34 @@ public class RdsContainerManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the region and account id backing an RDS runtime identity. {@code accountId} is
|
||||
* never blank (falls back to {@link RegionResolver#getAccountId}); {@code arnAccountId} keeps
|
||||
* the pre-existing null-when-absent semantics that log-stream routing depends on to pick
|
||||
* between {@code attach} and {@code attachForAccount}.
|
||||
*/
|
||||
private RuntimeIdentity resolveRuntimeIdentity(String runtimeId) {
|
||||
String region = regionResolver.getDefaultRegion();
|
||||
String arnAccountId = null;
|
||||
try {
|
||||
AwsArnUtils.Arn runtimeArn = AwsArnUtils.parse(runtimeId);
|
||||
if ("rds".equals(runtimeArn.service())) {
|
||||
if (!runtimeArn.region().isBlank()) {
|
||||
region = runtimeArn.region();
|
||||
}
|
||||
if (!runtimeArn.accountId().isBlank()) {
|
||||
arnAccountId = runtimeArn.accountId();
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
LOG.debugv("Using legacy RDS runtime identity for log routing: {0}", runtimeId);
|
||||
}
|
||||
String accountId = arnAccountId != null ? arnAccountId : regionResolver.getAccountId();
|
||||
return new RuntimeIdentity(region, accountId, arnAccountId);
|
||||
}
|
||||
|
||||
private record RuntimeIdentity(String region, String accountId, String arnAccountId) {}
|
||||
|
||||
public void stop(RdsContainerHandle handle) {
|
||||
if (handle == null) {
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user