Search in sources :

Example 16 with CertSecretSource

use of io.strimzi.api.kafka.model.CertSecretSource in project strimzi by strimzi.

the class KafkaMirrorMakerCluster method addProducerEnvVars.

/**
 * Sets the producer related environment variables in the provided List.
 *
 * @param varList   List with environment variables
 */
private void addProducerEnvVars(List<EnvVar> varList) {
    if (producer.getTls() != null) {
        varList.add(buildEnvVar(ENV_VAR_KAFKA_MIRRORMAKER_TLS_PRODUCER, "true"));
        if (producer.getTls().getTrustedCertificates() != null && producer.getTls().getTrustedCertificates().size() > 0) {
            StringBuilder sb = new StringBuilder();
            boolean separator = false;
            for (CertSecretSource certSecretSource : producer.getTls().getTrustedCertificates()) {
                if (separator) {
                    sb.append(";");
                }
                sb.append(certSecretSource.getSecretName() + "/" + certSecretSource.getCertificate());
                separator = true;
            }
            varList.add(buildEnvVar(ENV_VAR_KAFKA_MIRRORMAKER_TRUSTED_CERTS_PRODUCER, sb.toString()));
        }
    }
    AuthenticationUtils.configureClientAuthenticationEnvVars(producer.getAuthentication(), varList, name -> ENV_VAR_PREFIX + name + "_PRODUCER");
}
Also used : CertSecretSource(io.strimzi.api.kafka.model.CertSecretSource)

Example 17 with CertSecretSource

use of io.strimzi.api.kafka.model.CertSecretSource in project strimzi by strimzi.

the class KafkaConnectAssemblyOperator method generateAuthHash.

/**
 * Generates a hash from the trusted TLS certificates that can be used to spot if it has changed.
 *
 * @param namespace          Namespace of the Connect cluster
 * @param kafkaConnectSpec   KafkaConnectSpec object
 * @return                   Future for tracking the asynchronous result of generating the TLS auth hash
 */
Future<Integer> generateAuthHash(String namespace, KafkaConnectSpec kafkaConnectSpec) {
    KafkaClientAuthentication auth = kafkaConnectSpec.getAuthentication();
    List<CertSecretSource> trustedCertificates = kafkaConnectSpec.getTls() == null ? Collections.emptyList() : kafkaConnectSpec.getTls().getTrustedCertificates();
    return Util.authTlsHash(secretOperations, namespace, auth, trustedCertificates);
}
Also used : KafkaClientAuthentication(io.strimzi.api.kafka.model.authentication.KafkaClientAuthentication) CertSecretSource(io.strimzi.api.kafka.model.CertSecretSource)

Example 18 with CertSecretSource

use of io.strimzi.api.kafka.model.CertSecretSource in project strimzi by strimzi.

the class KafkaMirrorMakerAssemblyOperator method createOrUpdate.

@Override
protected Future<KafkaMirrorMakerStatus> createOrUpdate(Reconciliation reconciliation, KafkaMirrorMaker assemblyResource) {
    String namespace = reconciliation.namespace();
    KafkaMirrorMakerCluster mirror;
    KafkaMirrorMakerStatus kafkaMirrorMakerStatus = new KafkaMirrorMakerStatus();
    try {
        mirror = KafkaMirrorMakerCluster.fromCrd(reconciliation, assemblyResource, versions);
    } catch (Exception e) {
        LOGGER.warnCr(reconciliation, e);
        StatusUtils.setStatusConditionAndObservedGeneration(assemblyResource, kafkaMirrorMakerStatus, Future.failedFuture(e));
        return Future.failedFuture(new ReconciliationException(kafkaMirrorMakerStatus, e));
    }
    Map<String, String> annotations = new HashMap<>(1);
    KafkaClientAuthentication authConsumer = assemblyResource.getSpec().getConsumer().getAuthentication();
    List<CertSecretSource> trustedCertificatesConsumer = assemblyResource.getSpec().getConsumer().getTls() == null ? Collections.emptyList() : assemblyResource.getSpec().getConsumer().getTls().getTrustedCertificates();
    KafkaClientAuthentication authProducer = assemblyResource.getSpec().getProducer().getAuthentication();
    List<CertSecretSource> trustedCertificatesProducer = assemblyResource.getSpec().getProducer().getTls() == null ? Collections.emptyList() : assemblyResource.getSpec().getProducer().getTls().getTrustedCertificates();
    Promise<KafkaMirrorMakerStatus> createOrUpdatePromise = Promise.promise();
    boolean mirrorHasZeroReplicas = mirror.getReplicas() == 0;
    LOGGER.debugCr(reconciliation, "Updating Kafka Mirror Maker cluster");
    mirrorMakerServiceAccount(reconciliation, namespace, mirror).compose(i -> deploymentOperations.scaleDown(reconciliation, namespace, mirror.getName(), mirror.getReplicas())).compose(i -> Util.metricsAndLogging(reconciliation, configMapOperations, namespace, mirror.getLogging(), mirror.getMetricsConfigInCm())).compose(metricsAndLoggingCm -> {
        ConfigMap logAndMetricsConfigMap = mirror.generateMetricsAndLogConfigMap(metricsAndLoggingCm);
        annotations.put(Annotations.STRIMZI_LOGGING_ANNOTATION, logAndMetricsConfigMap.getData().get(mirror.ANCILLARY_CM_KEY_LOG_CONFIG));
        return configMapOperations.reconcile(reconciliation, namespace, mirror.getAncillaryConfigMapName(), logAndMetricsConfigMap);
    }).compose(i -> pfa.hasPodDisruptionBudgetV1() ? podDisruptionBudgetOperator.reconcile(reconciliation, namespace, mirror.getName(), mirror.generatePodDisruptionBudget()) : Future.succeededFuture()).compose(i -> !pfa.hasPodDisruptionBudgetV1() ? podDisruptionBudgetV1Beta1Operator.reconcile(reconciliation, namespace, mirror.getName(), mirror.generatePodDisruptionBudgetV1Beta1()) : Future.succeededFuture()).compose(i -> CompositeFuture.join(Util.authTlsHash(secretOperations, namespace, authConsumer, trustedCertificatesConsumer), Util.authTlsHash(secretOperations, namespace, authProducer, trustedCertificatesProducer))).compose(hashFut -> {
        if (hashFut != null) {
            annotations.put(Annotations.ANNO_STRIMZI_AUTH_HASH, Integer.toString((int) hashFut.resultAt(0) + (int) hashFut.resultAt(1)));
        }
        return Future.succeededFuture();
    }).compose(i -> deploymentOperations.reconcile(reconciliation, namespace, mirror.getName(), mirror.generateDeployment(annotations, pfa.isOpenshift(), imagePullPolicy, imagePullSecrets))).compose(i -> deploymentOperations.scaleUp(reconciliation, namespace, mirror.getName(), mirror.getReplicas())).compose(i -> deploymentOperations.waitForObserved(reconciliation, namespace, mirror.getName(), 1_000, operationTimeoutMs)).compose(i -> mirrorHasZeroReplicas ? Future.succeededFuture() : deploymentOperations.readiness(reconciliation, namespace, mirror.getName(), 1_000, operationTimeoutMs)).onComplete(reconciliationResult -> {
        StatusUtils.setStatusConditionAndObservedGeneration(assemblyResource, kafkaMirrorMakerStatus, reconciliationResult);
        kafkaMirrorMakerStatus.setReplicas(mirror.getReplicas());
        kafkaMirrorMakerStatus.setLabelSelector(mirror.getSelectorLabels().toSelectorString());
        if (reconciliationResult.succeeded()) {
            createOrUpdatePromise.complete(kafkaMirrorMakerStatus);
        } else {
            createOrUpdatePromise.fail(new ReconciliationException(kafkaMirrorMakerStatus, reconciliationResult.cause()));
        }
    });
    return createOrUpdatePromise.future();
}
Also used : ReconciliationException(io.strimzi.operator.common.ReconciliationException) KafkaMirrorMakerResources(io.strimzi.api.kafka.model.KafkaMirrorMakerResources) KafkaMirrorMakerList(io.strimzi.api.kafka.KafkaMirrorMakerList) CertManager(io.strimzi.certs.CertManager) Annotations(io.strimzi.operator.common.Annotations) HashMap(java.util.HashMap) CompositeFuture(io.vertx.core.CompositeFuture) Resource(io.fabric8.kubernetes.client.dsl.Resource) Map(java.util.Map) KafkaMirrorMakerSpec(io.strimzi.api.kafka.model.KafkaMirrorMakerSpec) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ReconciliationException(io.strimzi.operator.common.ReconciliationException) ReconcileResult(io.strimzi.operator.common.operator.resource.ReconcileResult) StatusUtils(io.strimzi.operator.common.operator.resource.StatusUtils) ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) CertSecretSource(io.strimzi.api.kafka.model.CertSecretSource) KafkaMirrorMaker(io.strimzi.api.kafka.model.KafkaMirrorMaker) DeploymentOperator(io.strimzi.operator.common.operator.resource.DeploymentOperator) Promise(io.vertx.core.Promise) KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) Vertx(io.vertx.core.Vertx) Future(io.vertx.core.Future) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Reconciliation(io.strimzi.operator.common.Reconciliation) List(java.util.List) Util(io.strimzi.operator.common.Util) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) KafkaMirrorMakerCluster(io.strimzi.operator.cluster.model.KafkaMirrorMakerCluster) KafkaMirrorMakerStatus(io.strimzi.api.kafka.model.status.KafkaMirrorMakerStatus) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) KafkaClientAuthentication(io.strimzi.api.kafka.model.authentication.KafkaClientAuthentication) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) Collections(java.util.Collections) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) KafkaMirrorMakerStatus(io.strimzi.api.kafka.model.status.KafkaMirrorMakerStatus) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) HashMap(java.util.HashMap) KafkaMirrorMakerCluster(io.strimzi.operator.cluster.model.KafkaMirrorMakerCluster) ReconciliationException(io.strimzi.operator.common.ReconciliationException) KafkaClientAuthentication(io.strimzi.api.kafka.model.authentication.KafkaClientAuthentication) CertSecretSource(io.strimzi.api.kafka.model.CertSecretSource)

Example 19 with CertSecretSource

use of io.strimzi.api.kafka.model.CertSecretSource in project strimzi by strimzi.

the class KafkaBridgeAssemblyOperator method createOrUpdate.

@Override
protected Future<KafkaBridgeStatus> createOrUpdate(Reconciliation reconciliation, KafkaBridge assemblyResource) {
    KafkaBridgeStatus kafkaBridgeStatus = new KafkaBridgeStatus();
    String namespace = reconciliation.namespace();
    KafkaBridgeCluster bridge;
    try {
        bridge = KafkaBridgeCluster.fromCrd(reconciliation, assemblyResource, versions);
    } catch (Exception e) {
        LOGGER.warnCr(reconciliation, e);
        StatusUtils.setStatusConditionAndObservedGeneration(assemblyResource, kafkaBridgeStatus, Future.failedFuture(e));
        return Future.failedFuture(new ReconciliationException(kafkaBridgeStatus, e));
    }
    KafkaClientAuthentication auth = assemblyResource.getSpec().getAuthentication();
    List<CertSecretSource> trustedCertificates = assemblyResource.getSpec().getTls() == null ? Collections.emptyList() : assemblyResource.getSpec().getTls().getTrustedCertificates();
    Promise<KafkaBridgeStatus> createOrUpdatePromise = Promise.promise();
    boolean bridgeHasZeroReplicas = bridge.getReplicas() == 0;
    LOGGER.debugCr(reconciliation, "Updating Kafka Bridge cluster");
    kafkaBridgeServiceAccount(reconciliation, namespace, bridge).compose(i -> deploymentOperations.scaleDown(reconciliation, namespace, bridge.getName(), bridge.getReplicas())).compose(scale -> serviceOperations.reconcile(reconciliation, namespace, bridge.getServiceName(), bridge.generateService())).compose(i -> Util.metricsAndLogging(reconciliation, configMapOperations, namespace, bridge.getLogging(), null)).compose(metricsAndLogging -> configMapOperations.reconcile(reconciliation, namespace, bridge.getAncillaryConfigMapName(), bridge.generateMetricsAndLogConfigMap(metricsAndLogging))).compose(i -> pfa.hasPodDisruptionBudgetV1() ? podDisruptionBudgetOperator.reconcile(reconciliation, namespace, bridge.getName(), bridge.generatePodDisruptionBudget()) : Future.succeededFuture()).compose(i -> !pfa.hasPodDisruptionBudgetV1() ? podDisruptionBudgetV1Beta1Operator.reconcile(reconciliation, namespace, bridge.getName(), bridge.generatePodDisruptionBudgetV1Beta1()) : Future.succeededFuture()).compose(i -> Util.authTlsHash(secretOperations, namespace, auth, trustedCertificates)).compose(hash -> deploymentOperations.reconcile(reconciliation, namespace, bridge.getName(), bridge.generateDeployment(Collections.singletonMap(Annotations.ANNO_STRIMZI_AUTH_HASH, Integer.toString(hash)), pfa.isOpenshift(), imagePullPolicy, imagePullSecrets))).compose(i -> deploymentOperations.scaleUp(reconciliation, namespace, bridge.getName(), bridge.getReplicas())).compose(i -> deploymentOperations.waitForObserved(reconciliation, namespace, bridge.getName(), 1_000, operationTimeoutMs)).compose(i -> bridgeHasZeroReplicas ? Future.succeededFuture() : deploymentOperations.readiness(reconciliation, namespace, bridge.getName(), 1_000, operationTimeoutMs)).onComplete(reconciliationResult -> {
        StatusUtils.setStatusConditionAndObservedGeneration(assemblyResource, kafkaBridgeStatus, reconciliationResult.mapEmpty());
        if (!bridgeHasZeroReplicas) {
            int port = KafkaBridgeCluster.DEFAULT_REST_API_PORT;
            if (bridge.getHttp() != null) {
                port = bridge.getHttp().getPort();
            }
            kafkaBridgeStatus.setUrl(KafkaBridgeResources.url(bridge.getCluster(), namespace, port));
        }
        kafkaBridgeStatus.setReplicas(bridge.getReplicas());
        kafkaBridgeStatus.setLabelSelector(bridge.getSelectorLabels().toSelectorString());
        if (reconciliationResult.succeeded()) {
            createOrUpdatePromise.complete(kafkaBridgeStatus);
        } else {
            createOrUpdatePromise.fail(new ReconciliationException(kafkaBridgeStatus, reconciliationResult.cause()));
        }
    });
    return createOrUpdatePromise.future();
}
Also used : KafkaBridgeCluster(io.strimzi.operator.cluster.model.KafkaBridgeCluster) ReconciliationException(io.strimzi.operator.common.ReconciliationException) KafkaClientAuthentication(io.strimzi.api.kafka.model.authentication.KafkaClientAuthentication) CertManager(io.strimzi.certs.CertManager) Annotations(io.strimzi.operator.common.Annotations) Resource(io.fabric8.kubernetes.client.dsl.Resource) KafkaBridge(io.strimzi.api.kafka.model.KafkaBridge) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ReconciliationException(io.strimzi.operator.common.ReconciliationException) ReconcileResult(io.strimzi.operator.common.operator.resource.ReconcileResult) KafkaBridgeResources(io.strimzi.api.kafka.model.KafkaBridgeResources) StatusUtils(io.strimzi.operator.common.operator.resource.StatusUtils) ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) ExternalLogging(io.strimzi.api.kafka.model.ExternalLogging) CertSecretSource(io.strimzi.api.kafka.model.CertSecretSource) DeploymentOperator(io.strimzi.operator.common.operator.resource.DeploymentOperator) Promise(io.vertx.core.Promise) KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) Vertx(io.vertx.core.Vertx) KafkaBridgeSpec(io.strimzi.api.kafka.model.KafkaBridgeSpec) KafkaBridgeList(io.strimzi.api.kafka.KafkaBridgeList) Future(io.vertx.core.Future) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) KafkaBridgeCluster(io.strimzi.operator.cluster.model.KafkaBridgeCluster) KafkaBridgeStatus(io.strimzi.api.kafka.model.status.KafkaBridgeStatus) Reconciliation(io.strimzi.operator.common.Reconciliation) List(java.util.List) Util(io.strimzi.operator.common.Util) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) KafkaClientAuthentication(io.strimzi.api.kafka.model.authentication.KafkaClientAuthentication) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) Collections(java.util.Collections) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) CertSecretSource(io.strimzi.api.kafka.model.CertSecretSource) ReconciliationException(io.strimzi.operator.common.ReconciliationException) KafkaBridgeStatus(io.strimzi.api.kafka.model.status.KafkaBridgeStatus)

Example 20 with CertSecretSource

use of io.strimzi.api.kafka.model.CertSecretSource in project strimzi-kafka-operator by strimzi.

the class KafkaConnectCluster method populateTLSEnvVars.

private void populateTLSEnvVars(final List<EnvVar> varList) {
    varList.add(buildEnvVar(ENV_VAR_KAFKA_CONNECT_TLS, "true"));
    List<CertSecretSource> trustedCertificates = tls.getTrustedCertificates();
    if (trustedCertificates != null && trustedCertificates.size() > 0) {
        StringBuilder sb = new StringBuilder();
        boolean separator = false;
        for (CertSecretSource certSecretSource : trustedCertificates) {
            if (separator) {
                sb.append(";");
            }
            sb.append(certSecretSource.getSecretName()).append("/").append(certSecretSource.getCertificate());
            separator = true;
        }
        varList.add(buildEnvVar(ENV_VAR_KAFKA_CONNECT_TRUSTED_CERTS, sb.toString()));
    }
}
Also used : CertSecretSource(io.strimzi.api.kafka.model.CertSecretSource)

Aggregations

CertSecretSource (io.strimzi.api.kafka.model.CertSecretSource)70 CertSecretSourceBuilder (io.strimzi.api.kafka.model.CertSecretSourceBuilder)30 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)26 ParallelTest (io.strimzi.test.annotations.ParallelTest)24 ArrayList (java.util.ArrayList)24 ResourceRequirementsBuilder (io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder)22 ServiceAccount (io.fabric8.kubernetes.api.model.ServiceAccount)22 Reconciliation (io.strimzi.operator.common.Reconciliation)22 Collections (java.util.Collections)22 List (java.util.List)22 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)20 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)20 ContainerEnvVar (io.strimzi.api.kafka.model.ContainerEnvVar)20 HashMap (java.util.HashMap)20 Map (java.util.Map)20 Container (io.fabric8.kubernetes.api.model.Container)18 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)18 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)18 LocalObjectReference (io.fabric8.kubernetes.api.model.LocalObjectReference)18 OwnerReference (io.fabric8.kubernetes.api.model.OwnerReference)18