Search in sources :

Example 76 with TestStorage

use of io.strimzi.systemtest.storage.TestStorage in project strimzi-kafka-operator by strimzi.

the class RollingUpdateST method testMetricsChange.

@IsolatedTest
@Tag(ROLLING_UPDATE)
@KRaftNotSupported("Zookeeper is not supported by KRaft mode and is used in this test class")
@SuppressWarnings("checkstyle:MethodLength")
void testMetricsChange(ExtensionContext extensionContext) throws JsonProcessingException {
    final TestStorage testStorage = new TestStorage(extensionContext, namespace);
    // Kafka
    Map<String, Object> kafkaRule = new HashMap<>();
    kafkaRule.put("pattern", "kafka.(\\w+)<type=(.+), name=(.+)><>Count");
    kafkaRule.put("name", "kafka_$1_$2_$3_count");
    kafkaRule.put("type", "COUNTER");
    Map<String, Object> kafkaMetrics = new HashMap<>();
    kafkaMetrics.put("lowercaseOutputName", true);
    kafkaMetrics.put("rules", Collections.singletonList(kafkaRule));
    String metricsCMNameK = "k-metrics-cm";
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    String yaml = mapper.writeValueAsString(kafkaMetrics);
    ConfigMap metricsCMK = new ConfigMapBuilder().withNewMetadata().withName(metricsCMNameK).withNamespace(testStorage.getNamespaceName()).endMetadata().withData(singletonMap("metrics-config.yml", yaml)).build();
    JmxPrometheusExporterMetrics kafkaMetricsConfig = new JmxPrometheusExporterMetricsBuilder().withNewValueFrom().withConfigMapKeyRef(new ConfigMapKeySelectorBuilder().withName(metricsCMNameK).withKey("metrics-config.yml").withOptional(true).build()).endValueFrom().build();
    // Zookeeper
    Map<String, Object> zookeeperLabels = new HashMap<>();
    zookeeperLabels.put("replicaId", "$2");
    Map<String, Object> zookeeperRule = new HashMap<>();
    zookeeperRule.put("labels", zookeeperLabels);
    zookeeperRule.put("name", "zookeeper_$3");
    zookeeperRule.put("pattern", "org.apache.ZooKeeperService<name0=ReplicatedServer_id(\\d+), name1=replica.(\\d+)><>(\\w+)");
    Map<String, Object> zookeeperMetrics = new HashMap<>();
    zookeeperMetrics.put("lowercaseOutputName", true);
    zookeeperMetrics.put("rules", Collections.singletonList(zookeeperRule));
    String metricsCMNameZk = "zk-metrics-cm";
    ConfigMap metricsCMZk = new ConfigMapBuilder().withNewMetadata().withName(metricsCMNameZk).withNamespace(testStorage.getNamespaceName()).endMetadata().withData(singletonMap("metrics-config.yml", mapper.writeValueAsString(zookeeperMetrics))).build();
    JmxPrometheusExporterMetrics zkMetricsConfig = new JmxPrometheusExporterMetricsBuilder().withNewValueFrom().withConfigMapKeyRef(new ConfigMapKeySelectorBuilder().withName(metricsCMNameZk).withKey("metrics-config.yml").withOptional(true).build()).endValueFrom().build();
    kubeClient().getClient().configMaps().inNamespace(testStorage.getNamespaceName()).createOrReplace(metricsCMK);
    kubeClient().getClient().configMaps().inNamespace(testStorage.getNamespaceName()).createOrReplace(metricsCMZk);
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(testStorage.getClusterName(), 3, 3).editMetadata().withNamespace(testStorage.getNamespaceName()).endMetadata().editSpec().editKafka().withMetricsConfig(kafkaMetricsConfig).endKafka().editOrNewZookeeper().withMetricsConfig(zkMetricsConfig).endZookeeper().withNewKafkaExporter().endKafkaExporter().endSpec().build());
    Map<String, String> kafkaPods = PodUtils.podSnapshot(testStorage.getNamespaceName(), testStorage.getKafkaSelector());
    Map<String, String> zkPods = PodUtils.podSnapshot(testStorage.getNamespaceName(), testStorage.getZookeeperSelector());
    resourceManager.createResource(extensionContext, ScraperTemplates.scraperPod(testStorage.getNamespaceName(), testStorage.getScraperName()).build());
    String metricsScraperPodName = PodUtils.getPodsByPrefixInNameWithDynamicWait(testStorage.getNamespaceName(), testStorage.getScraperName()).get(0).getMetadata().getName();
    MetricsCollector metricsCollector = new MetricsCollector.Builder().withNamespaceName(testStorage.getNamespaceName()).withScraperPodName(metricsScraperPodName).withComponentName(testStorage.getClusterName()).withComponentType(ComponentType.Kafka).build();
    LOGGER.info("Check if metrics are present in pod of Kafka and Zookeeper");
    Map<String, String> kafkaMetricsOutput = metricsCollector.collectMetricsFromPods();
    Map<String, String> zkMetricsOutput = metricsCollector.toBuilder().withComponentType(ComponentType.Zookeeper).build().collectMetricsFromPods();
    assertThat(kafkaMetricsOutput.values().toString().contains("kafka_"), is(true));
    assertThat(zkMetricsOutput.values().toString().contains("replicaId"), is(true));
    LOGGER.info("Changing metrics to something else");
    kafkaRule.replace("pattern", "kafka.(\\w+)<type=(.+), name=(.+)><>Count", "kafka.(\\w+)<type=(.+), name=(.+)Percent\\w*><>MeanRate");
    kafkaRule.replace("name", "kafka_$1_$2_$3_count", "kafka_$1_$2_$3_percent");
    kafkaRule.replace("type", "COUNTER", "GAUGE");
    zookeeperRule.replace("pattern", "org.apache.ZooKeeperService<name0=ReplicatedServer_id(\\d+), name1=replica.(\\d+)><>(\\w+)", "org.apache.ZooKeeperService<name0=StandaloneServer_port(\\d+)><>(\\w+)");
    zookeeperRule.replace("name", "zookeeper_$3", "zookeeper_$2");
    zookeeperRule.replace("labels", zookeeperLabels, null);
    metricsCMZk = new ConfigMapBuilder().withNewMetadata().withName(metricsCMNameZk).withNamespace(testStorage.getNamespaceName()).endMetadata().withData(singletonMap("metrics-config.yml", mapper.writeValueAsString(zookeeperMetrics))).build();
    metricsCMK = new ConfigMapBuilder().withNewMetadata().withName(metricsCMNameK).withNamespace(testStorage.getNamespaceName()).endMetadata().withData(singletonMap("metrics-config.yml", mapper.writeValueAsString(kafkaMetrics))).build();
    kubeClient().getClient().configMaps().inNamespace(testStorage.getNamespaceName()).createOrReplace(metricsCMK);
    kubeClient().getClient().configMaps().inNamespace(testStorage.getNamespaceName()).createOrReplace(metricsCMZk);
    PodUtils.verifyThatRunningPodsAreStable(testStorage.getNamespaceName(), KafkaResources.zookeeperStatefulSetName(testStorage.getClusterName()));
    PodUtils.verifyThatRunningPodsAreStable(testStorage.getNamespaceName(), KafkaResources.kafkaStatefulSetName(testStorage.getClusterName()));
    LOGGER.info("Check if Kafka and Zookeeper pods didn't roll");
    assertThat(PodUtils.podSnapshot(testStorage.getNamespaceName(), testStorage.getZookeeperSelector()), is(zkPods));
    assertThat(PodUtils.podSnapshot(testStorage.getNamespaceName(), testStorage.getKafkaSelector()), is(kafkaPods));
    LOGGER.info("Check if Kafka and Zookeeper metrics are changed");
    ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
    String kafkaMetricsConf = kubeClient().getClient().configMaps().inNamespace(testStorage.getNamespaceName()).withName(metricsCMNameK).get().getData().get("metrics-config.yml");
    String zkMetricsConf = kubeClient().getClient().configMaps().inNamespace(testStorage.getNamespaceName()).withName(metricsCMNameZk).get().getData().get("metrics-config.yml");
    Object kafkaMetricsJsonToYaml = yamlReader.readValue(kafkaMetricsConf, Object.class);
    Object zkMetricsJsonToYaml = yamlReader.readValue(zkMetricsConf, Object.class);
    ObjectMapper jsonWriter = new ObjectMapper();
    for (String cmName : StUtils.getKafkaConfigurationConfigMaps(testStorage.getClusterName(), 3)) {
        assertThat(kubeClient().getClient().configMaps().inNamespace(testStorage.getNamespaceName()).withName(cmName).get().getData().get(Constants.METRICS_CONFIG_JSON_NAME), is(jsonWriter.writeValueAsString(kafkaMetricsJsonToYaml)));
    }
    assertThat(kubeClient().getClient().configMaps().inNamespace(testStorage.getNamespaceName()).withName(KafkaResources.zookeeperMetricsAndLogConfigMapName(testStorage.getClusterName())).get().getData().get(Constants.METRICS_CONFIG_JSON_NAME), is(jsonWriter.writeValueAsString(zkMetricsJsonToYaml)));
    LOGGER.info("Check if metrics are present in pod of Kafka and Zookeeper");
    kafkaMetricsOutput = metricsCollector.collectMetricsFromPods();
    zkMetricsOutput = metricsCollector.toBuilder().withComponentType(ComponentType.Zookeeper).build().collectMetricsFromPods();
    assertThat(kafkaMetricsOutput.values().toString().contains("kafka_"), is(true));
    assertThat(zkMetricsOutput.values().toString().contains("replicaId"), is(true));
    LOGGER.info("Removing metrics from Kafka and Zookeeper and setting them to null");
    KafkaResource.replaceKafkaResourceInSpecificNamespace(testStorage.getClusterName(), kafka -> {
        kafka.getSpec().getKafka().setMetricsConfig(null);
        kafka.getSpec().getZookeeper().setMetricsConfig(null);
    }, testStorage.getNamespaceName());
    LOGGER.info("Wait if Kafka and Zookeeper pods will roll");
    RollingUpdateUtils.waitTillComponentHasRolledAndPodsReady(testStorage.getNamespaceName(), testStorage.getZookeeperSelector(), 3, zkPods);
    RollingUpdateUtils.waitTillComponentHasRolled(testStorage.getNamespaceName(), testStorage.getKafkaSelector(), 3, kafkaPods);
    LOGGER.info("Check if metrics are not existing in pods");
    kafkaMetricsOutput = metricsCollector.collectMetricsFromPodsWithoutWait();
    zkMetricsOutput = metricsCollector.toBuilder().withComponentType(ComponentType.Zookeeper).build().collectMetricsFromPodsWithoutWait();
    kafkaMetricsOutput.values().forEach(value -> assertThat(value, is("")));
    zkMetricsOutput.values().forEach(value -> assertThat(value, is("")));
}
Also used : MetricsCollector(io.strimzi.systemtest.metrics.MetricsCollector) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) HashMap(java.util.HashMap) ConfigMapKeySelectorBuilder(io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder) JmxPrometheusExporterMetrics(io.strimzi.api.kafka.model.JmxPrometheusExporterMetrics) JmxPrometheusExporterMetricsBuilder(io.strimzi.api.kafka.model.JmxPrometheusExporterMetricsBuilder) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) TestStorage(io.strimzi.systemtest.storage.TestStorage) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) KRaftNotSupported(io.strimzi.systemtest.annotations.KRaftNotSupported) IsolatedTest(io.strimzi.systemtest.annotations.IsolatedTest) Tag(org.junit.jupiter.api.Tag)

Example 77 with TestStorage

use of io.strimzi.systemtest.storage.TestStorage in project strimzi-kafka-operator by strimzi.

the class PodSetIsolatedST method testPodSetOnlyReconciliation.

@IsolatedTest("We are changing CO env variables in this test")
void testPodSetOnlyReconciliation(ExtensionContext extensionContext) {
    final TestStorage testStorage = new TestStorage(extensionContext);
    final Map<String, String> coPod = DeploymentUtils.depSnapshot(clusterOperator.getDeploymentNamespace(), STRIMZI_DEPLOYMENT_NAME);
    final int replicas = 3;
    final int probeTimeoutSeconds = 6;
    EnvVar reconciliationEnv = new EnvVar(Environment.STRIMZI_POD_SET_RECONCILIATION_ONLY_ENV, "true", null);
    List<EnvVar> envVars = kubeClient().getDeployment(clusterOperator.getDeploymentNamespace(), Constants.STRIMZI_DEPLOYMENT_NAME).getSpec().getTemplate().getSpec().getContainers().get(0).getEnv();
    envVars.addAll(INITIAL_ENV_VARS);
    envVars.add(reconciliationEnv);
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaPersistent(testStorage.getClusterName(), replicas).build());
    LOGGER.info("Changing {} to 'true', so only SPS will be reconciled", Environment.STRIMZI_POD_SET_RECONCILIATION_ONLY_ENV);
    DeploymentResource.replaceDeployment(Constants.STRIMZI_DEPLOYMENT_NAME, coDep -> coDep.getSpec().getTemplate().getSpec().getContainers().get(0).setEnv(envVars), clusterOperator.getDeploymentNamespace());
    DeploymentUtils.waitTillDepHasRolled(clusterOperator.getDeploymentNamespace(), STRIMZI_DEPLOYMENT_NAME, 1, coPod);
    Map<String, String> kafkaPods = PodUtils.podSnapshot(testStorage.getNamespaceName(), testStorage.getKafkaSelector());
    Map<String, String> zkPods = PodUtils.podSnapshot(testStorage.getNamespaceName(), testStorage.getZookeeperSelector());
    LOGGER.info("Changing Kafka resource configuration, the pods should not be rolled");
    KafkaResource.replaceKafkaResourceInSpecificNamespace(testStorage.getClusterName(), kafka -> {
        kafka.getSpec().getZookeeper().setReadinessProbe(new ProbeBuilder().withTimeoutSeconds(probeTimeoutSeconds).build());
        kafka.getSpec().getKafka().setReadinessProbe(new ProbeBuilder().withTimeoutSeconds(probeTimeoutSeconds).build());
    }, testStorage.getNamespaceName());
    RollingUpdateUtils.waitForNoKafkaAndZKRollingUpdate(testStorage.getNamespaceName(), testStorage.getClusterName(), kafkaPods, zkPods);
    LOGGER.info("Deleting one Kafka and one ZK pod, the should be recreated");
    kubeClient().deletePodWithName(testStorage.getNamespaceName(), KafkaResources.kafkaPodName(testStorage.getClusterName(), 0));
    PodUtils.waitForPodsReady(testStorage.getNamespaceName(), testStorage.getKafkaSelector(), replicas, true);
    kubeClient().deletePodWithName(testStorage.getNamespaceName(), KafkaResources.zookeeperPodName(testStorage.getClusterName(), 0));
    PodUtils.waitForPodsReady(testStorage.getNamespaceName(), testStorage.getZookeeperSelector(), replicas, true);
    kafkaPods = PodUtils.podSnapshot(testStorage.getNamespaceName(), testStorage.getKafkaSelector());
    zkPods = PodUtils.podSnapshot(testStorage.getNamespaceName(), testStorage.getZookeeperSelector());
    LOGGER.info("Removing {} env from CO", Environment.STRIMZI_POD_SET_RECONCILIATION_ONLY_ENV);
    envVars.remove(reconciliationEnv);
    DeploymentResource.replaceDeployment(Constants.STRIMZI_DEPLOYMENT_NAME, coDep -> coDep.getSpec().getTemplate().getSpec().getContainers().get(0).setEnv(envVars), clusterOperator.getDeploymentNamespace());
    DeploymentUtils.waitTillDepHasRolled(clusterOperator.getDeploymentNamespace(), STRIMZI_DEPLOYMENT_NAME, 1, coPod);
    LOGGER.info("Because the configuration was changed, pods should be rolled");
    RollingUpdateUtils.waitTillComponentHasRolledAndPodsReady(testStorage.getNamespaceName(), testStorage.getZookeeperSelector(), replicas, kafkaPods);
    RollingUpdateUtils.waitTillComponentHasRolledAndPodsReady(testStorage.getNamespaceName(), testStorage.getKafkaSelector(), replicas, zkPods);
}
Also used : ProbeBuilder(io.strimzi.api.kafka.model.ProbeBuilder) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) TestStorage(io.strimzi.systemtest.storage.TestStorage) IsolatedTest(io.strimzi.systemtest.annotations.IsolatedTest)

Example 78 with TestStorage

use of io.strimzi.systemtest.storage.TestStorage in project strimzi-kafka-operator by strimzi.

the class ListenersST method testCustomChainCertificatesForRoute.

@ParallelNamespaceTest
@Tag(EXTERNAL_CLIENTS_USED)
@Tag(INTERNAL_CLIENTS_USED)
@OpenShiftOnly
@KRaftNotSupported("UserOperator is not supported by KRaft mode and is used in this test case")
void testCustomChainCertificatesForRoute(ExtensionContext extensionContext) {
    final TestStorage testStorage = new TestStorage(extensionContext);
    final String clusterCustomCertChain1 = testStorage.getClusterName() + "-" + customCertChain1;
    final String clusterCustomRootCA1 = testStorage.getClusterName() + "-" + customRootCA1;
    SecretUtils.createCustomSecret(clusterCustomCertChain1, testStorage.getClusterName(), testStorage.getNamespaceName(), CHAIN_CERT_AND_KEY_1);
    SecretUtils.createCustomSecret(clusterCustomRootCA1, testStorage.getClusterName(), testStorage.getNamespaceName(), ROOT_CA_CERT_AND_KEY_1);
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(testStorage.getClusterName(), 3).editSpec().editKafka().withListeners(new GenericKafkaListenerBuilder().withName(Constants.TLS_LISTENER_DEFAULT_NAME).withPort(9112).withType(KafkaListenerType.INTERNAL).withTls(true).withNewConfiguration().withNewBrokerCertChainAndKey().withSecretName(clusterCustomCertChain1).withKey("ca.key").withCertificate("ca.crt").endBrokerCertChainAndKey().endConfiguration().build(), new GenericKafkaListenerBuilder().withName(Constants.EXTERNAL_LISTENER_DEFAULT_NAME).withPort(9113).withType(KafkaListenerType.ROUTE).withTls(true).withNewConfiguration().withNewBrokerCertChainAndKey().withSecretName(clusterCustomCertChain1).withKey("ca.key").withCertificate("ca.crt").endBrokerCertChainAndKey().endConfiguration().build()).endKafka().endSpec().build());
    resourceManager.createResource(extensionContext, KafkaUserTemplates.tlsUser(testStorage.getClusterName(), testStorage.getUserName()).build());
    ExternalKafkaClient externalKafkaClient = new ExternalKafkaClient.Builder().withTopicName(testStorage.getTopicName()).withNamespaceName(testStorage.getNamespaceName()).withClusterName(testStorage.getClusterName()).withKafkaUsername(testStorage.getUserName()).withMessageCount(MESSAGE_COUNT).withCertificateAuthorityCertificateName(clusterCustomRootCA1).withSecurityProtocol(SecurityProtocol.SSL).withListenerName(Constants.EXTERNAL_LISTENER_DEFAULT_NAME).build();
    externalKafkaClient.verifyProducedAndConsumedMessages(externalKafkaClient.sendMessagesTls(), externalKafkaClient.receiveMessagesTls());
    KafkaClients kafkaClients = new KafkaClientsBuilder().withNamespaceName(testStorage.getNamespaceName()).withTopicName(testStorage.getTopicName()).withBootstrapAddress(KafkaResources.bootstrapServiceName(testStorage.getClusterName()) + ":9112").withMessageCount(MESSAGE_COUNT).withUserName(testStorage.getUserName()).withProducerName(testStorage.getProducerName()).withConsumerName(testStorage.getConsumerName()).withConsumerGroup("consumer-group-certs-6").withCaCertSecretName(clusterCustomCertChain1).build();
    resourceManager.createResource(extensionContext, kafkaClients.producerTlsStrimzi(testStorage.getClusterName()));
    ClientUtils.waitForClientSuccess(testStorage.getProducerName(), testStorage.getNamespaceName(), MESSAGE_COUNT);
    kafkaClients = new KafkaClientsBuilder(kafkaClients).withMessageCount(2 * MESSAGE_COUNT).build();
    resourceManager.createResource(extensionContext, kafkaClients.consumerTlsStrimzi(testStorage.getClusterName()));
    ClientUtils.waitForClientSuccess(testStorage.getConsumerName(), testStorage.getNamespaceName(), MESSAGE_COUNT);
}
Also used : KafkaClientsBuilder(io.strimzi.systemtest.kafkaclients.internalClients.KafkaClientsBuilder) ExternalKafkaClient(io.strimzi.systemtest.kafkaclients.externalClients.ExternalKafkaClient) KafkaClients(io.strimzi.systemtest.kafkaclients.internalClients.KafkaClients) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) TestStorage(io.strimzi.systemtest.storage.TestStorage) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) KRaftNotSupported(io.strimzi.systemtest.annotations.KRaftNotSupported) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest) Tag(org.junit.jupiter.api.Tag) OpenShiftOnly(io.strimzi.systemtest.annotations.OpenShiftOnly)

Example 79 with TestStorage

use of io.strimzi.systemtest.storage.TestStorage in project strimzi-kafka-operator by strimzi.

the class ListenersST method testSendMessagesPlainScramSha.

/**
 * Test sending messages over plain transport using scram sha auth
 */
@ParallelNamespaceTest
@Tag(INTERNAL_CLIENTS_USED)
@KRaftNotSupported("UserOperator is not supported by KRaft mode and is used in this test case")
void testSendMessagesPlainScramSha(ExtensionContext extensionContext) {
    final TestStorage testStorage = new TestStorage(extensionContext);
    // Use a Kafka with plain listener disabled
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(testStorage.getClusterName(), 3).editSpec().editKafka().withListeners(new GenericKafkaListenerBuilder().withType(KafkaListenerType.INTERNAL).withName(customListenerName).withPort(9095).withTls(false).withNewKafkaListenerAuthenticationScramSha512Auth().endKafkaListenerAuthenticationScramSha512Auth().build()).endKafka().endSpec().build());
    resourceManager.createResource(extensionContext, KafkaTopicTemplates.topic(testStorage.getClusterName(), testStorage.getTopicName()).build(), KafkaUserTemplates.scramShaUser(testStorage.getClusterName(), testStorage.getUserName()).build());
    String brokerPodLog = kubeClient(testStorage.getNamespaceName()).logsInSpecificNamespace(testStorage.getNamespaceName(), testStorage.getClusterName() + "-kafka-0", "kafka");
    Pattern p = Pattern.compile("^.*" + Pattern.quote(testStorage.getUserName()) + ".*$", Pattern.MULTILINE);
    Matcher m = p.matcher(brokerPodLog);
    boolean found = false;
    while (m.find()) {
        found = true;
        LOGGER.info("Broker pod log line about user {}: {}", testStorage.getUserName(), m.group());
    }
    if (!found) {
        LOGGER.warn("No broker pod log lines about user {}", testStorage.getUserName());
        LOGGER.info("Broker pod log:\n----\n{}\n----\n", brokerPodLog);
    }
    KafkaClients kafkaClients = new KafkaClientsBuilder().withProducerName(testStorage.getProducerName()).withConsumerName(testStorage.getConsumerName()).withNamespaceName(testStorage.getNamespaceName()).withMessageCount(MESSAGE_COUNT).withBootstrapAddress(KafkaResources.bootstrapServiceName(testStorage.getClusterName()) + ":9095").withUserName(testStorage.getUserName()).withTopicName(testStorage.getTopicName()).build();
    resourceManager.createResource(extensionContext, kafkaClients.producerScramShaPlainStrimzi(), kafkaClients.consumerScramShaPlainStrimzi());
    ClientUtils.waitForClientsSuccess(testStorage.getProducerName(), testStorage.getConsumerName(), testStorage.getNamespaceName(), MESSAGE_COUNT);
    Service kafkaService = kubeClient(testStorage.getNamespaceName()).getService(testStorage.getNamespaceName(), KafkaResources.bootstrapServiceName(testStorage.getClusterName()));
    String kafkaServiceDiscoveryAnnotation = kafkaService.getMetadata().getAnnotations().get("strimzi.io/discovery");
    JsonArray serviceDiscoveryArray = new JsonArray(kafkaServiceDiscoveryAnnotation);
    assertThat(serviceDiscoveryArray, is(StUtils.expectedServiceDiscoveryInfo(9095, "kafka", "scram-sha-512", false)));
}
Also used : KafkaClientsBuilder(io.strimzi.systemtest.kafkaclients.internalClients.KafkaClientsBuilder) JsonArray(io.vertx.core.json.JsonArray) Pattern(java.util.regex.Pattern) KafkaClients(io.strimzi.systemtest.kafkaclients.internalClients.KafkaClients) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) Matcher(java.util.regex.Matcher) Service(io.fabric8.kubernetes.api.model.Service) TestStorage(io.strimzi.systemtest.storage.TestStorage) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) KRaftNotSupported(io.strimzi.systemtest.annotations.KRaftNotSupported) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest) Tag(org.junit.jupiter.api.Tag)

Example 80 with TestStorage

use of io.strimzi.systemtest.storage.TestStorage in project strimzi-kafka-operator by strimzi.

the class ListenersST method testSendMessagesTlsScramSha.

/**
 * Test sending messages over tls transport using scram sha auth
 */
@ParallelNamespaceTest
@Tag(ACCEPTANCE)
@Tag(INTERNAL_CLIENTS_USED)
@KRaftNotSupported("UserOperator is not supported by KRaft mode and is used in this test case")
void testSendMessagesTlsScramSha(ExtensionContext extensionContext) {
    final TestStorage testStorage = new TestStorage(extensionContext);
    final int passwordLength = 25;
    // Use a Kafka with plain listener disabled
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(testStorage.getClusterName(), 3).editSpec().editKafka().withListeners(new GenericKafkaListenerBuilder().withType(KafkaListenerType.INTERNAL).withName(Constants.TLS_LISTENER_DEFAULT_NAME).withPort(9096).withTls(true).withNewKafkaListenerAuthenticationScramSha512Auth().endKafkaListenerAuthenticationScramSha512Auth().build()).endKafka().editEntityOperator().editOrNewTemplate().editOrNewUserOperatorContainer().addToEnv(new ContainerEnvVarBuilder().withName("STRIMZI_SCRAM_SHA_PASSWORD_LENGTH").withValue(String.valueOf(passwordLength)).build()).endUserOperatorContainer().endTemplate().endEntityOperator().endSpec().build());
    resourceManager.createResource(extensionContext, KafkaTopicTemplates.topic(testStorage.getClusterName(), testStorage.getTopicName()).build(), KafkaUserTemplates.scramShaUser(testStorage.getClusterName(), testStorage.getUserName()).build());
    KafkaClients kafkaClients = new KafkaClientsBuilder().withNamespaceName(testStorage.getNamespaceName()).withTopicName(testStorage.getTopicName()).withBootstrapAddress(KafkaResources.bootstrapServiceName(testStorage.getClusterName()) + ":9096").withMessageCount(MESSAGE_COUNT).withUserName(testStorage.getUserName()).withProducerName(testStorage.getProducerName()).withConsumerName(testStorage.getConsumerName()).build();
    resourceManager.createResource(extensionContext, kafkaClients.producerScramShaTlsStrimzi(testStorage.getClusterName()), kafkaClients.consumerScramShaTlsStrimzi(testStorage.getClusterName()));
    ClientUtils.waitForClientsSuccess(testStorage.getProducerName(), testStorage.getConsumerName(), testStorage.getNamespaceName(), MESSAGE_COUNT);
    LOGGER.info("Checking if generated password has {} characters", passwordLength);
    String password = kubeClient().namespace(testStorage.getNamespaceName()).getSecret(testStorage.getUserName()).getData().get("password");
    String decodedPassword = new String(Base64.getDecoder().decode(password));
    assertEquals(decodedPassword.length(), passwordLength);
    Service kafkaService = kubeClient(testStorage.getNamespaceName()).getService(testStorage.getNamespaceName(), KafkaResources.bootstrapServiceName(testStorage.getClusterName()));
    String kafkaServiceDiscoveryAnnotation = kafkaService.getMetadata().getAnnotations().get("strimzi.io/discovery");
    JsonArray serviceDiscoveryArray = new JsonArray(kafkaServiceDiscoveryAnnotation);
    assertThat(serviceDiscoveryArray, is(StUtils.expectedServiceDiscoveryInfo(9096, "kafka", "scram-sha-512", true)));
}
Also used : KafkaClientsBuilder(io.strimzi.systemtest.kafkaclients.internalClients.KafkaClientsBuilder) JsonArray(io.vertx.core.json.JsonArray) ContainerEnvVarBuilder(io.strimzi.api.kafka.model.ContainerEnvVarBuilder) KafkaClients(io.strimzi.systemtest.kafkaclients.internalClients.KafkaClients) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) Service(io.fabric8.kubernetes.api.model.Service) TestStorage(io.strimzi.systemtest.storage.TestStorage) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) KRaftNotSupported(io.strimzi.systemtest.annotations.KRaftNotSupported) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest) Tag(org.junit.jupiter.api.Tag)

Aggregations

TestStorage (io.strimzi.systemtest.storage.TestStorage)210 KafkaClientsBuilder (io.strimzi.systemtest.kafkaclients.internalClients.KafkaClientsBuilder)152 ParallelNamespaceTest (io.strimzi.systemtest.annotations.ParallelNamespaceTest)150 KafkaClients (io.strimzi.systemtest.kafkaclients.internalClients.KafkaClients)150 Tag (org.junit.jupiter.api.Tag)128 KRaftNotSupported (io.strimzi.systemtest.annotations.KRaftNotSupported)94 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)72 Matchers.containsString (org.hamcrest.Matchers.containsString)70 HashMap (java.util.HashMap)54 Secret (io.fabric8.kubernetes.api.model.Secret)46 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)46 Map (java.util.Map)34 KafkaResources (io.strimzi.api.kafka.model.KafkaResources)32 AbstractST (io.strimzi.systemtest.AbstractST)32 Constants (io.strimzi.systemtest.Constants)32 REGRESSION (io.strimzi.systemtest.Constants.REGRESSION)32 Environment (io.strimzi.systemtest.Environment)32 KafkaTemplates (io.strimzi.systemtest.templates.crd.KafkaTemplates)32 KafkaTopicTemplates (io.strimzi.systemtest.templates.crd.KafkaTopicTemplates)32 ClientUtils (io.strimzi.systemtest.utils.ClientUtils)32