Search in sources :

Example 6 with BuildConfigOperator

use of io.strimzi.controller.cluster.operator.resource.BuildConfigOperator in project strimzi by strimzi.

the class KafkaConnectS2IAssemblyOperatorTest method testReconcile.

@Test
public void testReconcile(TestContext context) {
    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 clusterCmNamespace = "test";
    ConfigMap foo = ResourceUtils.createEmptyKafkaConnectClusterConfigMap(clusterCmNamespace, "foo");
    ConfigMap bar = ResourceUtils.createEmptyKafkaConnectClusterConfigMap(clusterCmNamespace, "bar");
    ConfigMap baz = ResourceUtils.createEmptyKafkaConnectClusterConfigMap(clusterCmNamespace, "baz");
    when(mockCmOps.list(eq(clusterCmNamespace), any())).thenReturn(asList(foo, bar));
    // when requested ConfigMap for a specific Kafka Connect S2I cluster
    when(mockCmOps.get(eq(clusterCmNamespace), eq("foo"))).thenReturn(foo);
    when(mockCmOps.get(eq(clusterCmNamespace), eq("bar"))).thenReturn(bar);
    // providing the list of ALL DeploymentConfigs for all the Kafka Connect S2I clusters
    Labels newLabels = Labels.forType(AssemblyType.CONNECT_S2I);
    when(mockDcOps.list(eq(clusterCmNamespace), eq(newLabels))).thenReturn(asList(KafkaConnectS2ICluster.fromConfigMap(bar).generateDeploymentConfig(), KafkaConnectS2ICluster.fromConfigMap(baz).generateDeploymentConfig()));
    // providing the list DeploymentConfigs for already "existing" Kafka Connect S2I clusters
    Labels barLabels = Labels.forCluster("bar");
    when(mockDcOps.list(eq(clusterCmNamespace), eq(barLabels))).thenReturn(asList(KafkaConnectS2ICluster.fromConfigMap(bar).generateDeploymentConfig()));
    Labels bazLabels = Labels.forCluster("baz");
    when(mockDcOps.list(eq(clusterCmNamespace), eq(bazLabels))).thenReturn(asList(KafkaConnectS2ICluster.fromConfigMap(baz).generateDeploymentConfig()));
    Set<String> createdOrUpdated = new HashSet<>();
    Set<String> deleted = new HashSet<>();
    Async async = context.async(3);
    KafkaConnectS2IAssemblyOperator ops = new KafkaConnectS2IAssemblyOperator(vertx, true, mockCmOps, mockDcOps, mockServiceOps, mockIsOps, mockBcOps) {

        @Override
        public void createOrUpdate(Reconciliation reconciliation, ConfigMap assemblyCm, Handler h) {
            createdOrUpdated.add(assemblyCm.getMetadata().getName());
            async.countDown();
            h.handle(Future.succeededFuture());
        }

        @Override
        public void delete(Reconciliation reconciliation, Handler h) {
            deleted.add(reconciliation.assemblyName());
            async.countDown();
            h.handle(Future.succeededFuture());
        }
    };
    // Now try to reconcile all the Kafka Connect S2I clusters
    ops.reconcileAll("test", clusterCmNamespace, Labels.EMPTY);
    async.await();
    context.assertEquals(new HashSet(asList("foo", "bar")), createdOrUpdated);
    context.assertEquals(singleton("baz"), deleted);
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Handler(io.vertx.core.Handler) Labels(io.strimzi.controller.cluster.model.Labels) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ServiceOperator(io.strimzi.controller.cluster.operator.resource.ServiceOperator) 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) DeploymentConfigOperator(io.strimzi.controller.cluster.operator.resource.DeploymentConfigOperator) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with BuildConfigOperator

use of io.strimzi.controller.cluster.operator.resource.BuildConfigOperator in project strimzi by strimzi.

the class KafkaConnectS2IAssemblyOperatorTest method testDeleteCluster.

@Test
public void testDeleteCluster(TestContext context) {
    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";
    KafkaConnectS2ICluster connect = KafkaConnectS2ICluster.fromConfigMap(ResourceUtils.createEmptyKafkaConnectS2IClusterConfigMap(clusterCmNamespace, clusterCmName));
    when(mockDcOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateDeploymentConfig());
    when(mockIsOps.get(clusterCmNamespace, connect.getSourceImageStreamName())).thenReturn(connect.generateSourceImageStream());
    ArgumentCaptor<String> serviceNamespaceCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> serviceNameCaptor = ArgumentCaptor.forClass(String.class);
    when(mockServiceOps.reconcile(serviceNamespaceCaptor.capture(), serviceNameCaptor.capture(), isNull())).thenReturn(Future.succeededFuture());
    ArgumentCaptor<String> dcNamespaceCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> dcNameCaptor = ArgumentCaptor.forClass(String.class);
    when(mockDcOps.reconcile(dcNamespaceCaptor.capture(), dcNameCaptor.capture(), isNull())).thenReturn(Future.succeededFuture());
    ArgumentCaptor<String> isNamespaceCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> isNameCaptor = ArgumentCaptor.forClass(String.class);
    when(mockIsOps.reconcile(isNamespaceCaptor.capture(), isNameCaptor.capture(), isNull())).thenReturn(Future.succeededFuture());
    ArgumentCaptor<String> bcNamespaceCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> bcNameCaptor = ArgumentCaptor.forClass(String.class);
    when(mockBcOps.reconcile(bcNamespaceCaptor.capture(), bcNameCaptor.capture(), isNull())).thenReturn(Future.succeededFuture());
    KafkaConnectS2IAssemblyOperator ops = new KafkaConnectS2IAssemblyOperator(vertx, true, mockCmOps, mockDcOps, mockServiceOps, mockIsOps, mockBcOps);
    Async async = context.async();
    ops.delete(new Reconciliation("test-trigger", AssemblyType.CONNECT_S2I, clusterCmNamespace, clusterCmName), createResult -> {
        context.assertTrue(createResult.succeeded());
        // Verify service
        context.assertEquals(1, serviceNameCaptor.getAllValues().size());
        context.assertEquals(clusterCmNamespace, serviceNamespaceCaptor.getValue());
        context.assertEquals(connect.getName(), serviceNameCaptor.getValue());
        // Vertify deployment Config
        context.assertEquals(1, dcNameCaptor.getAllValues().size());
        context.assertEquals(clusterCmNamespace, dcNamespaceCaptor.getValue());
        context.assertEquals(connect.getName(), dcNameCaptor.getValue());
        // Vertify BuildConfig
        context.assertEquals(1, bcNameCaptor.getAllValues().size());
        context.assertEquals(clusterCmNamespace, bcNamespaceCaptor.getValue());
        context.assertEquals(connect.getName(), bcNameCaptor.getValue());
        // Vertify ImageStreams
        int sisIndex = (connect.getSourceImageStreamName()).equals(isNameCaptor.getAllValues().get(0)) ? 0 : 1;
        int tisIndex = (connect.getName()).equals(isNameCaptor.getAllValues().get(0)) ? 0 : 1;
        context.assertEquals(2, isNameCaptor.getAllValues().size());
        context.assertEquals(clusterCmNamespace, isNamespaceCaptor.getAllValues().get(sisIndex));
        context.assertEquals(connect.getSourceImageStreamName(), isNameCaptor.getAllValues().get(sisIndex));
        context.assertEquals(clusterCmNamespace, isNamespaceCaptor.getAllValues().get(tisIndex));
        context.assertEquals(connect.getName(), isNameCaptor.getAllValues().get(tisIndex));
        async.complete();
    });
}
Also used : 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) DeploymentConfigOperator(io.strimzi.controller.cluster.operator.resource.DeploymentConfigOperator) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ServiceOperator(io.strimzi.controller.cluster.operator.resource.ServiceOperator) Test(org.junit.Test)

Example 8 with BuildConfigOperator

use of io.strimzi.controller.cluster.operator.resource.BuildConfigOperator 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 9 with BuildConfigOperator

use of io.strimzi.controller.cluster.operator.resource.BuildConfigOperator 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

BuildConfigOperator (io.strimzi.controller.cluster.operator.resource.BuildConfigOperator)9 ConfigMapOperator (io.strimzi.controller.cluster.operator.resource.ConfigMapOperator)9 DeploymentConfigOperator (io.strimzi.controller.cluster.operator.resource.DeploymentConfigOperator)9 ImageStreamOperator (io.strimzi.controller.cluster.operator.resource.ImageStreamOperator)9 ServiceOperator (io.strimzi.controller.cluster.operator.resource.ServiceOperator)9 Reconciliation (io.strimzi.controller.cluster.Reconciliation)8 Async (io.vertx.ext.unit.Async)8 Test (org.junit.Test)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)7 KafkaConnectS2ICluster (io.strimzi.controller.cluster.model.KafkaConnectS2ICluster)7 Service (io.fabric8.kubernetes.api.model.Service)4 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)4 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)4 ImageStream (io.fabric8.openshift.api.model.ImageStream)4 Labels (io.strimzi.controller.cluster.model.Labels)1 KafkaAssemblyOperator (io.strimzi.controller.cluster.operator.assembly.KafkaAssemblyOperator)1 KafkaConnectAssemblyOperator (io.strimzi.controller.cluster.operator.assembly.KafkaConnectAssemblyOperator)1 KafkaConnectS2IAssemblyOperator (io.strimzi.controller.cluster.operator.assembly.KafkaConnectS2IAssemblyOperator)1 DeploymentOperator (io.strimzi.controller.cluster.operator.resource.DeploymentOperator)1