mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(eks): replace a surviving k3s container left on another Docker network (#6063)
When Floci runs in a container and restarts on a different Docker network (FLOCI_SERVICES_DOCKER_NETWORK changed, or Floci moved from host networking to a bridge), restoreCluster adopted the surviving k3s container where it was. Docker isolates bridge networks from each other, so Floci could not reach the API server, the readiness poller never marked the cluster ACTIVE, and every add-on, access entry and access policy call kept failing with "Cluster must be ACTIVE". A survivor that is not on the network Floci now starts clusters on is replaced, the way a survivor whose node capacity changed already is: the data volume is kept, so the workloads come back. Floci on the host reaches k3s through the published port, so there a survivor is kept wherever it is. Co-authored-by: Robin Baeckman <27041454+RobinBaeckman@users.noreply.github.com>
This commit is contained in:
1 parent
47f570a821
commit
aeb798939b
2 files changed
+90
-9
No files matched your search
@@ -492,6 +492,7 @@ class EksClusterManagerTest {
|
||||
private PortAllocator portAllocator;
|
||||
private DockerClient dockerClient;
|
||||
private ContainerBuilder containerBuilder;
|
||||
private ContainerDetector containerDetector;
|
||||
private EksClusterManager manager;
|
||||
|
||||
@BeforeEach
|
||||
@@ -521,8 +522,9 @@ class EksClusterManagerTest {
|
||||
dockerClient = Mockito.mock(DockerClient.class, Mockito.RETURNS_DEEP_STUBS);
|
||||
when(lifecycleManager.getDockerClient()).thenReturn(dockerClient);
|
||||
|
||||
containerDetector = Mockito.mock(ContainerDetector.class);
|
||||
manager = new EksClusterManager(containerBuilder, lifecycleManager,
|
||||
Mockito.mock(ContainerDetector.class), portAllocator,
|
||||
containerDetector, portAllocator,
|
||||
Mockito.mock(DockerHostResolver.class), Mockito.mock(EcrRegistryManager.class),
|
||||
config, Mockito.mock(RegionResolver.class));
|
||||
}
|
||||
@@ -642,6 +644,64 @@ class EksClusterManagerTest {
|
||||
assertEquals(Boolean.FALSE, cluster.getDefaultStorageClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
void replacesASurvivorLeftOnANetworkFlociNoLongerUses() {
|
||||
when(containerDetector.isRunningInContainer()).thenReturn(true);
|
||||
restoreSurvivorOn("\"bridge\":{\"IPAddress\":\"172.17.0.3\"}");
|
||||
stubFreshStart("cid-new", 6440);
|
||||
|
||||
Cluster cluster = cluster();
|
||||
manager.restoreCluster(cluster);
|
||||
|
||||
assertEquals("cid-new", cluster.getContainerId());
|
||||
verify(dockerClient).stopContainerCmd("cid-old");
|
||||
}
|
||||
|
||||
@Test
|
||||
void keepsASurvivorOnTheNetworkFlociUsesBesideTheDefaultBridge() {
|
||||
when(containerDetector.isRunningInContainer()).thenReturn(true);
|
||||
restoreSurvivorOn("\"bridge\":{\"IPAddress\":\"172.17.0.3\"},"
|
||||
+ "\"floci_default\":{\"IPAddress\":\"172.18.0.4\"}");
|
||||
|
||||
Cluster cluster = cluster();
|
||||
manager.restoreCluster(cluster);
|
||||
|
||||
assertEquals("cid-old", cluster.getContainerId());
|
||||
verify(lifecycleManager, never()).create(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void keepsASurvivorThatReportsNoNetworks() {
|
||||
when(containerDetector.isRunningInContainer()).thenReturn(true);
|
||||
restoreSurvivorOn("");
|
||||
|
||||
Cluster cluster = cluster();
|
||||
manager.restoreCluster(cluster);
|
||||
|
||||
assertEquals("cid-old", cluster.getContainerId());
|
||||
verify(lifecycleManager, never()).create(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void keepsASurvivorOnAnotherNetworkWhenFlociRunsOnTheHost() {
|
||||
restoreSurvivorOn("\"bridge\":{\"IPAddress\":\"172.17.0.3\"}");
|
||||
|
||||
Cluster cluster = cluster();
|
||||
manager.restoreCluster(cluster);
|
||||
|
||||
assertEquals("cid-old", cluster.getContainerId());
|
||||
verify(lifecycleManager, never()).create(any());
|
||||
}
|
||||
|
||||
private void restoreSurvivorOn(String networks) {
|
||||
when(containerBuilder.resolveDockerNetwork(Optional.empty())).thenReturn(Optional.of("floci_default"));
|
||||
when(lifecycleManager.findByName("floci-eks-demo")).thenReturn(Optional.of(containerFromJson(
|
||||
"{\"Id\":\"cid-old\",\"Labels\":{\"io.floci.eks.node-capacity\":\"m5.large:unbounded\"},"
|
||||
+ "\"NetworkSettings\":{\"Networks\":{" + networks + "}}}")));
|
||||
when(lifecycleManager.adopt(eq("cid-old"), eq(List.of(6443)), any()))
|
||||
.thenReturn(new ContainerInfo("cid-old", Map.of(), Map.of(6443, 6440)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void recreatesAnOldSurvivorWithoutCapacityLimits() {
|
||||
when(lifecycleManager.findByName("floci-eks-demo"))
|
||||
|
||||
Reference in new issue
Block a user