mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
fix(msk): create a serverless cluster without Docker as a provisioned one is (#5808)
This commit is contained in:
1 parent
c67a5afbc3
commit
9cd8b32670
3 files changed
+58
-16
No files matched your search
@@ -167,16 +167,7 @@ public class MskService implements ResourceProvider {
|
||||
cluster.getCurrentBrokerSoftwareInfo().setConfigurationRevision(configurationInfo.getRevision());
|
||||
}
|
||||
|
||||
if (config.services().msk().mock()) {
|
||||
cluster.setState(ClusterState.ACTIVE);
|
||||
cluster.setBootstrapBrokers("localhost:9092");
|
||||
} 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");
|
||||
}
|
||||
startBroker(cluster);
|
||||
|
||||
storage.put(clusterArn, cluster);
|
||||
return cluster;
|
||||
@@ -220,6 +211,19 @@ public class MskService implements ResourceProvider {
|
||||
return createCluster(merged);
|
||||
}
|
||||
|
||||
private void startBroker(MskCluster cluster) {
|
||||
if (config.services().msk().mock()) {
|
||||
cluster.setState(ClusterState.ACTIVE);
|
||||
cluster.setBootstrapBrokers("localhost:9092");
|
||||
} 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.", cluster.getClusterName());
|
||||
cluster.setState(ClusterState.ACTIVE);
|
||||
cluster.setBootstrapBrokers("localhost:9092");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rejects the CreateCluster input AWS rejects.
|
||||
*
|
||||
@@ -360,12 +364,7 @@ public class MskService implements ResourceProvider {
|
||||
cluster.setZookeeperConnectString(null);
|
||||
cluster.setCurrentBrokerSoftwareInfo(null);
|
||||
|
||||
if (config.services().msk().mock()) {
|
||||
cluster.setState(ClusterState.ACTIVE);
|
||||
cluster.setBootstrapBrokers("localhost:9092");
|
||||
} else {
|
||||
redpandaManager.startContainer(cluster);
|
||||
}
|
||||
startBroker(cluster);
|
||||
|
||||
storage.put(clusterArn, cluster);
|
||||
return cluster;
|
||||
|
||||
@@ -1024,4 +1024,25 @@ class MskServiceTest {
|
||||
|
||||
assertThrows(AwsException.class, () -> mskService.createCluster(request));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createServerlessClusterWithoutDockerDaemonStillReachesActive() {
|
||||
when(config.services().msk().mock()).thenReturn(false);
|
||||
Mockito.doThrow(new RuntimeException("Cannot connect to the Docker daemon"))
|
||||
.when(redpandaManager).startContainer(Mockito.any());
|
||||
when(redpandaManager.tryStartContainer(Mockito.any())).thenReturn(false);
|
||||
|
||||
Serverless serverless = new Serverless();
|
||||
serverless.setVpcConfigs(List.of(new VpcConfig()));
|
||||
CreateClusterV2Request request = new CreateClusterV2Request();
|
||||
request.setClusterName("no-docker-serverless");
|
||||
request.setServerless(serverless);
|
||||
|
||||
MskCluster cluster = mskService.createCluster(request);
|
||||
|
||||
assertEquals(ClusterState.ACTIVE, cluster.getState());
|
||||
assertEquals("localhost:9092", cluster.getBootstrapBrokers());
|
||||
assertEquals(ClusterState.ACTIVE,
|
||||
mskService.describeCluster(cluster.getClusterArn()).getState());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.github.hectorvent.floci.services.msk;
|
||||
|
||||
import com.github.dockerjava.api.DockerClient;
|
||||
import com.github.dockerjava.api.exception.NotFoundException;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
@@ -358,6 +359,27 @@ class RedpandaManagerTest {
|
||||
verify(lifecycleManager, never()).createAndStart(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tryStartContainerReportsUnavailableWhenNoDaemonAnswers() {
|
||||
when(lifecycleManager.createAndStart(any()))
|
||||
.thenThrow(new RuntimeException("java.net.SocketException: No such file or directory"));
|
||||
when(lifecycleManager.getDockerClient())
|
||||
.thenThrow(new RuntimeException("java.net.SocketException: No such file or directory"));
|
||||
|
||||
assertFalse(manager.tryStartContainer(newCluster()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tryStartContainerPropagatesFailuresWhileTheDaemonIsReachable() {
|
||||
when(lifecycleManager.createAndStart(any()))
|
||||
.thenThrow(new RuntimeException("no such image: redpandadata/redpanda:latest"));
|
||||
when(lifecycleManager.getDockerClient()).thenReturn(mock(DockerClient.class, RETURNS_DEEP_STUBS));
|
||||
|
||||
RuntimeException failure = assertThrows(RuntimeException.class,
|
||||
() -> manager.tryStartContainer(newCluster()));
|
||||
assertEquals("no such image: redpandadata/redpanda:latest", failure.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void movesToTheNextHostPortWhenDockerReportsTheChosenOneInUse() {
|
||||
// From inside a container, allocate() cannot see a host process holding a port, so the
|
||||
|
||||
Reference in new issue
Block a user