Search in sources :

Example 1 with KafkaExporterSpec

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

the class KafkaExporterTest method testFromConfigMapDefaultConfig.

@ParallelTest
public void testFromConfigMapDefaultConfig() {
    Kafka resource = ResourceUtils.createKafka(namespace, cluster, replicas, null, healthDelay, healthTimeout, jmxMetricsConfig, kafkaConfig, zooConfig, kafkaStorage, zkStorage, kafkaLogJson, zooLogJson, new KafkaExporterSpec(), null);
    KafkaExporter ke = KafkaExporter.fromCrd(new Reconciliation("test", resource.getKind(), resource.getMetadata().getNamespace(), resource.getMetadata().getName()), resource, VERSIONS);
    assertThat(ke.getImage(), is(KafkaVersionTestUtils.DEFAULT_KAFKA_IMAGE));
    assertThat(ke.logging, is("info"));
    assertThat(ke.groupRegex, is(".*"));
    assertThat(ke.topicRegex, is(".*"));
    assertThat(ke.saramaLoggingEnabled, is(false));
}
Also used : KafkaExporterSpec(io.strimzi.api.kafka.model.KafkaExporterSpec) Reconciliation(io.strimzi.operator.common.Reconciliation) Kafka(io.strimzi.api.kafka.model.Kafka) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 2 with KafkaExporterSpec

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

the class KafkaExporterTest method testContainerTemplateEnvVarsWithKeyConflict.

@ParallelTest
public void testContainerTemplateEnvVarsWithKeyConflict() {
    ContainerEnvVar envVar1 = new ContainerEnvVar();
    String testEnvOneKey = "TEST_ENV_1";
    String testEnvOneValue = "test.env.one";
    envVar1.setName(testEnvOneKey);
    envVar1.setValue(testEnvOneValue);
    ContainerEnvVar envVar2 = new ContainerEnvVar();
    String testEnvTwoKey = KafkaExporter.ENV_VAR_KAFKA_EXPORTER_GROUP_REGEX;
    String testEnvTwoValue = "my-special-value";
    envVar2.setName(testEnvTwoKey);
    envVar2.setValue(testEnvTwoValue);
    KafkaExporterSpec exporterSpec = new KafkaExporterSpecBuilder().withLogging(exporterOperatorLogging).withGroupRegex(groupRegex).withTopicRegex(topicRegex).withImage(keImage).withNewTemplate().withNewContainer().withEnv(envVar1, envVar2).endContainer().endTemplate().build();
    Kafka resource = ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, kafkaConfig, zooConfig, kafkaStorage, zkStorage, kafkaLogJson, zooLogJson, exporterSpec, null);
    KafkaExporter ke = KafkaExporter.fromCrd(new Reconciliation("test", resource.getKind(), resource.getMetadata().getNamespace(), resource.getMetadata().getName()), resource, VERSIONS);
    List<EnvVar> kafkaEnvVars = ke.getEnvVars();
    assertThat(kafkaEnvVars.stream().filter(var -> testEnvOneKey.equals(var.getName())).map(EnvVar::getValue).findFirst().orElseThrow(), is(testEnvOneValue));
    assertThat(kafkaEnvVars.stream().filter(var -> testEnvTwoKey.equals(var.getName())).map(EnvVar::getValue).findFirst().orElseThrow(), is(groupRegex));
}
Also used : KafkaExporterSpec(io.strimzi.api.kafka.model.KafkaExporterSpec) Reconciliation(io.strimzi.operator.common.Reconciliation) KafkaExporterSpecBuilder(io.strimzi.api.kafka.model.KafkaExporterSpecBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) ContainerEnvVar(io.strimzi.api.kafka.model.ContainerEnvVar) ContainerEnvVar(io.strimzi.api.kafka.model.ContainerEnvVar) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 3 with KafkaExporterSpec

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

the class KafkaExporter method fromCrd.

public static KafkaExporter fromCrd(Reconciliation reconciliation, Kafka kafkaAssembly, KafkaVersion.Lookup versions) {
    KafkaExporter kafkaExporter = new KafkaExporter(reconciliation, kafkaAssembly);
    KafkaExporterSpec spec = kafkaAssembly.getSpec().getKafkaExporter();
    if (spec != null) {
        kafkaExporter.isDeployed = true;
        kafkaExporter.setResources(spec.getResources());
        if (spec.getReadinessProbe() != null) {
            kafkaExporter.setReadinessProbe(spec.getReadinessProbe());
        }
        if (spec.getLivenessProbe() != null) {
            kafkaExporter.setLivenessProbe(spec.getLivenessProbe());
        }
        kafkaExporter.setGroupRegex(spec.getGroupRegex());
        kafkaExporter.setTopicRegex(spec.getTopicRegex());
        String image = spec.getImage();
        if (image == null) {
            KafkaClusterSpec kafkaClusterSpec = kafkaAssembly.getSpec().getKafka();
            image = System.getenv().getOrDefault(ClusterOperatorConfig.STRIMZI_DEFAULT_KAFKA_EXPORTER_IMAGE, versions.kafkaImage(kafkaClusterSpec.getImage(), versions.defaultVersion().version()));
        }
        kafkaExporter.setImage(image);
        kafkaExporter.setLogging(spec.getLogging());
        kafkaExporter.setSaramaLoggingEnabled(spec.getEnableSaramaLogging());
        if (spec.getTemplate() != null) {
            KafkaExporterTemplate template = spec.getTemplate();
            if (template.getDeployment() != null && template.getDeployment().getMetadata() != null) {
                kafkaExporter.templateDeploymentLabels = template.getDeployment().getMetadata().getLabels();
                kafkaExporter.templateDeploymentAnnotations = template.getDeployment().getMetadata().getAnnotations();
            }
            if (template.getContainer() != null && template.getContainer().getEnv() != null) {
                kafkaExporter.templateContainerEnvVars = template.getContainer().getEnv();
            }
            if (template.getContainer() != null && template.getContainer().getSecurityContext() != null) {
                kafkaExporter.templateContainerSecurityContext = template.getContainer().getSecurityContext();
            }
            if (template.getServiceAccount() != null && template.getServiceAccount().getMetadata() != null) {
                kafkaExporter.templateServiceAccountLabels = template.getServiceAccount().getMetadata().getLabels();
                kafkaExporter.templateServiceAccountAnnotations = template.getServiceAccount().getMetadata().getAnnotations();
            }
            ModelUtils.parsePodTemplate(kafkaExporter, template.getPod());
        }
        kafkaExporter.setVersion(versions.supportedVersion(kafkaAssembly.getSpec().getKafka().getVersion()).version());
        kafkaExporter.setOwnerReference(kafkaAssembly);
    } else {
        kafkaExporter.isDeployed = false;
    }
    kafkaExporter.templatePodLabels = Util.mergeLabelsOrAnnotations(kafkaExporter.templatePodLabels, DEFAULT_POD_LABELS);
    return kafkaExporter;
}
Also used : KafkaClusterSpec(io.strimzi.api.kafka.model.KafkaClusterSpec) KafkaExporterTemplate(io.strimzi.api.kafka.model.template.KafkaExporterTemplate) KafkaExporterSpec(io.strimzi.api.kafka.model.KafkaExporterSpec) IntOrString(io.fabric8.kubernetes.api.model.IntOrString)

Example 4 with KafkaExporterSpec

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

the class KafkaExporter method fromCrd.

public static KafkaExporter fromCrd(Reconciliation reconciliation, Kafka kafkaAssembly, KafkaVersion.Lookup versions) {
    KafkaExporter kafkaExporter = new KafkaExporter(reconciliation, kafkaAssembly);
    KafkaExporterSpec spec = kafkaAssembly.getSpec().getKafkaExporter();
    if (spec != null) {
        kafkaExporter.isDeployed = true;
        kafkaExporter.setResources(spec.getResources());
        if (spec.getReadinessProbe() != null) {
            kafkaExporter.setReadinessProbe(spec.getReadinessProbe());
        }
        if (spec.getLivenessProbe() != null) {
            kafkaExporter.setLivenessProbe(spec.getLivenessProbe());
        }
        kafkaExporter.setGroupRegex(spec.getGroupRegex());
        kafkaExporter.setTopicRegex(spec.getTopicRegex());
        String image = spec.getImage();
        if (image == null) {
            KafkaClusterSpec kafkaClusterSpec = kafkaAssembly.getSpec().getKafka();
            image = System.getenv().getOrDefault(ClusterOperatorConfig.STRIMZI_DEFAULT_KAFKA_EXPORTER_IMAGE, versions.kafkaImage(kafkaClusterSpec.getImage(), versions.defaultVersion().version()));
        }
        kafkaExporter.setImage(image);
        kafkaExporter.setLogging(spec.getLogging());
        kafkaExporter.setSaramaLoggingEnabled(spec.getEnableSaramaLogging());
        if (spec.getTemplate() != null) {
            KafkaExporterTemplate template = spec.getTemplate();
            if (template.getDeployment() != null && template.getDeployment().getMetadata() != null) {
                kafkaExporter.templateDeploymentLabels = template.getDeployment().getMetadata().getLabels();
                kafkaExporter.templateDeploymentAnnotations = template.getDeployment().getMetadata().getAnnotations();
            }
            if (template.getContainer() != null && template.getContainer().getEnv() != null) {
                kafkaExporter.templateContainerEnvVars = template.getContainer().getEnv();
            }
            if (template.getContainer() != null && template.getContainer().getSecurityContext() != null) {
                kafkaExporter.templateContainerSecurityContext = template.getContainer().getSecurityContext();
            }
            if (template.getServiceAccount() != null && template.getServiceAccount().getMetadata() != null) {
                kafkaExporter.templateServiceAccountLabels = template.getServiceAccount().getMetadata().getLabels();
                kafkaExporter.templateServiceAccountAnnotations = template.getServiceAccount().getMetadata().getAnnotations();
            }
            ModelUtils.parsePodTemplate(kafkaExporter, template.getPod());
        }
        kafkaExporter.setVersion(versions.supportedVersion(kafkaAssembly.getSpec().getKafka().getVersion()).version());
        kafkaExporter.setOwnerReference(kafkaAssembly);
    } else {
        kafkaExporter.isDeployed = false;
    }
    kafkaExporter.templatePodLabels = Util.mergeLabelsOrAnnotations(kafkaExporter.templatePodLabels, DEFAULT_POD_LABELS);
    return kafkaExporter;
}
Also used : KafkaClusterSpec(io.strimzi.api.kafka.model.KafkaClusterSpec) KafkaExporterTemplate(io.strimzi.api.kafka.model.template.KafkaExporterTemplate) KafkaExporterSpec(io.strimzi.api.kafka.model.KafkaExporterSpec) IntOrString(io.fabric8.kubernetes.api.model.IntOrString)

Example 5 with KafkaExporterSpec

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

the class KafkaAssemblyOperatorTest method getKafkaAssembly.

private Kafka getKafkaAssembly(String clusterName) {
    String clusterNamespace = "test";
    int replicas = 3;
    String image = "bar";
    int healthDelay = 120;
    int healthTimeout = 30;
    KafkaExporterSpec exporter = metrics ? new KafkaExporterSpec() : null;
    String metricsCMName = "metrics-cm";
    JmxPrometheusExporterMetrics jmxMetricsConfig = metrics ? null : io.strimzi.operator.cluster.TestUtils.getJmxPrometheusExporterMetrics("metrics-config.yml", metricsCMName);
    Kafka resource = ResourceUtils.createKafka(clusterNamespace, clusterName, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, kafkaConfig, zooConfig, kafkaStorage, zkStorage, LOG_KAFKA_CONFIG, LOG_ZOOKEEPER_CONFIG, exporter, null);
    return new KafkaBuilder(resource).editSpec().editKafka().withListeners(kafkaListeners).endKafka().withEntityOperator(eoConfig).endSpec().build();
}
Also used : JmxPrometheusExporterMetrics(io.strimzi.api.kafka.model.JmxPrometheusExporterMetrics) KafkaExporterSpec(io.strimzi.api.kafka.model.KafkaExporterSpec) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Checkpoint(io.vertx.junit5.Checkpoint)

Aggregations

KafkaExporterSpec (io.strimzi.api.kafka.model.KafkaExporterSpec)10 Kafka (io.strimzi.api.kafka.model.Kafka)8 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)6 Reconciliation (io.strimzi.operator.common.Reconciliation)6 ParallelTest (io.strimzi.test.annotations.ParallelTest)6 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)4 ContainerEnvVar (io.strimzi.api.kafka.model.ContainerEnvVar)4 KafkaExporterSpecBuilder (io.strimzi.api.kafka.model.KafkaExporterSpecBuilder)4 JmxPrometheusExporterMetrics (io.strimzi.api.kafka.model.JmxPrometheusExporterMetrics)2 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)2 KafkaClusterSpec (io.strimzi.api.kafka.model.KafkaClusterSpec)2 KafkaExporterTemplate (io.strimzi.api.kafka.model.template.KafkaExporterTemplate)2 Checkpoint (io.vertx.junit5.Checkpoint)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2