Search in sources :

Example 1 with KafkaUserModel

use of io.strimzi.operator.user.model.KafkaUserModel in project strimzi by strimzi.

the class KafkaUserOperator method createOrUpdate.

/**
 * Creates or updates the user. The implementation
 * should not assume that any resources are in any particular state (e.g. that the absence on
 * one resource means that all resources need to be created).
 *
 * @param reconciliation Unique identification for the reconciliation
 * @param resource KafkaUser resources with the desired user configuration.
 * @return a Future
 */
@Override
protected Future<KafkaUserStatus> createOrUpdate(Reconciliation reconciliation, KafkaUser resource) {
    KafkaUserModel user;
    KafkaUserStatus userStatus = new KafkaUserStatus();
    try {
        user = KafkaUserModel.fromCrd(resource, config.getSecretPrefix(), config.isAclsAdminApiSupported());
        LOGGER.debugCr(reconciliation, "Updating User {} in namespace {}", reconciliation.name(), reconciliation.namespace());
    } catch (Exception e) {
        LOGGER.warnCr(reconciliation, e);
        StatusUtils.setStatusConditionAndObservedGeneration(resource, userStatus, Future.failedFuture(e));
        return Future.failedFuture(new ReconciliationException(userStatus, e));
    }
    Promise<KafkaUserStatus> handler = Promise.promise();
    secretOperations.getAsync(reconciliation.namespace(), user.getSecretName()).compose(userSecret -> maybeGenerateCredentials(reconciliation, user, userSecret)).compose(ignore -> reconcileCredentialsQuotasAndAcls(reconciliation, user, userStatus)).onComplete(reconciliationResult -> {
        StatusUtils.setStatusConditionAndObservedGeneration(resource, userStatus, reconciliationResult.mapEmpty());
        userStatus.setUsername(user.getUserName());
        if (reconciliationResult.succeeded()) {
            handler.complete(userStatus);
        } else {
            handler.fail(new ReconciliationException(userStatus, reconciliationResult.cause()));
        }
    });
    return handler.future();
}
Also used : ReconciliationException(io.strimzi.operator.common.ReconciliationException) CertManager(io.strimzi.certs.CertManager) KafkaUser(io.strimzi.api.kafka.model.KafkaUser) KafkaUserList(io.strimzi.api.kafka.KafkaUserList) CompositeFuture(io.vertx.core.CompositeFuture) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) ReconciliationException(io.strimzi.operator.common.ReconciliationException) ReconcileResult(io.strimzi.operator.common.operator.resource.ReconcileResult) AbstractOperator(io.strimzi.operator.common.AbstractOperator) StatusUtils(io.strimzi.operator.common.operator.resource.StatusUtils) ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) KafkaUserStatus(io.strimzi.api.kafka.model.status.KafkaUserStatus) SimpleAclRule(io.strimzi.operator.user.model.acl.SimpleAclRule) Promise(io.vertx.core.Promise) Collection(java.util.Collection) MicrometerMetricsProvider(io.strimzi.operator.common.MicrometerMetricsProvider) Vertx(io.vertx.core.Vertx) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) Set(java.util.Set) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) KafkaUserModel(io.strimzi.operator.user.model.KafkaUserModel) Reconciliation(io.strimzi.operator.common.Reconciliation) NamespaceAndName(io.strimzi.operator.common.model.NamespaceAndName) List(java.util.List) KafkaUserQuotas(io.strimzi.api.kafka.model.KafkaUserQuotas) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) UserOperatorConfig(io.strimzi.operator.user.UserOperatorConfig) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Secret(io.fabric8.kubernetes.api.model.Secret) KafkaUserSpec(io.strimzi.api.kafka.model.KafkaUserSpec) KafkaUserModel(io.strimzi.operator.user.model.KafkaUserModel) KafkaUserStatus(io.strimzi.api.kafka.model.status.KafkaUserStatus) ReconciliationException(io.strimzi.operator.common.ReconciliationException)

Example 2 with KafkaUserModel

use of io.strimzi.operator.user.model.KafkaUserModel in project strimzi-kafka-operator by strimzi.

the class KafkaUserOperator method createOrUpdate.

/**
 * Creates or updates the user. The implementation
 * should not assume that any resources are in any particular state (e.g. that the absence on
 * one resource means that all resources need to be created).
 *
 * @param reconciliation Unique identification for the reconciliation
 * @param resource KafkaUser resources with the desired user configuration.
 * @return a Future
 */
@Override
protected Future<KafkaUserStatus> createOrUpdate(Reconciliation reconciliation, KafkaUser resource) {
    KafkaUserModel user;
    KafkaUserStatus userStatus = new KafkaUserStatus();
    try {
        user = KafkaUserModel.fromCrd(resource, config.getSecretPrefix(), config.isAclsAdminApiSupported());
        LOGGER.debugCr(reconciliation, "Updating User {} in namespace {}", reconciliation.name(), reconciliation.namespace());
    } catch (Exception e) {
        LOGGER.warnCr(reconciliation, e);
        StatusUtils.setStatusConditionAndObservedGeneration(resource, userStatus, Future.failedFuture(e));
        return Future.failedFuture(new ReconciliationException(userStatus, e));
    }
    Promise<KafkaUserStatus> handler = Promise.promise();
    secretOperations.getAsync(reconciliation.namespace(), user.getSecretName()).compose(userSecret -> maybeGenerateCredentials(reconciliation, user, userSecret)).compose(ignore -> reconcileCredentialsQuotasAndAcls(reconciliation, user, userStatus)).onComplete(reconciliationResult -> {
        StatusUtils.setStatusConditionAndObservedGeneration(resource, userStatus, reconciliationResult.mapEmpty());
        userStatus.setUsername(user.getUserName());
        if (reconciliationResult.succeeded()) {
            handler.complete(userStatus);
        } else {
            handler.fail(new ReconciliationException(userStatus, reconciliationResult.cause()));
        }
    });
    return handler.future();
}
Also used : ReconciliationException(io.strimzi.operator.common.ReconciliationException) CertManager(io.strimzi.certs.CertManager) KafkaUser(io.strimzi.api.kafka.model.KafkaUser) KafkaUserList(io.strimzi.api.kafka.KafkaUserList) CompositeFuture(io.vertx.core.CompositeFuture) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) ReconciliationException(io.strimzi.operator.common.ReconciliationException) ReconcileResult(io.strimzi.operator.common.operator.resource.ReconcileResult) AbstractOperator(io.strimzi.operator.common.AbstractOperator) StatusUtils(io.strimzi.operator.common.operator.resource.StatusUtils) ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) KafkaUserStatus(io.strimzi.api.kafka.model.status.KafkaUserStatus) SimpleAclRule(io.strimzi.operator.user.model.acl.SimpleAclRule) Promise(io.vertx.core.Promise) Collection(java.util.Collection) MicrometerMetricsProvider(io.strimzi.operator.common.MicrometerMetricsProvider) Vertx(io.vertx.core.Vertx) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) Set(java.util.Set) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) KafkaUserModel(io.strimzi.operator.user.model.KafkaUserModel) Reconciliation(io.strimzi.operator.common.Reconciliation) NamespaceAndName(io.strimzi.operator.common.model.NamespaceAndName) List(java.util.List) KafkaUserQuotas(io.strimzi.api.kafka.model.KafkaUserQuotas) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) UserOperatorConfig(io.strimzi.operator.user.UserOperatorConfig) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Secret(io.fabric8.kubernetes.api.model.Secret) KafkaUserSpec(io.strimzi.api.kafka.model.KafkaUserSpec) KafkaUserModel(io.strimzi.operator.user.model.KafkaUserModel) KafkaUserStatus(io.strimzi.api.kafka.model.status.KafkaUserStatus) ReconciliationException(io.strimzi.operator.common.ReconciliationException)

Aggregations

Secret (io.fabric8.kubernetes.api.model.Secret)2 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 KafkaUserList (io.strimzi.api.kafka.KafkaUserList)2 KafkaUser (io.strimzi.api.kafka.model.KafkaUser)2 KafkaUserQuotas (io.strimzi.api.kafka.model.KafkaUserQuotas)2 KafkaUserSpec (io.strimzi.api.kafka.model.KafkaUserSpec)2 KafkaUserStatus (io.strimzi.api.kafka.model.status.KafkaUserStatus)2 CertManager (io.strimzi.certs.CertManager)2 AbstractOperator (io.strimzi.operator.common.AbstractOperator)2 MicrometerMetricsProvider (io.strimzi.operator.common.MicrometerMetricsProvider)2 PasswordGenerator (io.strimzi.operator.common.PasswordGenerator)2 Reconciliation (io.strimzi.operator.common.Reconciliation)2 ReconciliationException (io.strimzi.operator.common.ReconciliationException)2 ReconciliationLogger (io.strimzi.operator.common.ReconciliationLogger)2 NamespaceAndName (io.strimzi.operator.common.model.NamespaceAndName)2 CrdOperator (io.strimzi.operator.common.operator.resource.CrdOperator)2 ReconcileResult (io.strimzi.operator.common.operator.resource.ReconcileResult)2 SecretOperator (io.strimzi.operator.common.operator.resource.SecretOperator)2 StatusUtils (io.strimzi.operator.common.operator.resource.StatusUtils)2 UserOperatorConfig (io.strimzi.operator.user.UserOperatorConfig)2