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();
}
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;
}
use of io.strimzi.api.kafka.model.KafkaExporterSpec in project strimzi by strimzi.
the class KafkaExporterTest method testContainerTemplateEnvVars.
@ParallelTest
public void testContainerTemplateEnvVars() {
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 = "TEST_ENV_2";
String testEnvTwoValue = "test.env.two";
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(testEnvTwoValue));
}
use of io.strimzi.api.kafka.model.KafkaExporterSpec in project strimzi 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();
}
use of io.strimzi.api.kafka.model.KafkaExporterSpec in project strimzi-kafka-operator 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));
}
Aggregations