Search in sources :

Example 1 with KafkaUserQuotas

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

the class UserST method alterBigAmountOfUsers.

synchronized void alterBigAmountOfUsers(ExtensionContext extensionContext, String userName, String typeOfUser, int numberOfUsers, int producerRate, int consumerRate, int requestsPercentage, double mutationRate) {
    KafkaUserQuotas kuq = new KafkaUserQuotas();
    kuq.setConsumerByteRate(consumerRate);
    kuq.setProducerByteRate(producerRate);
    kuq.setRequestPercentage(requestsPercentage);
    kuq.setControllerMutationRate(mutationRate);
    LOGGER.info("Updating of existing KafkaUsers");
    for (int i = 0; i < numberOfUsers; i++) {
        String userNameWithSuffix = userName + "-" + i;
        if (typeOfUser.equals("TLS")) {
            resourceManager.createResource(extensionContext, KafkaUserTemplates.tlsUser(userClusterName, userNameWithSuffix).editMetadata().withNamespace(namespace).endMetadata().editSpec().withQuotas(kuq).endSpec().build());
        } else {
            resourceManager.createResource(extensionContext, KafkaUserTemplates.scramShaUser(userClusterName, userNameWithSuffix).editMetadata().withNamespace(namespace).endMetadata().editSpec().withQuotas(kuq).endSpec().build());
        }
        LOGGER.info("[After update] Checking status of KafkaUser {}", userNameWithSuffix);
        Condition kafkaCondition = KafkaUserResource.kafkaUserClient().inNamespace(namespace).withName(userNameWithSuffix).get().getStatus().getConditions().get(0);
        LOGGER.debug("KafkaUser condition status: {}", kafkaCondition.getStatus());
        LOGGER.debug("KafkaUser condition type: {}", kafkaCondition.getType());
        assertThat(kafkaCondition.getType(), is(Ready.toString()));
        LOGGER.debug("KafkaUser {} is in desired state: {}", userNameWithSuffix, kafkaCondition.getType());
        KafkaUserQuotas kuqAfter = KafkaUserResource.kafkaUserClient().inNamespace(namespace).withName(userNameWithSuffix).get().getSpec().getQuotas();
        LOGGER.debug("Check altered KafkaUser {} new quotas.", userNameWithSuffix);
        assertThat(kuqAfter.getRequestPercentage(), is(requestsPercentage));
        assertThat(kuqAfter.getConsumerByteRate(), is(consumerRate));
        assertThat(kuqAfter.getProducerByteRate(), is(producerRate));
        assertThat(kuqAfter.getControllerMutationRate(), is(mutationRate));
    }
}
Also used : Condition(io.strimzi.api.kafka.model.status.Condition) KafkaUserQuotas(io.strimzi.api.kafka.model.KafkaUserQuotas)

Example 2 with KafkaUserQuotas

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

the class KafkaUserOperator method reconcileCredentialsQuotasAndAcls.

/**
 * Reconciles the credentials, quotas and ACLs
 *
 * @param reconciliation    Unique identification for the reconciliation
 * @param user              Model describing the KafkaUser
 * @param userStatus        Status subresource of the KafkaUser custom resource
 *
 * @return                  Future describing the result
 */
private CompositeFuture reconcileCredentialsQuotasAndAcls(Reconciliation reconciliation, KafkaUserModel user, KafkaUserStatus userStatus) {
    Set<SimpleAclRule> tlsAcls = null;
    Set<SimpleAclRule> scramOrNoneAcls = null;
    KafkaUserQuotas tlsQuotas = null;
    KafkaUserQuotas scramOrNoneQuotas = null;
    if (user.isTlsUser() || user.isTlsExternalUser()) {
        tlsAcls = user.getSimpleAclRules();
        tlsQuotas = user.getQuotas();
    } else if (user.isScramUser() || user.isNoneUser()) {
        scramOrNoneAcls = user.getSimpleAclRules();
        scramOrNoneQuotas = user.getQuotas();
    }
    // Reconcile the user SCRAM-SHA-512 credentials
    Future<ReconcileResult<String>> scramCredentialsFuture = scramCredentialsOperator.reconcile(reconciliation, user.getName(), user.getScramSha512Password());
    // Quotas need to reconciled for both regular and TLS username. It will be (possibly) set for one user and deleted for the other
    Future<ReconcileResult<KafkaUserQuotas>> tlsQuotasFuture = quotasOperator.reconcile(reconciliation, KafkaUserModel.getTlsUserName(reconciliation.name()), tlsQuotas);
    Future<ReconcileResult<KafkaUserQuotas>> quotasFuture = quotasOperator.reconcile(reconciliation, KafkaUserModel.getScramUserName(reconciliation.name()), scramOrNoneQuotas);
    // Reconcile the user secret generated by the user operator with the credentials
    Future<ReconcileResult<Secret>> userSecretFuture = reconcileUserSecret(reconciliation, user, userStatus);
    // ACLs need to reconciled for both regular and TLS username. It will be (possibly) set for one user and deleted for the other
    Future<ReconcileResult<Set<SimpleAclRule>>> aclsTlsUserFuture;
    Future<ReconcileResult<Set<SimpleAclRule>>> aclsScramUserFuture;
    if (config.isAclsAdminApiSupported()) {
        aclsTlsUserFuture = aclOperations.reconcile(reconciliation, KafkaUserModel.getTlsUserName(reconciliation.name()), tlsAcls);
        aclsScramUserFuture = aclOperations.reconcile(reconciliation, KafkaUserModel.getScramUserName(reconciliation.name()), scramOrNoneAcls);
    } else {
        aclsTlsUserFuture = Future.succeededFuture(ReconcileResult.noop(null));
        aclsScramUserFuture = Future.succeededFuture(ReconcileResult.noop(null));
    }
    return CompositeFuture.join(scramCredentialsFuture, tlsQuotasFuture, quotasFuture, aclsTlsUserFuture, aclsScramUserFuture, userSecretFuture);
}
Also used : KafkaUserQuotas(io.strimzi.api.kafka.model.KafkaUserQuotas) ReconcileResult(io.strimzi.operator.common.operator.resource.ReconcileResult) SimpleAclRule(io.strimzi.operator.user.model.acl.SimpleAclRule)

Example 3 with KafkaUserQuotas

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

the class KafkaUserModelTest method testFromCrdQuotaUser.

@Test
public void testFromCrdQuotaUser() {
    KafkaUserModel model = KafkaUserModel.fromCrd(quotasUser, UserOperatorConfig.DEFAULT_SECRET_PREFIX, UserOperatorConfig.DEFAULT_STRIMZI_ACLS_ADMIN_API_SUPPORTED);
    assertThat(model.namespace, is(ResourceUtils.NAMESPACE));
    assertThat(model.name, is(ResourceUtils.NAME));
    assertThat(model.labels, is(Labels.fromMap(ResourceUtils.LABELS).withStrimziKind(KafkaUser.RESOURCE_KIND).withKubernetesName(KafkaUserModel.KAFKA_USER_OPERATOR_NAME).withKubernetesInstance(ResourceUtils.NAME).withKubernetesPartOf(ResourceUtils.NAME).withKubernetesManagedBy(KafkaUserModel.KAFKA_USER_OPERATOR_NAME)));
    KafkaUserQuotas quotas = quotasUser.getSpec().getQuotas();
    assertThat(model.getQuotas().getConsumerByteRate(), is(quotas.getConsumerByteRate()));
    assertThat(model.getQuotas().getProducerByteRate(), is(quotas.getProducerByteRate()));
    assertThat(model.getQuotas().getRequestPercentage(), is(quotas.getRequestPercentage()));
    assertThat(model.getQuotas().getControllerMutationRate(), is(quotas.getControllerMutationRate()));
}
Also used : KafkaUserQuotas(io.strimzi.api.kafka.model.KafkaUserQuotas) Test(org.junit.jupiter.api.Test)

Example 4 with KafkaUserQuotas

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

the class QuotasOperator method getAsync.

/**
 * Retrieves the quotas for the given user.
 *
 * @param reconciliation The reconciliation
 * @param username Name of the user
 *
 * @return the Future with reconcile result
 */
protected Future<KafkaUserQuotas> getAsync(Reconciliation reconciliation, String username) {
    ClientQuotaFilterComponent c = ClientQuotaFilterComponent.ofEntity(ClientQuotaEntity.USER, username);
    ClientQuotaFilter f = ClientQuotaFilter.contains(List.of(c));
    return Util.kafkaFutureToVertxFuture(reconciliation, vertx, adminClient.describeClientQuotas(f).entities()).compose(quotas -> {
        ClientQuotaEntity cqe = new ClientQuotaEntity(Map.of(ClientQuotaEntity.USER, username));
        KafkaUserQuotas current = null;
        if (quotas.containsKey(cqe)) {
            current = QuotaUtils.fromClientQuota(quotas.get(cqe));
        }
        return Future.succeededFuture(current);
    });
}
Also used : ClientQuotaFilter(org.apache.kafka.common.quota.ClientQuotaFilter) ClientQuotaFilterComponent(org.apache.kafka.common.quota.ClientQuotaFilterComponent) KafkaUserQuotas(io.strimzi.api.kafka.model.KafkaUserQuotas) ClientQuotaEntity(org.apache.kafka.common.quota.ClientQuotaEntity)

Example 5 with KafkaUserQuotas

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

the class QuotasOperatorIT method getOriginal.

@Override
KafkaUserQuotas getOriginal() {
    KafkaUserQuotas quotas = new KafkaUserQuotas();
    quotas.setProducerByteRate(1024 * 1024);
    quotas.setConsumerByteRate(10 * 1024 * 1024);
    quotas.setRequestPercentage(55);
    quotas.setControllerMutationRate(100.0);
    return quotas;
}
Also used : KafkaUserQuotas(io.strimzi.api.kafka.model.KafkaUserQuotas)

Aggregations

KafkaUserQuotas (io.strimzi.api.kafka.model.KafkaUserQuotas)16 SimpleAclRule (io.strimzi.operator.user.model.acl.SimpleAclRule)4 Test (org.junit.jupiter.api.Test)4 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)2 Secret (io.fabric8.kubernetes.api.model.Secret)2 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)2 KafkaUser (io.strimzi.api.kafka.model.KafkaUser)2 KafkaUserBuilder (io.strimzi.api.kafka.model.KafkaUserBuilder)2 Condition (io.strimzi.api.kafka.model.status.Condition)2 KafkaUserStatus (io.strimzi.api.kafka.model.status.KafkaUserStatus)2 CertManager (io.strimzi.certs.CertManager)2 Reconciliation (io.strimzi.operator.common.Reconciliation)2 Labels (io.strimzi.operator.common.model.Labels)2 MockCertManager (io.strimzi.operator.common.operator.MockCertManager)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 ResourceUtils (io.strimzi.operator.user.ResourceUtils)2 KafkaUserModel (io.strimzi.operator.user.model.KafkaUserModel)2 Future (io.vertx.core.Future)2