use of io.strimzi.api.kafka.model.template.JmxTransTemplate 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;
}
use of io.strimzi.api.kafka.model.template.JmxTransTemplate 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;
}
Aggregations