Search in sources :

Example 16 with EntityOperatorSpec

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;
}
Also used : KafkaClusterSpec(io.strimzi.api.kafka.model.KafkaClusterSpec) EntityOperatorSpec(io.strimzi.api.kafka.model.EntityOperatorSpec) EntityOperatorTemplate(io.strimzi.api.kafka.model.template.EntityOperatorTemplate) TlsSidecar(io.strimzi.api.kafka.model.TlsSidecar)

Example 17 with EntityOperatorSpec

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;
}
Also used : EntityOperatorSpec(io.strimzi.api.kafka.model.EntityOperatorSpec) EntityUserOperatorSpec(io.strimzi.api.kafka.model.EntityUserOperatorSpec)

Example 18 with EntityOperatorSpec

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()));
}
Also used : EntityOperatorSpec(io.strimzi.api.kafka.model.EntityOperatorSpec) Reconciliation(io.strimzi.operator.common.Reconciliation) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) EntityOperatorSpecBuilder(io.strimzi.api.kafka.model.EntityOperatorSpecBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 19 with EntityOperatorSpec

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;
}
Also used : EntityOperatorSpec(io.strimzi.api.kafka.model.EntityOperatorSpec) ArrayList(java.util.ArrayList) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) EntityOperatorSpecBuilder(io.strimzi.api.kafka.model.EntityOperatorSpecBuilder) EntityTopicOperatorSpecBuilder(io.strimzi.api.kafka.model.EntityTopicOperatorSpecBuilder) GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) SingleVolumeStorage(io.strimzi.api.kafka.model.storage.SingleVolumeStorage) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) EphemeralStorage(io.strimzi.api.kafka.model.storage.EphemeralStorage) Map(java.util.Map) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) HashMap(java.util.HashMap) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap) EntityUserOperatorSpecBuilder(io.strimzi.api.kafka.model.EntityUserOperatorSpecBuilder)

Example 20 with EntityOperatorSpec

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;
}
Also used : EntityOperatorSpec(io.strimzi.api.kafka.model.EntityOperatorSpec) EntityTopicOperatorSpec(io.strimzi.api.kafka.model.EntityTopicOperatorSpec)

Aggregations

EntityOperatorSpec (io.strimzi.api.kafka.model.EntityOperatorSpec)22 EntityOperatorSpecBuilder (io.strimzi.api.kafka.model.EntityOperatorSpecBuilder)14 Kafka (io.strimzi.api.kafka.model.Kafka)12 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)12 Reconciliation (io.strimzi.operator.common.Reconciliation)12 ParallelTest (io.strimzi.test.annotations.ParallelTest)12 EntityUserOperatorSpec (io.strimzi.api.kafka.model.EntityUserOperatorSpec)6 EntityUserOperatorSpecBuilder (io.strimzi.api.kafka.model.EntityUserOperatorSpecBuilder)6 EntityTopicOperatorSpec (io.strimzi.api.kafka.model.EntityTopicOperatorSpec)4 EntityTopicOperatorSpecBuilder (io.strimzi.api.kafka.model.EntityTopicOperatorSpecBuilder)4 KafkaClusterSpec (io.strimzi.api.kafka.model.KafkaClusterSpec)4 HashMap (java.util.HashMap)4 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)2 CertificateAuthority (io.strimzi.api.kafka.model.CertificateAuthority)2 TlsSidecar (io.strimzi.api.kafka.model.TlsSidecar)2 ZookeeperClusterSpec (io.strimzi.api.kafka.model.ZookeeperClusterSpec)2 GenericKafkaListener (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener)2 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)2 EphemeralStorage (io.strimzi.api.kafka.model.storage.EphemeralStorage)2