Search in sources :

Example 21 with ConfigMapOperator

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();
    });
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) KafkaConnectS2ICluster(io.strimzi.controller.cluster.model.KafkaConnectS2ICluster) BuildConfigOperator(io.strimzi.controller.cluster.operator.resource.BuildConfigOperator) ImageStreamOperator(io.strimzi.controller.cluster.operator.resource.ImageStreamOperator) Async(io.vertx.ext.unit.Async) Reconciliation(io.strimzi.controller.cluster.Reconciliation) ConfigMapOperator(io.strimzi.controller.cluster.operator.resource.ConfigMapOperator) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DeploymentConfigOperator(io.strimzi.controller.cluster.operator.resource.DeploymentConfigOperator) ServiceOperator(io.strimzi.controller.cluster.operator.resource.ServiceOperator) Test(org.junit.Test)

Example 22 with ConfigMapOperator

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);
}
Also used : KafkaAssemblyOperator(io.strimzi.controller.cluster.operator.assembly.KafkaAssemblyOperator) ZookeeperSetOperator(io.strimzi.controller.cluster.operator.resource.ZookeeperSetOperator) KafkaConnectS2IAssemblyOperator(io.strimzi.controller.cluster.operator.assembly.KafkaConnectS2IAssemblyOperator) ArrayList(java.util.ArrayList) PvcOperator(io.strimzi.controller.cluster.operator.resource.PvcOperator) ServiceOperator(io.strimzi.controller.cluster.operator.resource.ServiceOperator) KafkaConnectAssemblyOperator(io.strimzi.controller.cluster.operator.assembly.KafkaConnectAssemblyOperator) ImageStreamOperator(io.strimzi.controller.cluster.operator.resource.ImageStreamOperator) BuildConfigOperator(io.strimzi.controller.cluster.operator.resource.BuildConfigOperator) KafkaSetOperator(io.strimzi.controller.cluster.operator.resource.KafkaSetOperator) CompositeFuture(io.vertx.core.CompositeFuture) Future(io.vertx.core.Future) ConfigMapOperator(io.strimzi.controller.cluster.operator.resource.ConfigMapOperator) DeploymentOperator(io.strimzi.controller.cluster.operator.resource.DeploymentOperator) DeploymentConfigOperator(io.strimzi.controller.cluster.operator.resource.DeploymentConfigOperator)

Aggregations

ConfigMapOperator (io.strimzi.controller.cluster.operator.resource.ConfigMapOperator)22 ServiceOperator (io.strimzi.controller.cluster.operator.resource.ServiceOperator)22 Reconciliation (io.strimzi.controller.cluster.Reconciliation)21 Async (io.vertx.ext.unit.Async)21 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)20 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)17 Test (org.junit.Test)17 DeploymentOperator (io.strimzi.controller.cluster.operator.resource.DeploymentOperator)14 Service (io.fabric8.kubernetes.api.model.Service)9 BuildConfigOperator (io.strimzi.controller.cluster.operator.resource.BuildConfigOperator)9 DeploymentConfigOperator (io.strimzi.controller.cluster.operator.resource.DeploymentConfigOperator)9 ImageStreamOperator (io.strimzi.controller.cluster.operator.resource.ImageStreamOperator)9 KafkaConnectCluster (io.strimzi.controller.cluster.model.KafkaConnectCluster)7 KafkaConnectS2ICluster (io.strimzi.controller.cluster.model.KafkaConnectS2ICluster)7 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)6 KafkaSetOperator (io.strimzi.controller.cluster.operator.resource.KafkaSetOperator)6 PvcOperator (io.strimzi.controller.cluster.operator.resource.PvcOperator)6 ZookeeperSetOperator (io.strimzi.controller.cluster.operator.resource.ZookeeperSetOperator)6 HashSet (java.util.HashSet)5 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)4