Search in sources :

Example 1 with KafkaConnectS2IAssemblyOperator

use of io.strimzi.controller.cluster.operator.assembly.KafkaConnectS2IAssemblyOperator 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)

Example 2 with KafkaConnectS2IAssemblyOperator

use of io.strimzi.controller.cluster.operator.assembly.KafkaConnectS2IAssemblyOperator in project strimzi by strimzi.

the class ClusterController method createConfigMapWatch.

private void createConfigMapWatch(Handler<AsyncResult<Watch>> handler) {
    getVertx().executeBlocking(future -> {
        Watch watch = client.configMaps().inNamespace(namespace).withLabels(selector.toMap()).watch(new Watcher<ConfigMap>() {

            @Override
            public void eventReceived(Action action, ConfigMap cm) {
                Labels labels = Labels.fromResource(cm);
                AssemblyType type;
                try {
                    type = labels.type();
                } catch (IllegalArgumentException e) {
                    log.warn("Unknown {} label {} received in Config Map {} in namespace {}", Labels.STRIMZI_TYPE_LABEL, cm.getMetadata().getLabels().get(Labels.STRIMZI_TYPE_LABEL), cm.getMetadata().getName(), namespace);
                    return;
                }
                final AbstractAssemblyOperator cluster;
                if (type == null) {
                    log.warn("Missing label {} in Config Map {} in namespace {}", Labels.STRIMZI_TYPE_LABEL, cm.getMetadata().getName(), namespace);
                    return;
                } else {
                    switch(type) {
                        case KAFKA:
                            cluster = kafkaAssemblyOperator;
                            break;
                        case CONNECT:
                            cluster = kafkaConnectAssemblyOperator;
                            break;
                        case CONNECT_S2I:
                            cluster = kafkaConnectS2IAssemblyOperator;
                            break;
                        default:
                            return;
                    }
                }
                String name = cm.getMetadata().getName();
                switch(action) {
                    case ADDED:
                    case DELETED:
                    case MODIFIED:
                        Reconciliation reconciliation = new Reconciliation("watch", type, namespace, name);
                        log.info("{}: ConfigMap {} in namespace {} was {}", reconciliation, name, namespace, action);
                        cluster.reconcileAssembly(reconciliation, result -> {
                            if (result.succeeded()) {
                                log.info("{}: assembly reconciled", reconciliation);
                            } else {
                                log.error("{}: Failed to reconcile", reconciliation);
                            }
                        });
                        break;
                    case ERROR:
                        log.error("Failed ConfigMap {} in namespace{} ", name, namespace);
                        reconcileAll("watch error");
                        break;
                    default:
                        log.error("Unknown action: {} in namespace {}", name, namespace);
                        reconcileAll("watch unknown");
                }
            }

            @Override
            public void onClose(KubernetesClientException e) {
                if (e != null) {
                    log.error("Watcher closed with exception in namespace {}", namespace, e);
                } else {
                    log.info("Watcher closed in namespace {}", namespace);
                }
                recreateConfigMapWatch();
            }
        });
        future.complete(watch);
    }, res -> {
        if (res.succeeded()) {
            log.info("ConfigMap watcher running for labels {}", selector);
            handler.handle(Future.succeededFuture((Watch) res.result()));
        } else {
            log.info("ConfigMap watcher failed to start", res.cause());
            handler.handle(Future.failedFuture("ConfigMap watcher failed to start"));
        }
    });
}
Also used : KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) AssemblyType(io.strimzi.controller.cluster.model.AssemblyType) KafkaAssemblyOperator(io.strimzi.controller.cluster.operator.assembly.KafkaAssemblyOperator) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Watcher(io.fabric8.kubernetes.client.Watcher) Watch(io.fabric8.kubernetes.client.Watch) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Labels(io.strimzi.controller.cluster.model.Labels) Future(io.vertx.core.Future) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) TimeUnit(java.util.concurrent.TimeUnit) AbstractVerticle(io.vertx.core.AbstractVerticle) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) AbstractAssemblyOperator(io.strimzi.controller.cluster.operator.assembly.AbstractAssemblyOperator) KafkaConnectS2IAssemblyOperator(io.strimzi.controller.cluster.operator.assembly.KafkaConnectS2IAssemblyOperator) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) KafkaConnectAssemblyOperator(io.strimzi.controller.cluster.operator.assembly.KafkaConnectAssemblyOperator) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Labels(io.strimzi.controller.cluster.model.Labels) AbstractAssemblyOperator(io.strimzi.controller.cluster.operator.assembly.AbstractAssemblyOperator) AssemblyType(io.strimzi.controller.cluster.model.AssemblyType) Watch(io.fabric8.kubernetes.client.Watch) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Aggregations

KafkaAssemblyOperator (io.strimzi.controller.cluster.operator.assembly.KafkaAssemblyOperator)2 KafkaConnectAssemblyOperator (io.strimzi.controller.cluster.operator.assembly.KafkaConnectAssemblyOperator)2 KafkaConnectS2IAssemblyOperator (io.strimzi.controller.cluster.operator.assembly.KafkaConnectS2IAssemblyOperator)2 Future (io.vertx.core.Future)2 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)1 Watch (io.fabric8.kubernetes.client.Watch)1 Watcher (io.fabric8.kubernetes.client.Watcher)1 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)1 AssemblyType (io.strimzi.controller.cluster.model.AssemblyType)1 Labels (io.strimzi.controller.cluster.model.Labels)1 AbstractAssemblyOperator (io.strimzi.controller.cluster.operator.assembly.AbstractAssemblyOperator)1 BuildConfigOperator (io.strimzi.controller.cluster.operator.resource.BuildConfigOperator)1 ConfigMapOperator (io.strimzi.controller.cluster.operator.resource.ConfigMapOperator)1 DeploymentConfigOperator (io.strimzi.controller.cluster.operator.resource.DeploymentConfigOperator)1 DeploymentOperator (io.strimzi.controller.cluster.operator.resource.DeploymentOperator)1 ImageStreamOperator (io.strimzi.controller.cluster.operator.resource.ImageStreamOperator)1 KafkaSetOperator (io.strimzi.controller.cluster.operator.resource.KafkaSetOperator)1 PvcOperator (io.strimzi.controller.cluster.operator.resource.PvcOperator)1