Search in sources :

Example 31 with Reconciliation

use of io.strimzi.controller.cluster.Reconciliation 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 32 with Reconciliation

use of io.strimzi.controller.cluster.Reconciliation 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 33 with Reconciliation

use of io.strimzi.controller.cluster.Reconciliation in project strimzi by strimzi.

the class AbstractAssemblyOperator method reconcileAll.

/**
 * Reconcile assembly resources in the given namespace having the given selector.
 * Reconciliation works by getting the assembly ConfigMaps in the given namespace with the given selector and
 * comparing with the corresponding {@linkplain #getResources(String) resource}.
 * <ul>
 * <li>An assembly will be {@linkplain #createOrUpdate(Reconciliation, ConfigMap, Handler) created} for all ConfigMaps without same-named resources</li>
 * <li>An assembly will be {@linkplain #delete(Reconciliation, Handler) deleted} for all resources without same-named ConfigMaps</li>
 * </ul>
 *
 * @param trigger A description of the triggering event (timer or watch), used for logging
 * @param namespace The namespace
 * @param selector The selector
 */
public final CountDownLatch reconcileAll(String trigger, String namespace, Labels selector) {
    Labels selectorWithCluster = selector.withType(assemblyType);
    // get ConfigMaps with kind=cluster&type=kafka (or connect, or connect-s2i) for the corresponding cluster type
    List<ConfigMap> cms = configMapOperations.list(namespace, selectorWithCluster);
    Set<String> cmsNames = cms.stream().map(cm -> cm.getMetadata().getName()).collect(Collectors.toSet());
    log.debug("reconcileAll({}, {}): ConfigMaps with labels {}: {}", assemblyType, trigger, selectorWithCluster, cmsNames);
    // get resources with kind=cluster&type=kafka (or connect, or connect-s2i)
    List<? extends HasMetadata> resources = getResources(namespace);
    // now extract the cluster name from those
    Set<String> resourceNames = resources.stream().filter(// exclude Cluster CM, which won't have a cluster label
    r -> Labels.kind(r) == null).map(Labels::cluster).collect(Collectors.toSet());
    log.debug("reconcileAll({}, {}): Other resources with labels {}: {}", assemblyType, trigger, selectorWithCluster, resourceNames);
    cmsNames.addAll(resourceNames);
    // We use a latch so that callers (specifically, test callers) know when the reconciliation is complete
    // Using futures would be more complex for no benefit
    CountDownLatch latch = new CountDownLatch(cmsNames.size());
    for (String name : cmsNames) {
        Reconciliation reconciliation = new Reconciliation(trigger, assemblyType, namespace, name);
        reconcileAssembly(reconciliation, result -> {
            if (result.succeeded()) {
                log.info("{}: Assembly reconciled", reconciliation);
            } else {
                log.error("{}: Failed to reconcile", reconciliation);
            }
            latch.countDown();
        });
    }
    return latch;
}
Also used : AssemblyType(io.strimzi.controller.cluster.model.AssemblyType) Logger(org.slf4j.Logger) Vertx(io.vertx.core.Vertx) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) ConfigMapOperator(io.strimzi.controller.cluster.operator.resource.ConfigMapOperator) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Labels(io.strimzi.controller.cluster.model.Labels) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Lock(io.vertx.core.shareddata.Lock) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) Reconciliation(io.strimzi.controller.cluster.Reconciliation) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Reconciliation(io.strimzi.controller.cluster.Reconciliation) Labels(io.strimzi.controller.cluster.model.Labels) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 34 with Reconciliation

use of io.strimzi.controller.cluster.Reconciliation in project strimzi by strimzi.

the class KafkaConnectAssemblyOperator method createOrUpdate.

@Override
protected void createOrUpdate(Reconciliation reconciliation, ConfigMap assemblyCm, Handler<AsyncResult<Void>> handler) {
    String namespace = reconciliation.namespace();
    String name = reconciliation.assemblyName();
    KafkaConnectCluster connect = KafkaConnectCluster.fromConfigMap(assemblyCm);
    log.info("{}: Updating Kafka Connect cluster", reconciliation, name, namespace);
    Future<Void> chainFuture = Future.future();
    deploymentOperations.scaleDown(namespace, connect.getName(), connect.getReplicas()).compose(scale -> serviceOperations.reconcile(namespace, connect.getName(), connect.generateService())).compose(i -> deploymentOperations.reconcile(namespace, connect.getName(), connect.generateDeployment())).compose(i -> deploymentOperations.scaleUp(namespace, connect.getName(), connect.getReplicas()).map((Void) null)).compose(chainFuture::complete, chainFuture);
    chainFuture.setHandler(handler);
}
Also used : AssemblyType(io.strimzi.controller.cluster.model.AssemblyType) Logger(org.slf4j.Logger) Vertx(io.vertx.core.Vertx) LoggerFactory(org.slf4j.LoggerFactory) ServiceOperator(io.strimzi.controller.cluster.operator.resource.ServiceOperator) ConfigMapOperator(io.strimzi.controller.cluster.operator.resource.ConfigMapOperator) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Labels(io.strimzi.controller.cluster.model.Labels) Future(io.vertx.core.Future) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ArrayList(java.util.ArrayList) CompositeFuture(io.vertx.core.CompositeFuture) List(java.util.List) Reconciliation(io.strimzi.controller.cluster.Reconciliation) DeploymentOperator(io.strimzi.controller.cluster.operator.resource.DeploymentOperator) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) KafkaConnectCluster(io.strimzi.controller.cluster.model.KafkaConnectCluster) KafkaConnectCluster(io.strimzi.controller.cluster.model.KafkaConnectCluster)

Example 35 with Reconciliation

use of io.strimzi.controller.cluster.Reconciliation in project strimzi by strimzi.

the class KafkaAssemblyOperator method createOrUpdateZk.

private final Future<Void> createOrUpdateZk(Reconciliation reconciliation, ConfigMap assemblyCm) {
    String namespace = assemblyCm.getMetadata().getNamespace();
    String name = assemblyCm.getMetadata().getName();
    log.info("{}: create/update zookeeper {}", reconciliation, name);
    ZookeeperCluster zk = ZookeeperCluster.fromConfigMap(assemblyCm);
    Service service = zk.generateService();
    Service headlessService = zk.generateHeadlessService();
    Future<Void> chainFuture = Future.future();
    zkSetOperations.scaleDown(namespace, zk.getName(), zk.getReplicas()).compose(scale -> serviceOperations.reconcile(namespace, zk.getName(), service)).compose(i -> serviceOperations.reconcile(namespace, zk.getHeadlessName(), headlessService)).compose(i -> configMapOperations.reconcile(namespace, zk.getMetricsConfigName(), zk.generateMetricsConfigMap())).compose(i -> zkSetOperations.reconcile(namespace, zk.getName(), zk.generateStatefulSet(isOpenShift))).compose(diffs -> {
        if (diffs instanceof ReconcileResult.Patched && ((ReconcileResult.Patched<Boolean>) diffs).differences()) {
            return zkSetOperations.rollingUpdate(namespace, zk.getName());
        } else {
            return Future.succeededFuture();
        }
    }).compose(i -> zkSetOperations.scaleUp(namespace, zk.getName(), zk.getReplicas())).compose(scale -> serviceOperations.endpointReadiness(namespace, service, 1_000, operationTimeoutMs)).compose(i -> serviceOperations.endpointReadiness(namespace, headlessService, 1_000, operationTimeoutMs)).compose(chainFuture::complete, chainFuture);
    return chainFuture;
}
Also used : PvcOperator(io.strimzi.controller.cluster.operator.resource.PvcOperator) TopicController.topicControllerName(io.strimzi.controller.cluster.model.TopicController.topicControllerName) KafkaSetOperator(io.strimzi.controller.cluster.operator.resource.KafkaSetOperator) ZookeeperCluster(io.strimzi.controller.cluster.model.ZookeeperCluster) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) ZookeeperSetOperator(io.strimzi.controller.cluster.operator.resource.ZookeeperSetOperator) LoggerFactory(org.slf4j.LoggerFactory) ConfigMapOperator(io.strimzi.controller.cluster.operator.resource.ConfigMapOperator) Storage(io.strimzi.controller.cluster.model.Storage) Labels(io.strimzi.controller.cluster.model.Labels) ArrayList(java.util.ArrayList) CompositeFuture(io.vertx.core.CompositeFuture) Reconciliation(io.strimzi.controller.cluster.Reconciliation) DeploymentOperator(io.strimzi.controller.cluster.operator.resource.DeploymentOperator) KafkaCluster(io.strimzi.controller.cluster.model.KafkaCluster) Service(io.fabric8.kubernetes.api.model.Service) AsyncResult(io.vertx.core.AsyncResult) AssemblyType(io.strimzi.controller.cluster.model.AssemblyType) Logger(org.slf4j.Logger) StatefulSet(io.fabric8.kubernetes.api.model.extensions.StatefulSet) Vertx(io.vertx.core.Vertx) ServiceOperator(io.strimzi.controller.cluster.operator.resource.ServiceOperator) TopicController(io.strimzi.controller.cluster.model.TopicController) ReconcileResult(io.strimzi.controller.cluster.operator.resource.ReconcileResult) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Future(io.vertx.core.Future) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) List(java.util.List) Handler(io.vertx.core.Handler) ReconcileResult(io.strimzi.controller.cluster.operator.resource.ReconcileResult) Service(io.fabric8.kubernetes.api.model.Service) ZookeeperCluster(io.strimzi.controller.cluster.model.ZookeeperCluster)

Aggregations

Reconciliation (io.strimzi.controller.cluster.Reconciliation)35 Async (io.vertx.ext.unit.Async)30 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)28 ConfigMapOperator (io.strimzi.controller.cluster.operator.resource.ConfigMapOperator)28 ServiceOperator (io.strimzi.controller.cluster.operator.resource.ServiceOperator)27 Test (org.junit.Test)24 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)20 DeploymentOperator (io.strimzi.controller.cluster.operator.resource.DeploymentOperator)18 Service (io.fabric8.kubernetes.api.model.Service)11 Labels (io.strimzi.controller.cluster.model.Labels)10 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 KafkaSetOperator (io.strimzi.controller.cluster.operator.resource.KafkaSetOperator)9 PvcOperator (io.strimzi.controller.cluster.operator.resource.PvcOperator)9 ZookeeperSetOperator (io.strimzi.controller.cluster.operator.resource.ZookeeperSetOperator)9 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)8 KafkaConnectCluster (io.strimzi.controller.cluster.model.KafkaConnectCluster)8 Handler (io.vertx.core.Handler)8 HashSet (java.util.HashSet)8