mirror of
https://github.com/floci-io/floci.git
synced 2026-11-28 08:09:43 -05:00
fix(docker): adopt a surviving container on the network it was created on (#5811)
When Floci runs in Docker, a sidecar it creates that publishes ports (a k3s node, the ECR registry, a Redshift engine, the Floci UI, the AppSync JS runtime) starts on the default bridge and is then connected to its service's network. createAndStart resolves the endpoint on that network. Adopting a surviving container after a restart took the first address in Docker's inspect response instead, which in practice is usually the bridge, and Floci is not on the bridge. Every probe of the adopted container failed; an EKS cluster stayed CREATING. ContainerLifecycleManager.adopt gains an overload that takes the network to prefer and resolves each endpoint with resolveEndpoint(inspect, port, network). Each caller passes the network it creates its container on, through ContainerBuilder.resolveDockerNetwork with the argument it gives withDockerNetwork. A survivor that is not on that network falls back to the first address, as before; the two-argument adopt is unchanged. Co-authored-by: Robin Baeckman <27041454+RobinBaeckman@users.noreply.github.com>
This commit is contained in:
1 parent
a7df271bb3
commit
dfeb05a400
12 files changed
+192
-35
No files matched your search
+10
-1
@@ -939,6 +939,15 @@ public class ContainerLifecycleManager {
|
||||
* @return information about the adopted container
|
||||
*/
|
||||
public ContainerInfo adopt(String containerId, List<Integer> ports) {
|
||||
return adopt(containerId, ports, Optional.empty());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adopts a container and resolves its endpoints on {@code preferredNetwork} when it is attached
|
||||
* there, as {@link #createAndStart} does with the spec's network. A container that is on the
|
||||
* default bridge as well as that network is otherwise reached at whichever address comes first.
|
||||
*/
|
||||
public ContainerInfo adopt(String containerId, List<Integer> ports, Optional<String> preferredNetwork) {
|
||||
LOG.infov("Adopting existing container {0}", containerId);
|
||||
|
||||
InspectContainerResponse inspect = dockerClient.inspectContainerCmd(containerId).exec();
|
||||
@@ -953,7 +962,7 @@ public class ContainerLifecycleManager {
|
||||
Map<Integer, EndpointInfo> endpoints = new HashMap<>();
|
||||
Map<Integer, Integer> publishedHostPorts = new HashMap<>();
|
||||
for (int port : ports) {
|
||||
endpoints.put(port, resolveEndpoint(inspect, port));
|
||||
endpoints.put(port, resolveEndpoint(inspect, port, preferredNetwork.orElse(null)));
|
||||
OptionalInt published = readPublishedHostPort(inspect, port);
|
||||
if (published.isPresent()) {
|
||||
publishedHostPorts.put(port, published.getAsInt());
|
||||
|
||||
+2
-1
@@ -215,7 +215,8 @@ public class NodeAppSyncJsRuntime implements AppSyncJsRuntime, ContainerTeardown
|
||||
}
|
||||
try {
|
||||
this.containerId = existing.getId();
|
||||
ContainerInfo info = lifecycleManager.adopt(containerId, List.of(CONTAINER_INTERNAL_PORT));
|
||||
ContainerInfo info = lifecycleManager.adopt(containerId, List.of(CONTAINER_INTERNAL_PORT),
|
||||
containerBuilder.resolveDockerNetwork(jsRuntimeConfig().dockerNetwork()));
|
||||
this.baseUrl = endpointUrl(info.getEndpoint(CONTAINER_INTERNAL_PORT));
|
||||
awaitHealthy(ADOPT_PROBE_SECONDS);
|
||||
this.started = true;
|
||||
|
||||
+2
-1
@@ -628,7 +628,8 @@ public class EcrRegistryManager {
|
||||
private void adoptExisting(Container existing) {
|
||||
this.containerId = existing.getId();
|
||||
try {
|
||||
ContainerInfo info = lifecycleManager.adopt(containerId, List.of(CONTAINER_INTERNAL_PORT));
|
||||
ContainerInfo info = lifecycleManager.adopt(containerId, List.of(CONTAINER_INTERNAL_PORT),
|
||||
containerBuilder.resolveDockerNetwork(resolveRegistryDockerNetwork()));
|
||||
// The control plane reaches the backing registry through this published loopback
|
||||
// binding when Floci runs on the host. In Docker, httpClient() uses container DNS.
|
||||
OptionalInt published = info.publishedHostPort(CONTAINER_INTERNAL_PORT);
|
||||
|
||||
@@ -807,7 +807,8 @@ public class EksClusterManager
|
||||
|
||||
ContainerInfo info;
|
||||
try {
|
||||
info = lifecycleManager.adopt(containerId, List.of(K3S_API_SERVER_PORT));
|
||||
info = lifecycleManager.adopt(containerId, List.of(K3S_API_SERVER_PORT),
|
||||
containerBuilder.resolveDockerNetwork(config.services().eks().dockerNetwork()));
|
||||
} catch (Exception e) {
|
||||
LOG.warnv("Could not adopt surviving k3s container {0} for EKS cluster {1} ({2}); recreating it",
|
||||
cluster.getDockerName(), cluster.getName(), e.getMessage());
|
||||
|
||||
@@ -779,7 +779,8 @@ public class FlociUiManager {
|
||||
this.containerId = existing.getId();
|
||||
try {
|
||||
int internalPort = profile.internalPort();
|
||||
ContainerInfo info = lifecycleManager.adopt(containerId, List.of(internalPort));
|
||||
ContainerInfo info = lifecycleManager.adopt(containerId, List.of(internalPort),
|
||||
containerBuilder.resolveDockerNetwork(resolveDockerNetwork()));
|
||||
EndpointInfo endpoint = info.getEndpoint(internalPort);
|
||||
this.hostPort = resolveHostPort(endpoint, config.services().ui().port());
|
||||
this.probeUrl = resolveProbeUrl(profile, endpoint, hostPort);
|
||||
|
||||
+2
-1
@@ -127,7 +127,8 @@ public class RedshiftContainerManager {
|
||||
LOG.infov("Adopting existing container {0} for cluster {1} to avoid discarding its data",
|
||||
containerName, clusterIdentifier);
|
||||
int enginePort = 5432;
|
||||
ContainerInfo info = lifecycleManager.adopt(existing.get().getId(), List.of(enginePort));
|
||||
ContainerInfo info = lifecycleManager.adopt(existing.get().getId(), List.of(enginePort),
|
||||
containerBuilder.resolveDockerNetwork(config.services().redshift().dockerNetwork()));
|
||||
return initializeAndRegisterHandle(info, accountId, clusterIdentifier, masterUsername, containerName, enginePort,
|
||||
databaseName);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user