fix(ec2,ecr,eks,elasticache,msk,opensearch): degrade gracefully with no Docker daemon (#2975)

* fix(ec2,ecr,eks,elasticache,msk,opensearch): degrade gracefully with no Docker daemon

Extends the daemonless degradation pattern #2386 established for MemoryDB,
Neptune and DocDB to the remaining container-backed services. Create paths
probe the daemon on failure, keep serving metadata, and log the outage once;
a failure with a reachable daemon still propagates.

* fix(opensearch,msk): keep the readiness pollers when the daemon is reachable

Create set the terminal state before the container started, which orphaned the readiness pollers. The terminal state is now set only in mock mode or when the daemon is unreachable, matching EKS. ElastiCache stops a partially created container before degrading to metadata.

* fix(elasticache): fail the create when a container was already started

Degrading to metadata now happens only when no container was created. A failure after creation runs the cleanup and rethrows. The service rollback then runs and no available group is persisted without a container.

* test(elasticache): stub tryStart in the parameter group reservation tests

The three tests from #3023 stubbed start, which createReplicationGroup no longer calls on this branch.
This commit is contained in:
lex00 authored and GitHub committed 2026-09-05 21:01:38 -04:00
1 parent 43e2a48263
commit 1aa981fef2
24 files changed
+900 -47

No files matched your search

@@ -106,6 +106,8 @@ public class Ec2ContainerManager {
private final RegionResolver regionResolver;
private final ContainerNetworkReachability containerNetworkReachability;
private volatile boolean dockerUnavailableLogged;
private final ExecutorService executor = Executors.newCachedThreadPool(r -> {
Thread t = new Thread(r, "ec2-container-launcher");
t.setDaemon(true);
@@ -147,7 +149,8 @@ public class Ec2ContainerManager {
/**
* Launches a Docker container for the given EC2 instance.
* The instance starts in pending state; an async thread transitions it to running
* and handles SSH key injection and UserData execution.
* and handles SSH key injection and UserData execution. With no Docker daemon
* reachable the instance goes straight to running as metadata only.
*
* @param instance the EC2 instance model (mutated in-place as state transitions occur)
* @param dockerImage Docker image URI resolved from the instance's AMI ID
@@ -169,6 +172,16 @@ public class Ec2ContainerManager {
public void launch(Instance instance, ResolvedAmiImage image, String publicKey, String region, Set<Integer> appPorts) {
instance.setState(InstanceState.pending());
// An instance record is metadata: id, addresses, tags and lifecycle state are all
// served without a container runtime. Only the guest itself (SSH, UserData, SSM
// commands) needs Docker, so when no daemon is reachable the instance still runs
// instead of dying: Floci in Docker without a mounted socket, or a stopped daemon
// on the host, would otherwise terminate every instance the moment it launched.
if (!isDockerAvailable()) {
markContainerlessRunning(instance);
return;
}
executor.submit(() -> {
try {
String instanceId = instance.getInstanceId();
@@ -274,7 +287,14 @@ public class Ec2ContainerManager {
failLaunch(instance);
} catch (Exception e) {
LOG.warnv("Failed to launch EC2 instance {0}: {1}", instance.getInstanceId(), e.getMessage());
failLaunch(instance);
// The daemon can disappear between the probe above and any of the calls in
// this block. Losing Docker is not the instance's fault, so degrade to a
// metadata-only instance; a genuine container failure still fails the launch.
if (isDockerAvailable()) {
failLaunch(instance);
} else {
markContainerlessRunning(instance);
}
}
});
}
@@ -486,6 +506,40 @@ public class Ec2ContainerManager {
private record StartedContainer(String containerId, int sshHostPort) {
}
/**
* Reports whether a Docker daemon is reachable, logging the transition in each
* direction once rather than on every launch.
*/
public boolean isDockerAvailable() {
try {
dockerClient.pingCmd().exec();
if (dockerUnavailableLogged) {
dockerUnavailableLogged = false;
LOG.info("Docker daemon is reachable again; new EC2 instances get a backing container.");
}
return true;
} catch (Exception e) {
if (!dockerUnavailableLogged) {
dockerUnavailableLogged = true;
LOG.warnv("No Docker daemon is reachable from Floci ({0}). EC2 instances are emulated as "
+ "metadata only: they reach running and honour stop, start and terminate, but have "
+ "no backing container, so SSH, UserData and SSM command execution stay unavailable "
+ "until a daemon is reachable.", e.getMessage());
}
return false;
}
}
/**
* Brings an instance to running with no container behind it. Stop, start, terminate and
* reboot already handle a null container id, so the rest of the lifecycle keeps working.
*/
private void markContainerlessRunning(Instance instance) {
LOG.infov("EC2 instance {0} is running without a backing container (no Docker daemon reachable)",
instance.getInstanceId());
instance.setState(InstanceState.running());
}
/**
* Synchronous stop for emulator shutdown: tears down the port-forward sidecars and
* stops the container with a short timeout so N instances cannot exhaust the SIGTERM
@@ -3894,7 +3894,10 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
if (instance == null) {
return false;
}
if (config.services().ec2().mock()) {
// Mock mode and instances launched with no Docker daemon reachable have nothing to
// inspect, so the recorded lifecycle state is the answer. Reporting those as not
// running would make AutoScaling replace healthy instances in a loop.
if (config.services().ec2().mock() || instance.getDockerContainerId() == null) {
String state = instance.getState() != null ? instance.getState().getName() : null;
return state == null
|| (!"shutting-down".equals(state) && !"terminated".equals(state) && !"stopping".equals(state));
@@ -121,7 +121,12 @@ public class EcrService implements ResourceProvider {
Map<String, String> tags,
String region) {
validateRepoName(repositoryName);
registryManager.ensureStarted();
// Repository records are pure metadata: the ARN and the URI are derived from the
// configured account, region and registry port, none of which need Docker. Start
// the backing registry opportunistically so the URI reflects an already-adopted
// container's published port, but never fail CreateRepository when no Docker
// daemon is reachable, the registry is retried on the next image operation.
registryManager.tryEnsureStarted();
String account = effectiveAccount(registryId);
String key = key(region, account, repositoryName);
if (repoStore.get(key).isPresent()) {
@@ -220,7 +225,7 @@ public class EcrService implements ResourceProvider {
// ============================================================
public AuthorizationData getAuthorizationToken() {
registryManager.ensureStarted();
requireRegistry();
String token = Base64.getEncoder()
.encodeToString("AWS:floci".getBytes(StandardCharsets.UTF_8));
Instant expires = Instant.now().plusSeconds(12 * 60 * 60);
@@ -234,7 +239,7 @@ public class EcrService implements ResourceProvider {
public List<ImageIdentifier> listImages(String repositoryName, String registryId, String region) {
Repository repo = requireRepo(repositoryName, registryId, region);
registryManager.ensureStarted();
requireRegistry();
String internal = registryManager.internalRepoName(repo.getRegistryId(), region, repositoryName);
try {
RegistryHttpClient http = registryManager.httpClient();
@@ -256,7 +261,7 @@ public class EcrService implements ResourceProvider {
String registryId,
String region) {
Repository repo = requireRepo(repositoryName, registryId, region);
registryManager.ensureStarted();
requireRegistry();
String internal = registryManager.internalRepoName(repo.getRegistryId(), region, repositoryName);
RegistryHttpClient http = registryManager.httpClient();
@@ -331,7 +336,7 @@ public class EcrService implements ResourceProvider {
String registryId,
String region) {
Repository repo = requireRepo(repositoryName, registryId, region);
registryManager.ensureStarted();
requireRegistry();
String internal = registryManager.internalRepoName(repo.getRegistryId(), region, repositoryName);
RegistryHttpClient http = registryManager.httpClient();
@@ -371,7 +376,7 @@ public class EcrService implements ResourceProvider {
String registryId,
String region) {
Repository repo = requireRepo(repositoryName, registryId, region);
registryManager.ensureStarted();
requireRegistry();
String internal = registryManager.internalRepoName(repo.getRegistryId(), region, repositoryName);
RegistryHttpClient http = registryManager.httpClient();
@@ -533,6 +538,20 @@ public class EcrService implements ResourceProvider {
}
/**
* Gate for the ECR data plane, which cannot be emulated without the backing
* registry container. Surfaces ECR's modelled {@code ServerException} instead of
* letting the Docker client's {@code SocketException} escape as an InternalFailure.
*/
private void requireRegistry() {
if (!registryManager.tryEnsureStarted()) {
throw new AwsException("ServerException",
"The ECR backing registry is unavailable because no Docker daemon is reachable "
+ "from Floci. Repository metadata operations are supported; image push, "
+ "pull and image queries require Docker.", 500);
}
}
private List<String> listTagsBestEffort(String account, String region, String repoName) {
try {
return registryManager.httpClient()
@@ -66,6 +66,7 @@ public class EcrRegistryManager {
private volatile boolean started;
private volatile boolean reconciled;
private volatile boolean unavailableLogged;
private volatile int hostPort;
private volatile String containerId;
private volatile Closeable logStream;
@@ -189,6 +190,36 @@ public class EcrRegistryManager {
this.reconcileHook = hook;
}
/**
* Attempts {@link #ensureStarted()} and reports whether the backing registry is
* usable, instead of propagating the failure. Callers that only need repository
* metadata (ARN, URI, tags) use this so ECR's control plane keeps working when
* Floci itself runs inside Docker without access to a Docker daemon; the registry
* is retried on the next call and starts as soon as a daemon becomes reachable.
*
* @return true when the registry container is running
*/
public boolean tryEnsureStarted() {
if (started) {
return true;
}
try {
ensureStarted();
} catch (RuntimeException e) {
if (!unavailableLogged) {
unavailableLogged = true;
LOG.warnv("ECR backing registry is unavailable ({0}). Repository metadata operations "
+ "continue to work; image push, pull and image queries stay disabled until a "
+ "Docker daemon is reachable.", e.getMessage());
}
return false;
}
if (started) {
unavailableLogged = false;
}
return started;
}
/**
* Lazily starts (or reuses) the {@code registry:2} container. Idempotent and
* thread-safe. Throws if Docker is unreachable.
@@ -82,6 +82,45 @@ public class EksClusterManager {
this.regionResolver = regionResolver;
}
/**
* Attempts {@link #startCluster} and reports the k3s backend as unavailable instead of
* propagating the failure, when the cause is that no Docker daemon is reachable from Floci:
* Floci running inside Docker without a mounted socket, or a stopped daemon on the host. A
* failure raised while the daemon <em>is</em> reachable is a genuine provisioning error and
* still propagates, so a cluster only reaches FAILED for a reason AWS would also fail on.
*
* @return true when the k3s container was created and started
*/
public boolean tryStartCluster(Cluster cluster) {
try {
startCluster(cluster);
return true;
} catch (RuntimeException e) {
if (isDockerReachable()) {
throw e;
}
LOG.warnv("No Docker daemon is reachable from Floci ({0}). EKS cluster {1} is created as "
+ "metadata only: describe, list, tag, nodegroups, Fargate profiles and delete "
+ "work, but the cluster has no Kubernetes API server and kubectl cannot connect "
+ "to the endpoint it reports.", e.getMessage(), cluster.getName());
return false;
}
}
/**
* Probes the configured Docker endpoint, which is how a missing daemon is told apart from a
* k3s container that failed for its own reasons.
*/
public boolean isDockerReachable() {
try {
lifecycleManager.getDockerClient().pingCmd().exec();
return true;
} catch (Exception e) {
LOG.debugv("Docker daemon is not reachable: {0}", e.getMessage());
return false;
}
}
/**
* Starts a k3s container for the given cluster. Updates the cluster with
* the container ID and host port. The cluster status remains CREATING until
@@ -137,9 +137,17 @@ public class EksService implements TagHandler, ResourceProvider {
cluster.setStatus(ClusterStatus.CREATING);
clusterManager.restoreCluster(cluster);
} catch (Exception e) {
LOG.errorv("Failed to restore k3s container for EKS cluster {0}: {1}",
cluster.getName(), e.getMessage());
cluster.setStatus(ClusterStatus.FAILED);
if (!clusterManager.isDockerReachable()) {
// Same degradation as create: a restored cluster is metadata that stands on
// its own, and FAILED is reserved for errors AWS would also report.
LOG.warnv("No Docker daemon is reachable from Floci; restored EKS cluster {0} "
+ "comes back as metadata only.", cluster.getName());
markMetadataOnlyActive(cluster);
} else {
LOG.errorv("Failed to restore k3s container for EKS cluster {0}: {1}",
cluster.getName(), e.getMessage());
cluster.setStatus(ClusterStatus.FAILED);
}
}
putClusterForAccount(entry.accountId(), cluster);
}
@@ -251,11 +259,15 @@ public class EksService implements TagHandler, ResourceProvider {
oidcService.ensureKey(name, issuer);
if (config.services().eks().mock()) {
cluster.setStatus(ClusterStatus.ACTIVE);
cluster.setEndpoint("https://localhost:" + config.services().eks().apiServerBasePort());
markMetadataOnlyActive(cluster);
} else {
try {
clusterManager.startCluster(cluster);
if (!clusterManager.tryStartCluster(cluster)) {
// No Docker daemon: the k3s control plane cannot run, but the cluster record is
// metadata that stands on its own. FAILED is reserved for provisioning errors
// AWS would also report, and would strand every IaC apply that polls for ACTIVE.
markMetadataOnlyActive(cluster);
}
} catch (Exception e) {
LOG.errorv("Failed to start k3s container for cluster {0}: {1}", name, e.getMessage());
cluster.setStatus(ClusterStatus.FAILED);
@@ -266,6 +278,17 @@ public class EksService implements TagHandler, ResourceProvider {
return cluster;
}
/**
* Marks a cluster ACTIVE with no Kubernetes API server behind it, the shape used by mock mode
* and by a Floci that cannot reach a Docker daemon. Every EKS API Floci implements is control
* plane (clusters, nodegroups, Fargate profiles, tags) and keeps working; the empty
* certificateAuthority is what tells a caller no real cluster is listening on the endpoint.
*/
private void markMetadataOnlyActive(Cluster cluster) {
cluster.setStatus(ClusterStatus.ACTIVE);
cluster.setEndpoint("https://localhost:" + config.services().eks().apiServerBasePort());
}
public Cluster describeCluster(String name) {
return storage.get(name)
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
@@ -25,6 +25,8 @@ public class ElastiCacheMemcachedService {
private static final Logger LOG = Logger.getLogger(ElastiCacheMemcachedService.class);
private static final String ENGINE = "memcached";
private static final String ENGINE_VERSION = "1.6.22";
/** Memcached's well-known port, used as the endpoint port when no backing container exists. */
private static final int BACKEND_PORT = 11211;
private final StorageBackend<String, CacheCluster> clusters;
private final ElastiCacheMemcachedContainerManager containerManager;
@@ -49,20 +51,30 @@ public class ElastiCacheMemcachedService {
String image = config.services().elasticache().defaultMemcachedImage();
LOG.infov("Creating Memcached cluster {0} with image {1}", clusterId, image);
ElastiCacheContainerHandle handle = containerManager.start(clusterId, image);
// A cache cluster record is metadata: its id and endpoint are derived from configuration,
// so the cluster is created and reaches 'available' even when no Docker daemon is
// reachable. Only connecting to the cache needs the container.
ElastiCacheContainerHandle handle = containerManager.tryStart(clusterId, image);
String endpointHost = resolveEndpointHost(handle);
Endpoint endpoint = new Endpoint(endpointHost, handle.getPort());
int endpointPort = handle != null ? handle.getPort() : BACKEND_PORT;
Endpoint endpoint = new Endpoint(endpointHost, endpointPort);
CacheCluster cluster = new CacheCluster(
clusterId, CacheClusterStatus.AVAILABLE, ENGINE, ENGINE_VERSION,
endpoint, Instant.now());
cluster.setContainerId(handle.getContainerId());
cluster.setContainerHost(handle.getHost());
cluster.setContainerPort(handle.getPort());
if (handle != null) {
cluster.setContainerId(handle.getContainerId());
cluster.setContainerHost(handle.getHost());
cluster.setContainerPort(handle.getPort());
} else {
LOG.warnv("Memcached cluster {0} created without a backing container: no Docker daemon "
+ "is reachable. Metadata operations work; connections to the cache do not "
+ "until a daemon appears.", clusterId);
}
clusters.put(clusterId, cluster);
LOG.infov("Memcached cluster {0} created, endpoint={1}:{2}", clusterId, endpointHost, handle.getPort());
LOG.infov("Memcached cluster {0} created, endpoint={1}:{2}", clusterId, endpointHost, endpointPort);
return cluster;
}
@@ -100,6 +112,6 @@ public class ElastiCacheMemcachedService {
}
private String resolveEndpointHost(ElastiCacheContainerHandle handle) {
return config.hostname().orElse(handle.getHost());
return config.hostname().orElse(handle != null ? handle.getHost() : "localhost");
}
}
@@ -229,16 +229,17 @@ public class ElastiCacheService implements ResourceProvider {
ElastiCacheContainerHandle handle = null;
try {
handle = containerManager.start(groupId, image);
// A replication group record is metadata: its id, endpoint host and proxy port are
// derived from configuration and need no Docker, so the group is created and reaches
// 'available' even when no daemon is reachable. Only connecting to the cache needs
// the container.
handle = containerManager.tryStart(groupId, image);
String endpointHost = resolveEndpointHost();
Endpoint endpoint = new Endpoint(endpointHost, proxyPort);
ReplicationGroup group = new ReplicationGroup(
groupId, request.description(), ReplicationGroupStatus.AVAILABLE,
authMode, endpoint, Instant.now(), proxyPort);
group.setContainerId(handle.getContainerId());
group.setContainerHost(handle.getHost());
group.setContainerPort(handle.getPort());
group.setAuthToken(request.authToken());
group.setArn(regionResolver.buildArn("elasticache", request.region(),
"replicationgroup:" + groupId));
@@ -248,11 +249,23 @@ public class ElastiCacheService implements ResourceProvider {
: 1);
applyCommonAttributes(group, request, resolvedSettings);
if (handle != null) {
group.setContainerId(handle.getContainerId());
group.setContainerHost(handle.getHost());
group.setContainerPort(handle.getPort());
}
synchronized (lockFor("rg:" + groupId)) {
groups.put(groupId, group);
proxyManager.startProxy(groupId, authMode, proxyPort,
handle.getHost(), handle.getPort(),
(username, password) -> validatePassword(groupId, username, password));
if (handle != null) {
proxyManager.startProxy(groupId, authMode, proxyPort,
handle.getHost(), handle.getPort(),
(username, password) -> validatePassword(groupId, username, password));
} else {
LOG.warnv("Replication group {0} created without a backing cache container: no "
+ "Docker daemon is reachable. Metadata operations work; connections to "
+ "the cache do not until a daemon appears.", groupId);
}
}
LOG.infov("Replication group {0} created, endpoint={1}:{2}", groupId, endpointHost, String.valueOf(proxyPort));
@@ -53,6 +53,7 @@ public class ElastiCacheContainerManager {
private final EmulatorConfig config;
private final RegionResolver regionResolver;
private final Map<String, ElastiCacheContainerHandle> activeContainers = new ConcurrentHashMap<>();
private volatile boolean dockerUnavailableLogged;
@Inject
public ElastiCacheContainerManager(ContainerBuilder containerBuilder,
@@ -69,6 +70,55 @@ public class ElastiCacheContainerManager {
this.regionResolver = regionResolver;
}
/**
* Attempts {@link #start} and reports the backend as unavailable instead of propagating the
* failure, when the cause is that no Docker daemon is reachable from Floci: Floci running
* inside Docker without a mounted socket, or a stopped daemon on the host. A failure raised
* while the daemon <em>is</em> reachable is a genuine container problem and still propagates,
* so nothing changes for a Floci that can start Valkey containers.
*
* @return the container handle, or {@code null} when no Docker daemon is reachable and no
* container was created
*/
public ElastiCacheContainerHandle tryStart(String groupId, String image) {
try {
ElastiCacheContainerHandle handle = start(groupId, image);
dockerUnavailableLogged = false;
return handle;
} catch (RuntimeException e) {
if (isDockerReachable()) {
throw e;
}
boolean partial = activeContainers.containsKey(groupId);
stopByGroupId(groupId);
if (partial) {
throw e;
}
if (!dockerUnavailableLogged) {
dockerUnavailableLogged = true;
LOG.warnv("No Docker daemon is reachable from Floci ({0}). ElastiCache metadata "
+ "operations keep working and replication groups still reach 'available', "
+ "but they have no backing Valkey container until a daemon becomes "
+ "reachable.", e.getMessage());
}
return null;
}
}
/**
* Probes the configured Docker endpoint, which is how a missing daemon is told apart from a
* container that failed for its own reasons.
*/
public boolean isDockerReachable() {
try {
lifecycleManager.getDockerClient().pingCmd().exec();
return true;
} catch (Exception e) {
LOG.debugv("Docker daemon is not reachable: {0}", e.getMessage());
return false;
}
}
public ElastiCacheContainerHandle start(String groupId, String image) {
return start(groupId, image, List.of());
}
@@ -49,6 +49,7 @@ public class ElastiCacheMemcachedContainerManager {
private final EmulatorConfig config;
private final RegionResolver regionResolver;
private final Map<String, ElastiCacheContainerHandle> activeContainers = new ConcurrentHashMap<>();
private volatile boolean dockerUnavailableLogged;
@Inject
public ElastiCacheMemcachedContainerManager(ContainerBuilder containerBuilder,
@@ -65,6 +66,55 @@ public class ElastiCacheMemcachedContainerManager {
this.regionResolver = regionResolver;
}
/**
* Attempts {@link #start} and reports the backend as unavailable instead of propagating the
* failure, when the cause is that no Docker daemon is reachable from Floci: Floci running
* inside Docker without a mounted socket, or a stopped daemon on the host. A failure raised
* while the daemon <em>is</em> reachable is a genuine container problem and still propagates,
* so nothing changes for a Floci that can start Memcached containers.
*
* @return the container handle, or {@code null} when no Docker daemon is reachable and no
* container was created
*/
public ElastiCacheContainerHandle tryStart(String clusterId, String image) {
try {
ElastiCacheContainerHandle handle = start(clusterId, image);
dockerUnavailableLogged = false;
return handle;
} catch (RuntimeException e) {
if (isDockerReachable()) {
throw e;
}
ElastiCacheContainerHandle partial = activeContainers.get(clusterId);
if (partial != null) {
stop(partial);
throw e;
}
if (!dockerUnavailableLogged) {
dockerUnavailableLogged = true;
LOG.warnv("No Docker daemon is reachable from Floci ({0}). ElastiCache metadata "
+ "operations keep working and cache clusters still reach 'available', but "
+ "they have no backing Memcached container until a daemon becomes "
+ "reachable.", e.getMessage());
}
return null;
}
}
/**
* Probes the configured Docker endpoint, which is how a missing daemon is told apart from a
* container that failed for its own reasons.
*/
public boolean isDockerReachable() {
try {
lifecycleManager.getDockerClient().pingCmd().exec();
return true;
} catch (Exception e) {
LOG.debugv("Docker daemon is not reachable: {0}", e.getMessage());
return false;
}
}
public ElastiCacheContainerHandle start(String clusterId, String image) {
LOG.infov("Starting Memcached container for cluster: {0}", clusterId);
@@ -162,8 +162,12 @@ public class MskService implements ResourceProvider {
if (config.services().msk().mock()) {
cluster.setState(ClusterState.ACTIVE);
cluster.setBootstrapBrokers("localhost:9092");
} else {
redpandaManager.startContainer(cluster);
} else if (!redpandaManager.tryStartContainer(cluster)) {
LOG.warnv("MSK cluster {0} created without a backing Kafka broker: no Docker daemon "
+ "is reachable. Metadata operations work; producing and consuming do not "
+ "until a daemon appears.", clusterName);
cluster.setState(ClusterState.ACTIVE);
cluster.setBootstrapBrokers("localhost:9092");
}
storage.put(clusterArn, cluster);
@@ -43,6 +43,7 @@ public class RedpandaManager {
private final RegionResolver regionResolver;
private final PortAllocator portAllocator;
private final Map<String, Closeable> logStreams = new ConcurrentHashMap<>();
private volatile boolean dockerUnavailableLogged;
@Inject
public RedpandaManager(ContainerBuilder containerBuilder,
@@ -61,6 +62,49 @@ public class RedpandaManager {
this.portAllocator = portAllocator;
}
/**
* Attempts {@link #startContainer} and reports the broker as unavailable instead of
* propagating the failure, when the cause is that no Docker daemon is reachable from Floci:
* Floci running inside Docker without a mounted socket, or a stopped daemon on the host. A
* failure raised while the daemon <em>is</em> reachable is a genuine container problem and
* still propagates, so nothing changes for a Floci that can start Redpanda containers.
*
* @return {@code true} when the container started, {@code false} when no Docker daemon is
* reachable
*/
public boolean tryStartContainer(MskCluster cluster) {
try {
startContainer(cluster);
dockerUnavailableLogged = false;
return true;
} catch (RuntimeException e) {
if (isDockerReachable()) {
throw e;
}
if (!dockerUnavailableLogged) {
dockerUnavailableLogged = true;
LOG.warnv("No Docker daemon is reachable from Floci ({0}). MSK metadata operations "
+ "keep working and clusters still reach ACTIVE, but they have no backing "
+ "Kafka broker until a daemon becomes reachable.", e.getMessage());
}
return false;
}
}
/**
* Probes the configured Docker endpoint, which is how a missing daemon is told apart from a
* container that failed for its own reasons.
*/
public boolean isDockerReachable() {
try {
lifecycleManager.getDockerClient().pingCmd().exec();
return true;
} catch (Exception e) {
LOG.debugv("Docker daemon is not reachable: {0}", e.getMessage());
return false;
}
}
public void startContainer(MskCluster cluster) {
String image = config.services().msk().defaultImage();
LOG.infov("Starting Redpanda container for MSK cluster: {0} using image {1}", cluster.getClusterName(), image);
@@ -34,6 +34,7 @@ public class OpenSearchDomainManager {
private final ContainerDetector containerDetector;
private final PortAllocator portAllocator;
private final EmulatorConfig config;
private volatile boolean dockerUnavailableLogged;
private final RegionResolver regionResolver;
@Inject
@@ -51,6 +52,50 @@ public class OpenSearchDomainManager {
this.regionResolver = regionResolver;
}
/**
* Attempts {@link #startDomain} and reports the backend as unavailable instead of propagating
* the failure, when the cause is that no Docker daemon is reachable from Floci: Floci running
* inside Docker without a mounted socket, or a stopped daemon on the host. A failure raised
* while the daemon <em>is</em> reachable is a genuine container problem and still propagates,
* so nothing changes for a Floci that can start OpenSearch containers.
*
* @return {@code true} when the container started, {@code false} when no Docker daemon is
* reachable
*/
public boolean tryStartDomain(Domain domain) {
try {
startDomain(domain);
dockerUnavailableLogged = false;
return true;
} catch (RuntimeException e) {
if (isDockerReachable()) {
throw e;
}
if (!dockerUnavailableLogged) {
dockerUnavailableLogged = true;
LOG.warnv("No Docker daemon is reachable from Floci ({0}). OpenSearch metadata "
+ "operations keep working and domains still report Processing=false, but "
+ "they have no backing search container until a daemon becomes reachable.",
e.getMessage());
}
return false;
}
}
/**
* Probes the configured Docker endpoint, which is how a missing daemon is told apart from a
* container that failed for its own reasons.
*/
public boolean isDockerReachable() {
try {
lifecycleManager.getDockerClient().pingCmd().exec();
return true;
} catch (Exception e) {
LOG.debugv("Docker daemon is not reachable: {0}", e.getMessage());
return false;
}
}
public void startDomain(Domain domain) {
String image = resolveImage(domain.getEngineVersion());
String containerName = containerName(domain);
@@ -146,7 +146,9 @@ public class OpenSearchService implements ResourceProvider {
domain.setProcessing(false);
} else {
domain.setProcessing(true);
domainManager.startDomain(domain);
if (!domainManager.tryStartDomain(domain)) {
domain.setProcessing(false);
}
}
domainStore.put(domainName, domain);