Search in sources :

Example 1 with KafkaJmxAuthenticationPassword

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

the class JmxIsolatedST method testKafkaZookeeperAndKafkaConnectWithJMX.

@ParallelNamespaceTest
@Tag(CONNECT)
@Tag(CONNECT_COMPONENTS)
void testKafkaZookeeperAndKafkaConnectWithJMX(ExtensionContext extensionContext) {
    final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
    final String kafkaClientsName = mapWithKafkaClientNames.get(extensionContext.getDisplayName());
    final String namespaceName = StUtils.getNamespaceBasedOnRbac(INFRA_NAMESPACE, extensionContext);
    final String zkSecretName = clusterName + "-zookeeper-jmx";
    final String connectJmxSecretName = clusterName + "-kafka-connect-jmx";
    final String kafkaJmxSecretName = clusterName + "-kafka-jmx";
    Map<String, String> jmxSecretLabels = Collections.singletonMap("my-label", "my-value");
    Map<String, String> jmxSecretAnnotations = Collections.singletonMap("my-annotation", "some-value");
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(clusterName, 3).editOrNewSpec().editKafka().withNewJmxOptions().withAuthentication(new KafkaJmxAuthenticationPassword()).endJmxOptions().endKafka().editOrNewZookeeper().withNewJmxOptions().withAuthentication(new KafkaJmxAuthenticationPassword()).endJmxOptions().editOrNewTemplate().withNewJmxSecret().withNewMetadata().withLabels(jmxSecretLabels).withAnnotations(jmxSecretAnnotations).endMetadata().endJmxSecret().endTemplate().endZookeeper().endSpec().build());
    resourceManager.createResource(extensionContext, KafkaClientsTemplates.kafkaClients(false, kafkaClientsName).build());
    String clientsPodName = kubeClient().listPodsByPrefixInName(kafkaClientsName).get(0).getMetadata().getName();
    resourceManager.createResource(extensionContext, KafkaConnectTemplates.kafkaConnect(extensionContext, clusterName, 1, true).editOrNewSpec().withNewJmxOptions().withAuthentication(new KafkaJmxAuthenticationPassword()).endJmxOptions().endSpec().build());
    Secret jmxZkSecret = kubeClient().getSecret(namespaceName, zkSecretName);
    String kafkaResults = JmxUtils.collectJmxMetricsWithWait(namespaceName, KafkaResources.brokersServiceName(clusterName), kafkaJmxSecretName, clientsPodName, "bean kafka.server:type=app-info\nget -i *");
    String kafkaConnectResults = JmxUtils.collectJmxMetricsWithWait(namespaceName, KafkaConnectResources.serviceName(clusterName), connectJmxSecretName, clientsPodName, "bean kafka.connect:type=app-info\nget -i *");
    String zkBeans = JmxUtils.collectJmxMetricsWithWait(namespaceName, KafkaResources.zookeeperHeadlessServiceName(clusterName), zkSecretName, clientsPodName, "domain org.apache.ZooKeeperService\nbeans");
    String zkBean = Arrays.asList(zkBeans.split("\\n")).stream().filter(bean -> bean.matches("org.apache.ZooKeeperService:name[0-9]+=ReplicatedServer_id[0-9]+")).findFirst().get();
    String zkResults = JmxUtils.collectJmxMetricsWithWait(namespaceName, KafkaResources.zookeeperHeadlessServiceName(clusterName), zkSecretName, clientsPodName, "bean " + zkBean + "\nget -i *");
    assertThat("Result from Kafka JMX doesn't contain right version of Kafka, result: " + kafkaResults, kafkaResults, containsString("version = " + Environment.ST_KAFKA_VERSION));
    assertThat("Result from KafkaConnect JMX doesn't contain right version of Kafka, result: " + kafkaConnectResults, kafkaConnectResults, containsString("version = " + Environment.ST_KAFKA_VERSION));
    assertThat("Result from Zookeeper JMX doesn't contain right quorum size, result: " + zkResults, zkResults, containsString("QuorumSize = 3"));
    LOGGER.info("Checking that Zookeeper JMX secret is created with custom labels and annotations");
    assertTrue(jmxZkSecret.getMetadata().getLabels().entrySet().containsAll(jmxSecretLabels.entrySet()));
    assertTrue(jmxZkSecret.getMetadata().getAnnotations().entrySet().containsAll(jmxSecretAnnotations.entrySet()));
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) KafkaJmxAuthenticationPassword(io.strimzi.api.kafka.model.KafkaJmxAuthenticationPassword) Matchers.containsString(org.hamcrest.Matchers.containsString) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest) Tag(org.junit.jupiter.api.Tag)

Example 2 with KafkaJmxAuthenticationPassword

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

the class JmxIsolatedST method testKafkaZookeeperAndKafkaConnectWithJMX.

@ParallelNamespaceTest
@Tag(CONNECT)
@Tag(CONNECT_COMPONENTS)
void testKafkaZookeeperAndKafkaConnectWithJMX(ExtensionContext extensionContext) {
    final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
    final String kafkaClientsName = mapWithKafkaClientNames.get(extensionContext.getDisplayName());
    final String namespaceName = StUtils.getNamespaceBasedOnRbac(INFRA_NAMESPACE, extensionContext);
    final String zkSecretName = clusterName + "-zookeeper-jmx";
    final String connectJmxSecretName = clusterName + "-kafka-connect-jmx";
    final String kafkaJmxSecretName = clusterName + "-kafka-jmx";
    Map<String, String> jmxSecretLabels = Collections.singletonMap("my-label", "my-value");
    Map<String, String> jmxSecretAnnotations = Collections.singletonMap("my-annotation", "some-value");
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(clusterName, 3).editOrNewSpec().editKafka().withNewJmxOptions().withAuthentication(new KafkaJmxAuthenticationPassword()).endJmxOptions().endKafka().editOrNewZookeeper().withNewJmxOptions().withAuthentication(new KafkaJmxAuthenticationPassword()).endJmxOptions().editOrNewTemplate().withNewJmxSecret().withNewMetadata().withLabels(jmxSecretLabels).withAnnotations(jmxSecretAnnotations).endMetadata().endJmxSecret().endTemplate().endZookeeper().endSpec().build());
    resourceManager.createResource(extensionContext, KafkaClientsTemplates.kafkaClients(false, kafkaClientsName).build());
    String clientsPodName = kubeClient().listPodsByPrefixInName(kafkaClientsName).get(0).getMetadata().getName();
    resourceManager.createResource(extensionContext, KafkaConnectTemplates.kafkaConnect(extensionContext, clusterName, 1, true).editOrNewSpec().withNewJmxOptions().withAuthentication(new KafkaJmxAuthenticationPassword()).endJmxOptions().endSpec().build());
    Secret jmxZkSecret = kubeClient().getSecret(namespaceName, zkSecretName);
    String kafkaResults = JmxUtils.collectJmxMetricsWithWait(namespaceName, KafkaResources.brokersServiceName(clusterName), kafkaJmxSecretName, clientsPodName, "bean kafka.server:type=app-info\nget -i *");
    String kafkaConnectResults = JmxUtils.collectJmxMetricsWithWait(namespaceName, KafkaConnectResources.serviceName(clusterName), connectJmxSecretName, clientsPodName, "bean kafka.connect:type=app-info\nget -i *");
    String zkBeans = JmxUtils.collectJmxMetricsWithWait(namespaceName, KafkaResources.zookeeperHeadlessServiceName(clusterName), zkSecretName, clientsPodName, "domain org.apache.ZooKeeperService\nbeans");
    String zkBean = Arrays.asList(zkBeans.split("\\n")).stream().filter(bean -> bean.matches("org.apache.ZooKeeperService:name[0-9]+=ReplicatedServer_id[0-9]+")).findFirst().get();
    String zkResults = JmxUtils.collectJmxMetricsWithWait(namespaceName, KafkaResources.zookeeperHeadlessServiceName(clusterName), zkSecretName, clientsPodName, "bean " + zkBean + "\nget -i *");
    assertThat("Result from Kafka JMX doesn't contain right version of Kafka, result: " + kafkaResults, kafkaResults, containsString("version = " + Environment.ST_KAFKA_VERSION));
    assertThat("Result from KafkaConnect JMX doesn't contain right version of Kafka, result: " + kafkaConnectResults, kafkaConnectResults, containsString("version = " + Environment.ST_KAFKA_VERSION));
    assertThat("Result from Zookeeper JMX doesn't contain right quorum size, result: " + zkResults, zkResults, containsString("QuorumSize = 3"));
    LOGGER.info("Checking that Zookeeper JMX secret is created with custom labels and annotations");
    assertTrue(jmxZkSecret.getMetadata().getLabels().entrySet().containsAll(jmxSecretLabels.entrySet()));
    assertTrue(jmxZkSecret.getMetadata().getAnnotations().entrySet().containsAll(jmxSecretAnnotations.entrySet()));
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) KafkaJmxAuthenticationPassword(io.strimzi.api.kafka.model.KafkaJmxAuthenticationPassword) Matchers.containsString(org.hamcrest.Matchers.containsString) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest) Tag(org.junit.jupiter.api.Tag)

Example 3 with KafkaJmxAuthenticationPassword

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

the class JmxTrans method fromCrd.

public static JmxTrans fromCrd(Reconciliation reconciliation, Kafka kafkaAssembly, KafkaVersion.Lookup versions) {
    JmxTrans result = null;
    JmxTransSpec spec = kafkaAssembly.getSpec().getJmxTrans();
    if (spec != null) {
        if (kafkaAssembly.getSpec().getKafka().getJmxOptions() == null) {
            String error = String.format("Can't start up JmxTrans '%s' in '%s' as Kafka spec.kafka.jmxOptions is not specified", JmxTransResources.deploymentName(kafkaAssembly.getMetadata().getName()), kafkaAssembly.getMetadata().getNamespace());
            LOGGER.warnCr(reconciliation, error);
            throw new InvalidResourceException(error);
        }
        result = new JmxTrans(reconciliation, kafkaAssembly);
        result.isDeployed = true;
        if (kafkaAssembly.getSpec().getKafka().getJmxOptions().getAuthentication() instanceof KafkaJmxAuthenticationPassword) {
            result.isJmxAuthenticated = true;
        }
        result.loggingLevel = spec.getLogLevel() == null ? "" : spec.getLogLevel();
        result.setResources(spec.getResources());
        String image = spec.getImage();
        if (image == null) {
            image = System.getenv().getOrDefault(STRIMZI_DEFAULT_JMXTRANS_IMAGE, "quay.io/strimzi/jmxtrans:latest");
        }
        result.setImage(image);
        result.setOwnerReference(kafkaAssembly);
        if (spec.getTemplate() != null) {
            JmxTransTemplate template = spec.getTemplate();
            if (template.getDeployment() != null && template.getDeployment().getMetadata() != null) {
                result.templateDeploymentLabels = template.getDeployment().getMetadata().getLabels();
                result.templateDeploymentAnnotations = template.getDeployment().getMetadata().getAnnotations();
            }
            ModelUtils.parsePodTemplate(result, template.getPod());
            if (template.getContainer() != null && template.getContainer().getEnv() != null) {
                result.templateContainerEnvVars = template.getContainer().getEnv();
            }
            if (template.getContainer() != null && template.getContainer().getSecurityContext() != null) {
                result.templateContainerSecurityContext = template.getContainer().getSecurityContext();
            }
            if (template.getServiceAccount() != null && template.getServiceAccount().getMetadata() != null) {
                result.templateServiceAccountLabels = template.getServiceAccount().getMetadata().getLabels();
                result.templateServiceAccountAnnotations = template.getServiceAccount().getMetadata().getAnnotations();
            }
        }
        result.templatePodLabels = Util.mergeLabelsOrAnnotations(result.templatePodLabels, DEFAULT_POD_LABELS);
    }
    return result;
}
Also used : JmxTransSpec(io.strimzi.api.kafka.model.JmxTransSpec) KafkaJmxAuthenticationPassword(io.strimzi.api.kafka.model.KafkaJmxAuthenticationPassword) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) JmxTransTemplate(io.strimzi.api.kafka.model.template.JmxTransTemplate)

Example 4 with KafkaJmxAuthenticationPassword

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

the class JmxTrans method fromCrd.

public static JmxTrans fromCrd(Reconciliation reconciliation, Kafka kafkaAssembly, KafkaVersion.Lookup versions) {
    JmxTrans result = null;
    JmxTransSpec spec = kafkaAssembly.getSpec().getJmxTrans();
    if (spec != null) {
        if (kafkaAssembly.getSpec().getKafka().getJmxOptions() == null) {
            String error = String.format("Can't start up JmxTrans '%s' in '%s' as Kafka spec.kafka.jmxOptions is not specified", JmxTransResources.deploymentName(kafkaAssembly.getMetadata().getName()), kafkaAssembly.getMetadata().getNamespace());
            LOGGER.warnCr(reconciliation, error);
            throw new InvalidResourceException(error);
        }
        result = new JmxTrans(reconciliation, kafkaAssembly);
        result.isDeployed = true;
        if (kafkaAssembly.getSpec().getKafka().getJmxOptions().getAuthentication() instanceof KafkaJmxAuthenticationPassword) {
            result.isJmxAuthenticated = true;
        }
        result.loggingLevel = spec.getLogLevel() == null ? "" : spec.getLogLevel();
        result.setResources(spec.getResources());
        String image = spec.getImage();
        if (image == null) {
            image = System.getenv().getOrDefault(STRIMZI_DEFAULT_JMXTRANS_IMAGE, "quay.io/strimzi/jmxtrans:latest");
        }
        result.setImage(image);
        result.setOwnerReference(kafkaAssembly);
        if (spec.getTemplate() != null) {
            JmxTransTemplate template = spec.getTemplate();
            if (template.getDeployment() != null && template.getDeployment().getMetadata() != null) {
                result.templateDeploymentLabels = template.getDeployment().getMetadata().getLabels();
                result.templateDeploymentAnnotations = template.getDeployment().getMetadata().getAnnotations();
            }
            ModelUtils.parsePodTemplate(result, template.getPod());
            if (template.getContainer() != null && template.getContainer().getEnv() != null) {
                result.templateContainerEnvVars = template.getContainer().getEnv();
            }
            if (template.getContainer() != null && template.getContainer().getSecurityContext() != null) {
                result.templateContainerSecurityContext = template.getContainer().getSecurityContext();
            }
            if (template.getServiceAccount() != null && template.getServiceAccount().getMetadata() != null) {
                result.templateServiceAccountLabels = template.getServiceAccount().getMetadata().getLabels();
                result.templateServiceAccountAnnotations = template.getServiceAccount().getMetadata().getAnnotations();
            }
        }
        result.templatePodLabels = Util.mergeLabelsOrAnnotations(result.templatePodLabels, DEFAULT_POD_LABELS);
    }
    return result;
}
Also used : JmxTransSpec(io.strimzi.api.kafka.model.JmxTransSpec) KafkaJmxAuthenticationPassword(io.strimzi.api.kafka.model.KafkaJmxAuthenticationPassword) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) JmxTransTemplate(io.strimzi.api.kafka.model.template.JmxTransTemplate)

Aggregations

KafkaJmxAuthenticationPassword (io.strimzi.api.kafka.model.KafkaJmxAuthenticationPassword)4 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)2 Secret (io.fabric8.kubernetes.api.model.Secret)2 JmxTransSpec (io.strimzi.api.kafka.model.JmxTransSpec)2 JmxTransTemplate (io.strimzi.api.kafka.model.template.JmxTransTemplate)2 ParallelNamespaceTest (io.strimzi.systemtest.annotations.ParallelNamespaceTest)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Tag (org.junit.jupiter.api.Tag)2