use of io.strimzi.api.kafka.model.EntityOperatorSpec in project strimzi by strimzi.
the class EntityOperator method fromCrd.
/**
* Create a Entity Operator from given desired resource
*
* @param reconciliation The reconciliation
* @param kafkaAssembly desired resource with cluster configuration containing the Entity Operator one
* @param versions The versions.
* @return Entity Operator instance, null if not configured in the ConfigMap
*/
public static EntityOperator fromCrd(Reconciliation reconciliation, Kafka kafkaAssembly, KafkaVersion.Lookup versions) {
EntityOperator result = null;
EntityOperatorSpec entityOperatorSpec = kafkaAssembly.getSpec().getEntityOperator();
if (entityOperatorSpec != null) {
result = new EntityOperator(reconciliation, kafkaAssembly);
result.setOwnerReference(kafkaAssembly);
EntityTopicOperator topicOperator = EntityTopicOperator.fromCrd(reconciliation, kafkaAssembly);
EntityUserOperator userOperator = EntityUserOperator.fromCrd(reconciliation, kafkaAssembly);
TlsSidecar tlsSidecar = entityOperatorSpec.getTlsSidecar();
if (entityOperatorSpec.getTemplate() != null) {
EntityOperatorTemplate template = entityOperatorSpec.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.getTopicOperatorContainer() != null && template.getTopicOperatorContainer().getEnv() != null) {
topicOperator.setContainerEnvVars(template.getTopicOperatorContainer().getEnv());
}
if (template.getTopicOperatorContainer() != null && template.getTopicOperatorContainer().getSecurityContext() != null) {
topicOperator.setContainerSecurityContext(template.getTopicOperatorContainer().getSecurityContext());
}
if (template.getUserOperatorContainer() != null && template.getUserOperatorContainer().getEnv() != null) {
userOperator.setContainerEnvVars(template.getUserOperatorContainer().getEnv());
}
if (template.getUserOperatorContainer() != null && template.getUserOperatorContainer().getSecurityContext() != null) {
userOperator.setContainerSecurityContext(template.getUserOperatorContainer().getSecurityContext());
}
if (template.getTlsSidecarContainer() != null && template.getTlsSidecarContainer().getEnv() != null) {
result.templateTlsSidecarContainerEnvVars = template.getTlsSidecarContainer().getEnv();
}
if (template.getTlsSidecarContainer() != null && template.getTlsSidecarContainer().getSecurityContext() != null) {
result.templateTlsSidecarContainerSecurityContext = template.getTlsSidecarContainer().getSecurityContext();
}
if (template.getServiceAccount() != null && template.getServiceAccount().getMetadata() != null) {
result.templateServiceAccountLabels = template.getServiceAccount().getMetadata().getLabels();
result.templateServiceAccountAnnotations = template.getServiceAccount().getMetadata().getAnnotations();
}
}
result.setTlsSidecar(tlsSidecar);
result.setTopicOperator(topicOperator);
result.setUserOperator(userOperator);
result.setDeployed(result.getTopicOperator() != null || result.getUserOperator() != null);
String tlsSideCarImage = tlsSidecar != null ? tlsSidecar.getImage() : null;
if (tlsSideCarImage == null) {
KafkaClusterSpec kafkaClusterSpec = kafkaAssembly.getSpec().getKafka();
tlsSideCarImage = System.getenv().getOrDefault(ClusterOperatorConfig.STRIMZI_DEFAULT_TLS_SIDECAR_ENTITY_OPERATOR_IMAGE, versions.kafkaImage(kafkaClusterSpec.getImage(), versions.defaultVersion().version()));
}
result.tlsSidecarImage = tlsSideCarImage;
result.templatePodLabels = Util.mergeLabelsOrAnnotations(result.templatePodLabels, DEFAULT_POD_LABELS);
}
return result;
}
use of io.strimzi.api.kafka.model.EntityOperatorSpec in project strimzi by strimzi.
the class EntityUserOperator method fromCrd.
/**
* Create an Entity User Operator from given desired resource
*
* @param reconciliation The reconciliation
* @param kafkaAssembly desired resource with cluster configuration containing the Entity User Operator one
* @return Entity User Operator instance, null if not configured in the ConfigMap
*/
public static EntityUserOperator fromCrd(Reconciliation reconciliation, Kafka kafkaAssembly) {
EntityUserOperator result = null;
EntityOperatorSpec entityOperatorSpec = kafkaAssembly.getSpec().getEntityOperator();
if (entityOperatorSpec != null) {
EntityUserOperatorSpec userOperatorSpec = entityOperatorSpec.getUserOperator();
if (userOperatorSpec != null) {
String namespace = kafkaAssembly.getMetadata().getNamespace();
result = new EntityUserOperator(reconciliation, kafkaAssembly);
result.setOwnerReference(kafkaAssembly);
String image = userOperatorSpec.getImage();
if (image == null) {
image = System.getenv().getOrDefault(ClusterOperatorConfig.STRIMZI_DEFAULT_USER_OPERATOR_IMAGE, "quay.io/strimzi/operator:latest");
}
result.setImage(image);
result.setWatchedNamespace(userOperatorSpec.getWatchedNamespace() != null ? userOperatorSpec.getWatchedNamespace() : namespace);
result.setReconciliationIntervalMs(userOperatorSpec.getReconciliationIntervalSeconds() * 1_000);
result.setLogging(userOperatorSpec.getLogging());
result.setGcLoggingEnabled(userOperatorSpec.getJvmOptions() == null ? DEFAULT_JVM_GC_LOGGING_ENABLED : userOperatorSpec.getJvmOptions().isGcLoggingEnabled());
result.setSecretPrefix(userOperatorSpec.getSecretPrefix() == null ? EntityUserOperatorSpec.DEFAULT_SECRET_PREFIX : userOperatorSpec.getSecretPrefix());
if (userOperatorSpec.getJvmOptions() != null) {
result.setJavaSystemProperties(userOperatorSpec.getJvmOptions().getJavaSystemProperties());
}
result.setJvmOptions(userOperatorSpec.getJvmOptions());
result.setResources(userOperatorSpec.getResources());
if (userOperatorSpec.getReadinessProbe() != null) {
result.setReadinessProbe(userOperatorSpec.getReadinessProbe());
}
if (userOperatorSpec.getLivenessProbe() != null) {
result.setLivenessProbe(userOperatorSpec.getLivenessProbe());
}
if (kafkaAssembly.getSpec().getClientsCa() != null) {
if (kafkaAssembly.getSpec().getClientsCa().getValidityDays() > 0) {
result.setClientsCaValidityDays(kafkaAssembly.getSpec().getClientsCa().getValidityDays());
}
if (kafkaAssembly.getSpec().getClientsCa().getRenewalDays() > 0) {
result.setClientsCaRenewalDays(kafkaAssembly.getSpec().getClientsCa().getRenewalDays());
}
}
if (kafkaAssembly.getSpec().getKafka().getAuthorization() != null) {
// Indicates whether the Kafka Admin API for ACL management are supported by the configured authorizer
// plugin. This information is passed to the User Operator.
result.aclsAdminApiSupported = kafkaAssembly.getSpec().getKafka().getAuthorization().supportsAdminApi();
}
}
}
return result;
}
use of io.strimzi.api.kafka.model.EntityOperatorSpec in project strimzi by strimzi.
the class EntityUserOperatorTest method testFromCrdNoUserOperatorInEntityOperator.
@ParallelTest
public void testFromCrdNoUserOperatorInEntityOperator() {
EntityOperatorSpec entityOperatorSpec = new EntityOperatorSpecBuilder().build();
Kafka resource = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout)).editSpec().withEntityOperator(entityOperatorSpec).endSpec().build();
EntityUserOperator entityUserOperator = EntityUserOperator.fromCrd(new Reconciliation("test", resource.getKind(), resource.getMetadata().getNamespace(), resource.getMetadata().getName()), resource);
assertThat(entityUserOperator, is(nullValue()));
}
use of io.strimzi.api.kafka.model.EntityOperatorSpec in project strimzi by strimzi.
the class KafkaAssemblyOperatorTest method data.
public static Iterable<Params> data() {
boolean[] metricsOpenShiftAndEntityOperatorOptions = { true, false };
SingleVolumeStorage[] storageConfig = { new EphemeralStorage(), new PersistentClaimStorageBuilder().withSize("123").withStorageClass("foo").withDeleteClaim(true).build() };
List<Map<String, Object>> configs = asList(null, emptyMap(), singletonMap("foo", "bar"));
List<Params> result = new ArrayList<>();
for (boolean metricsOpenShiftAndEntityOperator : metricsOpenShiftAndEntityOperatorOptions) {
for (Map<String, Object> config : configs) {
for (SingleVolumeStorage storage : storageConfig) {
EntityOperatorSpec eoConfig;
if (metricsOpenShiftAndEntityOperator) {
eoConfig = new EntityOperatorSpecBuilder().withUserOperator(new EntityUserOperatorSpecBuilder().build()).withTopicOperator(new EntityTopicOperatorSpecBuilder().build()).build();
} else {
eoConfig = null;
}
List<GenericKafkaListener> listeners = new ArrayList<>(3);
listeners.add(new GenericKafkaListenerBuilder().withName("plain").withPort(9092).withType(KafkaListenerType.INTERNAL).withTls(false).withNewKafkaListenerAuthenticationScramSha512Auth().endKafkaListenerAuthenticationScramSha512Auth().build());
listeners.add(new GenericKafkaListenerBuilder().withName("tls").withPort(9093).withType(KafkaListenerType.INTERNAL).withTls(true).withNewKafkaListenerAuthenticationTlsAuth().endKafkaListenerAuthenticationTlsAuth().build());
if (metricsOpenShiftAndEntityOperator) {
// On OpenShift, use Routes
listeners.add(new GenericKafkaListenerBuilder().withName("external").withPort(9094).withType(KafkaListenerType.ROUTE).withTls(true).withNewKafkaListenerAuthenticationTlsAuth().endKafkaListenerAuthenticationTlsAuth().build());
} else {
// On Kube, use nodeports
listeners.add(new GenericKafkaListenerBuilder().withName("external").withPort(9094).withType(KafkaListenerType.NODEPORT).withTls(true).withNewKafkaListenerAuthenticationTlsAuth().endKafkaListenerAuthenticationTlsAuth().build());
}
result.add(new Params(metricsOpenShiftAndEntityOperator, metricsOpenShiftAndEntityOperator, listeners, config, config, storage, storage, eoConfig));
}
}
}
return result;
}
use of io.strimzi.api.kafka.model.EntityOperatorSpec in project strimzi-kafka-operator by strimzi.
the class EntityTopicOperator method fromCrd.
/**
* Create an Entity Topic Operator from given desired resource
*
* @param reconciliation The reconciliation
* @param kafkaAssembly desired resource with cluster configuration containing the Entity Topic Operator one
* @return Entity Topic Operator instance, null if not configured in the ConfigMap
*/
public static EntityTopicOperator fromCrd(Reconciliation reconciliation, Kafka kafkaAssembly) {
EntityTopicOperator result = null;
EntityOperatorSpec entityOperatorSpec = kafkaAssembly.getSpec().getEntityOperator();
if (entityOperatorSpec != null) {
EntityTopicOperatorSpec topicOperatorSpec = entityOperatorSpec.getTopicOperator();
if (topicOperatorSpec != null) {
String namespace = kafkaAssembly.getMetadata().getNamespace();
result = new EntityTopicOperator(reconciliation, kafkaAssembly);
result.setOwnerReference(kafkaAssembly);
String image = topicOperatorSpec.getImage();
if (image == null) {
image = System.getenv().getOrDefault(ClusterOperatorConfig.STRIMZI_DEFAULT_TOPIC_OPERATOR_IMAGE, "quay.io/strimzi/operator:latest");
}
result.setImage(image);
result.setWatchedNamespace(topicOperatorSpec.getWatchedNamespace() != null ? topicOperatorSpec.getWatchedNamespace() : namespace);
result.setReconciliationIntervalMs(topicOperatorSpec.getReconciliationIntervalSeconds() * 1_000);
result.setZookeeperSessionTimeoutMs(topicOperatorSpec.getZookeeperSessionTimeoutSeconds() * 1_000);
result.setTopicMetadataMaxAttempts(topicOperatorSpec.getTopicMetadataMaxAttempts());
result.setLogging(topicOperatorSpec.getLogging());
result.setGcLoggingEnabled(topicOperatorSpec.getJvmOptions() == null ? DEFAULT_JVM_GC_LOGGING_ENABLED : topicOperatorSpec.getJvmOptions().isGcLoggingEnabled());
if (topicOperatorSpec.getJvmOptions() != null) {
result.setJavaSystemProperties(topicOperatorSpec.getJvmOptions().getJavaSystemProperties());
}
result.setJvmOptions(topicOperatorSpec.getJvmOptions());
result.setResources(topicOperatorSpec.getResources());
if (topicOperatorSpec.getStartupProbe() != null) {
result.setStartupProbe(topicOperatorSpec.getStartupProbe());
}
if (topicOperatorSpec.getReadinessProbe() != null) {
result.setReadinessProbe(topicOperatorSpec.getReadinessProbe());
}
if (topicOperatorSpec.getLivenessProbe() != null) {
result.setLivenessProbe(topicOperatorSpec.getLivenessProbe());
}
}
}
return result;
}
Aggregations