Search in sources :

Example 21 with EntityUserOperatorSpec

use of io.strimzi.api.kafka.model.EntityUserOperatorSpec in project debezium by debezium.

the class FabricKafkaBuilder method defaultKafkaEntityOperatorSpec.

private static EntityOperatorSpec defaultKafkaEntityOperatorSpec() {
    EntityTopicOperatorSpec topicOperator = new EntityTopicOperatorSpec();
    EntityUserOperatorSpec userOperator = new EntityUserOperatorSpec();
    return new EntityOperatorSpecBuilder().withTopicOperator(topicOperator).withUserOperator(userOperator).build();
}
Also used : EntityTopicOperatorSpec(io.strimzi.api.kafka.model.EntityTopicOperatorSpec) EntityUserOperatorSpec(io.strimzi.api.kafka.model.EntityUserOperatorSpec) EntityOperatorSpecBuilder(io.strimzi.api.kafka.model.EntityOperatorSpecBuilder)

Example 22 with EntityUserOperatorSpec

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

the class EntityOperatorTest method testTlsSideCarContainerEnvVars.

@ParallelTest
public void testTlsSideCarContainerEnvVars() {
    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);
    List<ContainerEnvVar> testEnvs = new ArrayList<>();
    testEnvs.add(envVar1);
    testEnvs.add(envVar2);
    ContainerTemplate tlsContainer = new ContainerTemplate();
    tlsContainer.setEnv(testEnvs);
    Kafka resource = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout)).editSpec().withNewEntityOperator().withTopicOperator(entityTopicOperatorSpec).withUserOperator(entityUserOperatorSpec).withNewTemplate().withTlsSidecarContainer(tlsContainer).endTemplate().endEntityOperator().endSpec().build();
    List<EnvVar> containerEnvVars = EntityOperator.fromCrd(new Reconciliation("test", resource.getKind(), resource.getMetadata().getNamespace(), resource.getMetadata().getName()), resource, VERSIONS, true).getTlsSidecarEnvVars();
    assertThat("Failed to correctly set container environment variable: " + testEnvOneKey, containerEnvVars.stream().filter(env -> testEnvOneKey.equals(env.getName())).map(EnvVar::getValue).findFirst().orElse("").equals(testEnvOneValue), is(true));
    assertThat("Failed to correctly set container environment variable: " + testEnvTwoKey, containerEnvVars.stream().filter(env -> testEnvTwoKey.equals(env.getName())).map(EnvVar::getValue).findFirst().orElse("").equals(testEnvTwoValue), is(true));
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) CoreMatchers.is(org.hamcrest.CoreMatchers.is) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) ParallelSuite(io.strimzi.test.annotations.ParallelSuite) TlsSidecar(io.strimzi.api.kafka.model.TlsSidecar) Role(io.fabric8.kubernetes.api.model.rbac.Role) SecurityContextBuilder(io.fabric8.kubernetes.api.model.SecurityContextBuilder) Collections.singletonList(java.util.Collections.singletonList) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) TlsSidecarBuilder(io.strimzi.api.kafka.model.TlsSidecarBuilder) AfterAll(org.junit.jupiter.api.AfterAll) EntityTopicOperatorSpec(io.strimzi.api.kafka.model.EntityTopicOperatorSpec) KafkaResources(io.strimzi.api.kafka.model.KafkaResources) Map(java.util.Map) ContainerEnvVar(io.strimzi.api.kafka.model.ContainerEnvVar) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) ProbeBuilder(io.strimzi.api.kafka.model.ProbeBuilder) LabelSelectorBuilder(io.fabric8.kubernetes.api.model.LabelSelectorBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest) Matchers.allOf(org.hamcrest.Matchers.allOf) PolicyRule(io.fabric8.kubernetes.api.model.rbac.PolicyRule) Collectors(java.util.stream.Collectors) List(java.util.List) Labels(io.strimzi.operator.common.model.Labels) PodSecurityContextBuilder(io.fabric8.kubernetes.api.model.PodSecurityContextBuilder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) TlsSidecarLogLevel(io.strimzi.api.kafka.model.TlsSidecarLogLevel) TopologySpreadConstraintBuilder(io.fabric8.kubernetes.api.model.TopologySpreadConstraintBuilder) EntityUserOperatorSpecBuilder(io.strimzi.api.kafka.model.EntityUserOperatorSpecBuilder) EntityOperatorSpecBuilder(io.strimzi.api.kafka.model.EntityOperatorSpecBuilder) EntityTopicOperatorSpecBuilder(io.strimzi.api.kafka.model.EntityTopicOperatorSpecBuilder) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) ContainerTemplate(io.strimzi.api.kafka.model.template.ContainerTemplate) Container(io.fabric8.kubernetes.api.model.Container) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) HashMap(java.util.HashMap) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ArrayList(java.util.ArrayList) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) SecurityContext(io.fabric8.kubernetes.api.model.SecurityContext) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) TestUtils(io.strimzi.test.TestUtils) Collections.singletonMap(java.util.Collections.singletonMap) PolicyRuleBuilder(io.fabric8.kubernetes.api.model.rbac.PolicyRuleBuilder) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Volume(io.fabric8.kubernetes.api.model.Volume) EntityOperatorSpec(io.strimzi.api.kafka.model.EntityOperatorSpec) TestUtils.map(io.strimzi.test.TestUtils.map) TopologySpreadConstraint(io.fabric8.kubernetes.api.model.TopologySpreadConstraint) Toleration(io.fabric8.kubernetes.api.model.Toleration) EntityUserOperatorSpec(io.strimzi.api.kafka.model.EntityUserOperatorSpec) IOException(java.io.IOException) TolerationBuilder(io.fabric8.kubernetes.api.model.TolerationBuilder) Reconciliation(io.strimzi.operator.common.Reconciliation) Constants(io.strimzi.api.kafka.model.Constants) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) Kafka(io.strimzi.api.kafka.model.Kafka) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ContainerTemplate(io.strimzi.api.kafka.model.template.ContainerTemplate) Reconciliation(io.strimzi.operator.common.Reconciliation) ArrayList(java.util.ArrayList) 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) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 23 with EntityUserOperatorSpec

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

the class EntityUserOperatorTest method testFromCrdCaValidityAndRenewal.

@ParallelTest
public void testFromCrdCaValidityAndRenewal() {
    EntityUserOperatorSpec entityUserOperatorSpec = new EntityUserOperatorSpecBuilder().build();
    EntityOperatorSpec entityOperatorSpec = new EntityOperatorSpecBuilder().withUserOperator(entityUserOperatorSpec).build();
    CertificateAuthority ca = new CertificateAuthority();
    ca.setValidityDays(42);
    ca.setRenewalDays(69);
    Kafka customValues = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout)).editSpec().withEntityOperator(entityOperatorSpec).withClientsCa(ca).endSpec().build();
    EntityUserOperator entityUserOperator = EntityUserOperator.fromCrd(new Reconciliation("test", resource.getKind(), resource.getMetadata().getNamespace(), resource.getMetadata().getName()), customValues, true);
    Kafka defaultValues = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout)).editSpec().withEntityOperator(entityOperatorSpec).endSpec().build();
    EntityUserOperator entityUserOperator2 = EntityUserOperator.fromCrd(new Reconciliation("test", resource.getKind(), resource.getMetadata().getNamespace(), resource.getMetadata().getName()), defaultValues, true);
    assertThat(entityUserOperator.clientsCaValidityDays, is(42));
    assertThat(entityUserOperator.clientsCaRenewalDays, is(69));
    assertThat(entityUserOperator2.clientsCaValidityDays, is(CertificateAuthority.DEFAULT_CERTS_VALIDITY_DAYS));
    assertThat(entityUserOperator2.clientsCaRenewalDays, is(CertificateAuthority.DEFAULT_CERTS_RENEWAL_DAYS));
}
Also used : EntityOperatorSpec(io.strimzi.api.kafka.model.EntityOperatorSpec) EntityUserOperatorSpec(io.strimzi.api.kafka.model.EntityUserOperatorSpec) Reconciliation(io.strimzi.operator.common.Reconciliation) Kafka(io.strimzi.api.kafka.model.Kafka) CertificateAuthority(io.strimzi.api.kafka.model.CertificateAuthority) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) EntityUserOperatorSpecBuilder(io.strimzi.api.kafka.model.EntityUserOperatorSpecBuilder) EntityOperatorSpecBuilder(io.strimzi.api.kafka.model.EntityOperatorSpecBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 24 with EntityUserOperatorSpec

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

the class KafkaST method testRemoveUserAndTopicOperatorsFromEntityOperator.

@ParallelNamespaceTest
@KRaftNotSupported("EntityOperator is not supported by KRaft mode and is used in this test class")
void testRemoveUserAndTopicOperatorsFromEntityOperator(ExtensionContext extensionContext) {
    final String namespaceName = StUtils.getNamespaceBasedOnRbac(namespace, extensionContext);
    final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
    Instant startTime = Instant.now();
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(clusterName, 3).build());
    String eoDeploymentName = KafkaResources.entityOperatorDeploymentName(clusterName);
    KafkaResource.replaceKafkaResourceInSpecificNamespace(clusterName, k -> {
        k.getSpec().getEntityOperator().setTopicOperator(null);
        k.getSpec().getEntityOperator().setUserOperator(null);
    }, namespaceName);
    PodUtils.waitUntilPodStabilityReplicasCount(namespaceName, eoDeploymentName, 0);
    KafkaResource.replaceKafkaResourceInSpecificNamespace(clusterName, k -> {
        k.getSpec().getEntityOperator().setTopicOperator(new EntityTopicOperatorSpec());
        k.getSpec().getEntityOperator().setUserOperator(new EntityUserOperatorSpec());
    }, namespaceName);
    DeploymentUtils.waitForDeploymentReady(namespaceName, eoDeploymentName);
    // Checking that EO was created
    kubeClient().listPodsByPrefixInName(namespaceName, eoDeploymentName).forEach(pod -> {
        pod.getSpec().getContainers().forEach(container -> {
            assertThat(container.getName(), anyOf(containsString("topic-operator"), containsString("user-operator"), containsString("tls-sidecar")));
        });
    });
    Instant endTime = Instant.now();
    long duration = Duration.between(startTime, endTime).toSeconds();
    assertNoCoErrorsLogged(duration);
}
Also used : EntityTopicOperatorSpec(io.strimzi.api.kafka.model.EntityTopicOperatorSpec) EntityUserOperatorSpec(io.strimzi.api.kafka.model.EntityUserOperatorSpec) Instant(java.time.Instant) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) TestUtils.fromYamlString(io.strimzi.test.TestUtils.fromYamlString) KRaftNotSupported(io.strimzi.systemtest.annotations.KRaftNotSupported) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest)

Example 25 with EntityUserOperatorSpec

use of io.strimzi.api.kafka.model.EntityUserOperatorSpec 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)

Aggregations

EntityUserOperatorSpec (io.strimzi.api.kafka.model.EntityUserOperatorSpec)25 EntityOperatorSpec (io.strimzi.api.kafka.model.EntityOperatorSpec)18 EntityOperatorSpecBuilder (io.strimzi.api.kafka.model.EntityOperatorSpecBuilder)17 EntityUserOperatorSpecBuilder (io.strimzi.api.kafka.model.EntityUserOperatorSpecBuilder)16 Kafka (io.strimzi.api.kafka.model.Kafka)16 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)16 Reconciliation (io.strimzi.operator.common.Reconciliation)16 ParallelTest (io.strimzi.test.annotations.ParallelTest)16 EntityTopicOperatorSpec (io.strimzi.api.kafka.model.EntityTopicOperatorSpec)15 Container (io.fabric8.kubernetes.api.model.Container)12 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)12 LabelSelectorBuilder (io.fabric8.kubernetes.api.model.LabelSelectorBuilder)12 LocalObjectReference (io.fabric8.kubernetes.api.model.LocalObjectReference)12 PodSecurityContextBuilder (io.fabric8.kubernetes.api.model.PodSecurityContextBuilder)12 Quantity (io.fabric8.kubernetes.api.model.Quantity)12 SecurityContext (io.fabric8.kubernetes.api.model.SecurityContext)12 SecurityContextBuilder (io.fabric8.kubernetes.api.model.SecurityContextBuilder)12 ServiceAccount (io.fabric8.kubernetes.api.model.ServiceAccount)12 Toleration (io.fabric8.kubernetes.api.model.Toleration)12 TolerationBuilder (io.fabric8.kubernetes.api.model.TolerationBuilder)12