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));
}
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."));
}
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)));
}
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())));
}
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));
}
Aggregations