use of io.strimzi.controller.cluster.operator.resource.ConfigMapOperator in project strimzi by strimzi.
the class KafkaConnectS2IAssemblyOperatorTest method testUpdateClusterScaleUp.
@Test
public void testUpdateClusterScaleUp(TestContext context) {
int scaleTo = 4;
String newReplicas = String.valueOf(scaleTo);
ConfigMapOperator mockCmOps = mock(ConfigMapOperator.class);
ServiceOperator mockServiceOps = mock(ServiceOperator.class);
DeploymentConfigOperator mockDcOps = mock(DeploymentConfigOperator.class);
BuildConfigOperator mockBcOps = mock(BuildConfigOperator.class);
ImageStreamOperator mockIsOps = mock(ImageStreamOperator.class);
String clusterCmName = "foo";
String clusterCmNamespace = "test";
ConfigMap clusterCm = ResourceUtils.createEmptyKafkaConnectS2IClusterConfigMap(clusterCmNamespace, clusterCmName);
KafkaConnectS2ICluster connect = KafkaConnectS2ICluster.fromConfigMap(clusterCm);
// Change replicas to create ScaleUp
clusterCm.getData().put(KafkaConnectCluster.KEY_REPLICAS, newReplicas);
when(mockCmOps.get(clusterCmNamespace, clusterCmName)).thenReturn(clusterCm);
when(mockServiceOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateService());
when(mockDcOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateDeploymentConfig());
when(mockIsOps.get(clusterCmNamespace, connect.getSourceImageStreamName())).thenReturn(connect.generateSourceImageStream());
when(mockIsOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateTargetImageStream());
when(mockBcOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateBuildConfig());
when(mockServiceOps.reconcile(any(), any(), any())).thenReturn(Future.succeededFuture());
when(mockDcOps.reconcile(any(), any(), any())).thenReturn(Future.succeededFuture());
doAnswer(i -> Future.succeededFuture(scaleTo)).when(mockDcOps).scaleUp(clusterCmNamespace, connect.getName(), scaleTo);
doAnswer(i -> Future.succeededFuture(scaleTo)).when(mockDcOps).scaleDown(clusterCmNamespace, connect.getName(), scaleTo);
when(mockIsOps.reconcile(any(), any(), any())).thenReturn(Future.succeededFuture());
when(mockBcOps.reconcile(any(), any(), any())).thenReturn(Future.succeededFuture());
KafkaConnectS2IAssemblyOperator ops = new KafkaConnectS2IAssemblyOperator(vertx, true, mockCmOps, mockDcOps, mockServiceOps, mockIsOps, mockBcOps);
Async async = context.async();
ops.createOrUpdate(new Reconciliation("test-trigger", AssemblyType.CONNECT_S2I, clusterCmNamespace, clusterCmName), clusterCm, createResult -> {
context.assertTrue(createResult.succeeded());
verify(mockDcOps).scaleUp(clusterCmNamespace, connect.getName(), scaleTo);
async.complete();
});
}
use of io.strimzi.controller.cluster.operator.resource.ConfigMapOperator in project strimzi by strimzi.
the class Main method run.
static CompositeFuture run(Vertx vertx, KubernetesClient client, boolean isOpenShift, Map<String, String> env) {
ClusterControllerConfig config = ClusterControllerConfig.fromMap(env);
ServiceOperator serviceOperations = new ServiceOperator(vertx, client);
ZookeeperSetOperator zookeeperSetOperations = new ZookeeperSetOperator(vertx, client);
KafkaSetOperator kafkaSetOperations = new KafkaSetOperator(vertx, client);
ConfigMapOperator configMapOperations = new ConfigMapOperator(vertx, client);
PvcOperator pvcOperations = new PvcOperator(vertx, client);
DeploymentOperator deploymentOperations = new DeploymentOperator(vertx, client);
KafkaAssemblyOperator kafkaClusterOperations = new KafkaAssemblyOperator(vertx, isOpenShift, config.getOperationTimeoutMs(), configMapOperations, serviceOperations, zookeeperSetOperations, kafkaSetOperations, pvcOperations, deploymentOperations);
KafkaConnectAssemblyOperator kafkaConnectClusterOperations = new KafkaConnectAssemblyOperator(vertx, isOpenShift, configMapOperations, deploymentOperations, serviceOperations);
DeploymentConfigOperator deploymentConfigOperations = null;
ImageStreamOperator imagesStreamOperations = null;
BuildConfigOperator buildConfigOperations = null;
KafkaConnectS2IAssemblyOperator kafkaConnectS2IClusterOperations = null;
if (isOpenShift) {
imagesStreamOperations = new ImageStreamOperator(vertx, client.adapt(OpenShiftClient.class));
buildConfigOperations = new BuildConfigOperator(vertx, client.adapt(OpenShiftClient.class));
deploymentConfigOperations = new DeploymentConfigOperator(vertx, client.adapt(OpenShiftClient.class));
kafkaConnectS2IClusterOperations = new KafkaConnectS2IAssemblyOperator(vertx, isOpenShift, configMapOperations, deploymentConfigOperations, serviceOperations, imagesStreamOperations, buildConfigOperations);
}
List<Future> futures = new ArrayList<>();
for (String namespace : config.getNamespaces()) {
Future<String> fut = Future.future();
futures.add(fut);
ClusterController controller = new ClusterController(namespace, config.getReconciliationIntervalMs(), client, kafkaClusterOperations, kafkaConnectClusterOperations, kafkaConnectS2IClusterOperations);
vertx.deployVerticle(controller, res -> {
if (res.succeeded()) {
log.info("Cluster Controller verticle started in namespace {}", namespace);
} else {
log.error("Cluster Controller verticle in namespace {} failed to start", namespace, res.cause());
System.exit(1);
}
fut.completer().handle(res);
});
}
return CompositeFuture.join(futures);
}
Aggregations