Search in sources :

Example 1 with KafkaBuilder

use of io.strimzi.api.kafka.model.KafkaBuilder in project strimzi by strimzi.

the class KafkaExporterTest method testTemplate.

@ParallelTest
public void testTemplate() {
    Map<String, String> depLabels = TestUtils.map("l1", "v1", "l2", "v2", Labels.KUBERNETES_PART_OF_LABEL, "custom-part", Labels.KUBERNETES_MANAGED_BY_LABEL, "custom-managed-by");
    Map<String, String> expectedDepLabels = new HashMap<>(depLabels);
    expectedDepLabels.remove(Labels.KUBERNETES_MANAGED_BY_LABEL);
    Map<String, String> depAnots = TestUtils.map("a1", "v1", "a2", "v2");
    Map<String, String> podLabels = TestUtils.map("l3", "v3", "l4", "v4");
    Map<String, String> podAnots = TestUtils.map("a3", "v3", "a4", "v4");
    Map<String, String> saLabels = TestUtils.map("l5", "v5", "l6", "v6");
    Map<String, String> saAnots = TestUtils.map("a5", "v5", "a6", "v6");
    Affinity affinity = new AffinityBuilder().withNewNodeAffinity().withNewRequiredDuringSchedulingIgnoredDuringExecution().withNodeSelectorTerms(new NodeSelectorTermBuilder().addNewMatchExpression().withKey("key1").withOperator("In").withValues("value1", "value2").endMatchExpression().build()).endRequiredDuringSchedulingIgnoredDuringExecution().endNodeAffinity().build();
    List<Toleration> tolerations = singletonList(new TolerationBuilder().withEffect("NoExecute").withKey("key1").withOperator("Equal").withValue("value1").build());
    TopologySpreadConstraint tsc1 = new TopologySpreadConstraintBuilder().withTopologyKey("kubernetes.io/zone").withMaxSkew(1).withWhenUnsatisfiable("DoNotSchedule").withLabelSelector(new LabelSelectorBuilder().withMatchLabels(singletonMap("label", "value")).build()).build();
    TopologySpreadConstraint tsc2 = new TopologySpreadConstraintBuilder().withTopologyKey("kubernetes.io/hostname").withMaxSkew(2).withWhenUnsatisfiable("ScheduleAnyway").withLabelSelector(new LabelSelectorBuilder().withMatchLabels(singletonMap("label", "value")).build()).build();
    Kafka resource = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout)).editSpec().withNewKafkaExporter().withNewTemplate().withNewDeployment().withNewMetadata().withLabels(depLabels).withAnnotations(depAnots).endMetadata().endDeployment().withNewPod().withNewMetadata().withLabels(podLabels).withAnnotations(podAnots).endMetadata().withPriorityClassName("top-priority").withSchedulerName("my-scheduler").withAffinity(affinity).withTolerations(tolerations).withTopologySpreadConstraints(tsc1, tsc2).withEnableServiceLinks(false).endPod().withNewServiceAccount().withNewMetadata().withLabels(saLabels).withAnnotations(saAnots).endMetadata().endServiceAccount().endTemplate().endKafkaExporter().endSpec().build();
    KafkaExporter ke = KafkaExporter.fromCrd(new Reconciliation("test", resource.getKind(), resource.getMetadata().getNamespace(), resource.getMetadata().getName()), resource, VERSIONS);
    // Check Deployment
    Deployment dep = ke.generateDeployment(true, null, null);
    assertThat(dep.getMetadata().getLabels().entrySet().containsAll(expectedDepLabels.entrySet()), is(true));
    assertThat(dep.getMetadata().getAnnotations().entrySet().containsAll(depAnots.entrySet()), is(true));
    // Check Pods
    assertThat(dep.getSpec().getTemplate().getMetadata().getLabels().entrySet().containsAll(podLabels.entrySet()), is(true));
    assertThat(dep.getSpec().getTemplate().getMetadata().getAnnotations().entrySet().containsAll(podAnots.entrySet()), is(true));
    assertThat(dep.getSpec().getTemplate().getSpec().getPriorityClassName(), is("top-priority"));
    assertThat(dep.getSpec().getTemplate().getSpec().getSchedulerName(), is("my-scheduler"));
    assertThat(dep.getSpec().getTemplate().getSpec().getAffinity(), is(affinity));
    assertThat(dep.getSpec().getTemplate().getSpec().getTolerations(), is(tolerations));
    assertThat(dep.getSpec().getTemplate().getSpec().getTopologySpreadConstraints(), containsInAnyOrder(tsc1, tsc2));
    assertThat(dep.getSpec().getTemplate().getSpec().getEnableServiceLinks(), is(false));
    // Check Service Account
    ServiceAccount sa = ke.generateServiceAccount();
    assertThat(sa.getMetadata().getLabels().entrySet().containsAll(saLabels.entrySet()), is(true));
    assertThat(sa.getMetadata().getAnnotations().entrySet().containsAll(saAnots.entrySet()), is(true));
}
Also used : LabelSelectorBuilder(io.fabric8.kubernetes.api.model.LabelSelectorBuilder) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) TolerationBuilder(io.fabric8.kubernetes.api.model.TolerationBuilder) HashMap(java.util.HashMap) AffinityBuilder(io.fabric8.kubernetes.api.model.AffinityBuilder) TopologySpreadConstraint(io.fabric8.kubernetes.api.model.TopologySpreadConstraint) TopologySpreadConstraintBuilder(io.fabric8.kubernetes.api.model.TopologySpreadConstraintBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Reconciliation(io.strimzi.operator.common.Reconciliation) Toleration(io.fabric8.kubernetes.api.model.Toleration) Affinity(io.fabric8.kubernetes.api.model.Affinity) NodeSelectorTermBuilder(io.fabric8.kubernetes.api.model.NodeSelectorTermBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 2 with KafkaBuilder

use of io.strimzi.api.kafka.model.KafkaBuilder in project strimzi by strimzi.

the class KafkaClusterTest method testCruiseControlWithSingleNodeKafka.

@ParallelTest
public void testCruiseControlWithSingleNodeKafka() {
    Map<String, Object> config = new HashMap<>();
    config.put("offsets.topic.replication.factor", 1);
    config.put("transaction.state.log.replication.factor", 1);
    config.put("transaction.state.log.min.isr", 1);
    Kafka kafkaAssembly = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, configuration, emptyMap())).editSpec().editKafka().withReplicas(1).withConfig(config).endKafka().withNewCruiseControl().endCruiseControl().endSpec().build();
    InvalidResourceException ex = assertThrows(InvalidResourceException.class, () -> {
        KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
    });
    assertThat(ex.getMessage(), is("Kafka " + namespace + "/" + cluster + " has invalid configuration. " + "Cruise Control cannot be deployed with a single-node Kafka cluster. It requires at least two Kafka nodes."));
}
Also used : HashMap(java.util.HashMap) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Matchers.containsString(org.hamcrest.Matchers.containsString) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 3 with KafkaBuilder

use of io.strimzi.api.kafka.model.KafkaBuilder in project strimzi 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);
    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);
    assertThat(entityUserOperator.getClientsCaValidityDays(), is(42L));
    assertThat(entityUserOperator.getClientsCaRenewalDays(), is(69L));
    assertThat(entityUserOperator2.getClientsCaValidityDays(), is(Long.valueOf(CertificateAuthority.DEFAULT_CERTS_VALIDITY_DAYS)));
    assertThat(entityUserOperator2.getClientsCaRenewalDays(), is(Long.valueOf(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 4 with KafkaBuilder

use of io.strimzi.api.kafka.model.KafkaBuilder in project strimzi by strimzi.

the class EntityUserOperatorTest method testAclsAdminApiSupported.

private void testAclsAdminApiSupported(KafkaAuthorization authorizer) {
    Kafka kafkaAssembly = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, singletonMap("foo", "bar"), emptyMap())).editSpec().editKafka().withAuthorization(authorizer).endKafka().withNewEntityOperator().withNewUserOperator().endUserOperator().endEntityOperator().endSpec().build();
    EntityUserOperator f = EntityUserOperator.fromCrd(new Reconciliation("test", resource.getKind(), resource.getMetadata().getNamespace(), resource.getMetadata().getName()), kafkaAssembly);
    assertThat(f.getEnvVars().stream().filter(a -> a.getName().equals(EntityUserOperator.ENV_VAR_ACLS_ADMIN_API_SUPPORTED)).findFirst().orElseThrow().getValue(), is(String.valueOf(authorizer.supportsAdminApi())));
}
Also used : Reconciliation(io.strimzi.operator.common.Reconciliation) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder)

Example 5 with KafkaBuilder

use of io.strimzi.api.kafka.model.KafkaBuilder in project strimzi by strimzi.

the class EntityUserOperatorTest method testFromCrdDefault.

@ParallelTest
public void testFromCrdDefault() {
    EntityUserOperatorSpec entityUserOperatorSpec = new EntityUserOperatorSpecBuilder().build();
    EntityOperatorSpec entityOperatorSpec = new EntityOperatorSpecBuilder().withUserOperator(entityUserOperatorSpec).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.getWatchedNamespace(), is(namespace));
    assertThat(entityUserOperator.getImage(), is("quay.io/strimzi/operator:latest"));
    assertThat(entityUserOperator.getReconciliationIntervalMs(), is(EntityUserOperatorSpec.DEFAULT_FULL_RECONCILIATION_INTERVAL_SECONDS * 1000));
    assertThat(entityUserOperator.readinessProbeOptions.getInitialDelaySeconds(), is(EntityUserOperatorSpec.DEFAULT_HEALTHCHECK_DELAY));
    assertThat(entityUserOperator.readinessProbeOptions.getTimeoutSeconds(), is(EntityUserOperatorSpec.DEFAULT_HEALTHCHECK_TIMEOUT));
    assertThat(entityUserOperator.livenessProbeOptions.getInitialDelaySeconds(), is(EntityUserOperatorSpec.DEFAULT_HEALTHCHECK_DELAY));
    assertThat(entityUserOperator.livenessProbeOptions.getTimeoutSeconds(), is(EntityUserOperatorSpec.DEFAULT_HEALTHCHECK_TIMEOUT));
    assertThat(entityUserOperator.getKafkaBootstrapServers(), is(EntityUserOperator.defaultBootstrapServers(cluster)));
    assertThat(entityUserOperator.getLogging(), is(nullValue()));
    assertThat(entityUserOperator.getSecretPrefix(), is(EntityUserOperatorSpec.DEFAULT_SECRET_PREFIX));
}
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) 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)

Aggregations

KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)469 Kafka (io.strimzi.api.kafka.model.Kafka)461 ParallelTest (io.strimzi.test.annotations.ParallelTest)344 Reconciliation (io.strimzi.operator.common.Reconciliation)192 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)162 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)126 StatefulSet (io.fabric8.kubernetes.api.model.apps.StatefulSet)124 ResourceUtils (io.strimzi.operator.cluster.ResourceUtils)120 KafkaVersionTestUtils (io.strimzi.operator.cluster.KafkaVersionTestUtils)116 CoreMatchers.is (org.hamcrest.CoreMatchers.is)116 Labels (io.strimzi.operator.common.model.Labels)114 ArrayList (java.util.ArrayList)112 Test (org.junit.jupiter.api.Test)110 PasswordGenerator (io.strimzi.operator.common.PasswordGenerator)106 List (java.util.List)102 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)96 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)96 Map (java.util.Map)96 Checkpoint (io.vertx.junit5.Checkpoint)92 TopologySpreadConstraint (io.fabric8.kubernetes.api.model.TopologySpreadConstraint)90