use of io.strimzi.api.kafka.model.KafkaBuilder in project strimzi by strimzi.
the class KafkaClusterTest method testMetricsParsingFromConfigMap.
@ParallelTest
public void testMetricsParsingFromConfigMap() {
MetricsConfig metrics = new JmxPrometheusExporterMetricsBuilder().withNewValueFrom().withConfigMapKeyRef(new ConfigMapKeySelectorBuilder().withName("my-metrics-configuration").withKey("config.yaml").build()).endValueFrom().build();
Kafka kafkaAssembly = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout)).editSpec().editKafka().withMetricsConfig(metrics).endKafka().endSpec().build();
KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
assertThat(kc.isMetricsEnabled(), is(true));
assertThat(kc.getMetricsConfigInCm(), is(metrics));
}
use of io.strimzi.api.kafka.model.KafkaBuilder in project strimzi by strimzi.
the class KafkaClusterTest method testTemplate.
@ParallelTest
@SuppressWarnings({ "checkstyle:MethodLength" })
public void testTemplate() {
Map<String, String> ssLabels = TestUtils.map("l1", "v1", "l2", "v2", Labels.KUBERNETES_PART_OF_LABEL, "custom-part", Labels.KUBERNETES_MANAGED_BY_LABEL, "custom-managed-by");
Map<String, String> expectedStsLabels = new HashMap<>(ssLabels);
expectedStsLabels.remove(Labels.KUBERNETES_MANAGED_BY_LABEL);
Map<String, String> ssAnnotations = TestUtils.map("a1", "v1", "a2", "v2");
Map<String, String> podLabels = TestUtils.map("l3", "v3", "l4", "v4");
Map<String, String> podAnnotations = TestUtils.map("a3", "v3", "a4", "v4");
Map<String, String> svcLabels = TestUtils.map("l5", "v5", "l6", "v6");
Map<String, String> svcAnnotations = TestUtils.map("a5", "v5", "a6", "v6");
Map<String, String> hSvcLabels = TestUtils.map("l7", "v7", "l8", "v8");
Map<String, String> hSvcAnnotations = TestUtils.map("a7", "v7", "a8", "v8");
Map<String, String> exSvcLabels = TestUtils.map("l9", "v9", "l10", "v10");
Map<String, String> exSvcAnnotations = TestUtils.map("a9", "v9", "a10", "v10");
Map<String, String> perPodSvcLabels = TestUtils.map("l11", "v11", "l12", "v12");
Map<String, String> perPodSvcAnnotations = TestUtils.map("a11", "v11", "a12", "v12");
Map<String, String> exRouteLabels = TestUtils.map("l13", "v13", "l14", "v14");
Map<String, String> exRouteAnnotations = TestUtils.map("a13", "v13", "a14", "v14");
Map<String, String> perPodRouteLabels = TestUtils.map("l15", "v15", "l16", "v16");
Map<String, String> perPodRouteAnnotations = TestUtils.map("a15", "v15", "a16", "v16");
Map<String, String> pdbLabels = TestUtils.map("l17", "v17", "l18", "v18");
Map<String, String> pdbAnnotations = TestUtils.map("a17", "v17", "a18", "v18");
Map<String, String> crbLabels = TestUtils.map("l19", "v19", "l20", "v20");
Map<String, String> crbAnnotations = TestUtils.map("a19", "v19", "a20", "v20");
Map<String, String> saLabels = TestUtils.map("l21", "v21", "l22", "v22");
Map<String, String> saAnnotations = TestUtils.map("a21", "v21", "a22", "v22");
HostAlias hostAlias1 = new HostAliasBuilder().withHostnames("my-host-1", "my-host-2").withIp("192.168.1.86").build();
HostAlias hostAlias2 = new HostAliasBuilder().withHostnames("my-host-3").withIp("192.168.1.87").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 kafkaAssembly = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, configuration, emptyMap())).editSpec().editKafka().withListeners(new GenericKafkaListenerBuilder().withName("external").withPort(9094).withType(KafkaListenerType.ROUTE).withTls(true).build(), new GenericKafkaListenerBuilder().withName("external2").withPort(9095).withType(KafkaListenerType.NODEPORT).withTls(true).build()).withNewTemplate().withNewStatefulset().withNewMetadata().withLabels(ssLabels).withAnnotations(ssAnnotations).endMetadata().endStatefulset().withNewPod().withNewMetadata().withLabels(podLabels).withAnnotations(podAnnotations).endMetadata().withPriorityClassName("top-priority").withSchedulerName("my-scheduler").withHostAliases(hostAlias1, hostAlias2).withTopologySpreadConstraints(tsc1, tsc2).withEnableServiceLinks(false).withTmpDirSizeLimit("10Mi").endPod().withNewBootstrapService().withNewMetadata().withLabels(svcLabels).withAnnotations(svcAnnotations).endMetadata().withIpFamilyPolicy(IpFamilyPolicy.PREFER_DUAL_STACK).withIpFamilies(IpFamily.IPV6, IpFamily.IPV4).endBootstrapService().withNewBrokersService().withNewMetadata().withLabels(hSvcLabels).withAnnotations(hSvcAnnotations).endMetadata().withIpFamilyPolicy(IpFamilyPolicy.SINGLE_STACK).withIpFamilies(IpFamily.IPV6).endBrokersService().withNewExternalBootstrapService().withNewMetadata().withLabels(exSvcLabels).withAnnotations(exSvcAnnotations).endMetadata().endExternalBootstrapService().withNewPerPodService().withNewMetadata().withLabels(perPodSvcLabels).withAnnotations(perPodSvcAnnotations).endMetadata().endPerPodService().withNewExternalBootstrapRoute().withNewMetadata().withLabels(exRouteLabels).withAnnotations(exRouteAnnotations).endMetadata().endExternalBootstrapRoute().withNewPerPodRoute().withNewMetadata().withLabels(perPodRouteLabels).withAnnotations(perPodRouteAnnotations).endMetadata().endPerPodRoute().withNewPodDisruptionBudget().withNewMetadata().withLabels(pdbLabels).withAnnotations(pdbAnnotations).endMetadata().endPodDisruptionBudget().withNewClusterRoleBinding().withNewMetadata().withLabels(crbLabels).withAnnotations(crbAnnotations).endMetadata().endClusterRoleBinding().withNewServiceAccount().withNewMetadata().withLabels(saLabels).withAnnotations(saAnnotations).endMetadata().endServiceAccount().endTemplate().endKafka().endSpec().build();
KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
// Check StatefulSet
StatefulSet sts = kc.generateStatefulSet(true, null, null, null);
assertThat(sts.getMetadata().getLabels().entrySet().containsAll(expectedStsLabels.entrySet()), is(true));
assertThat(sts.getMetadata().getAnnotations().entrySet().containsAll(ssAnnotations.entrySet()), is(true));
assertThat(sts.getSpec().getTemplate().getSpec().getPriorityClassName(), is("top-priority"));
// Check Pods
assertThat(sts.getSpec().getTemplate().getMetadata().getLabels().entrySet().containsAll(podLabels.entrySet()), is(true));
assertThat(sts.getSpec().getTemplate().getMetadata().getAnnotations().entrySet().containsAll(podAnnotations.entrySet()), is(true));
assertThat(sts.getSpec().getTemplate().getSpec().getSchedulerName(), is("my-scheduler"));
assertThat(sts.getSpec().getTemplate().getSpec().getHostAliases(), containsInAnyOrder(hostAlias1, hostAlias2));
assertThat(sts.getSpec().getTemplate().getSpec().getTopologySpreadConstraints(), containsInAnyOrder(tsc1, tsc2));
assertThat(sts.getSpec().getTemplate().getSpec().getEnableServiceLinks(), is(false));
assertThat(sts.getSpec().getTemplate().getSpec().getVolumes().stream().filter(volume -> volume.getName().equalsIgnoreCase("strimzi-tmp")).findFirst().orElseThrow().getEmptyDir().getSizeLimit(), is(new Quantity("10Mi")));
// Check Service
Service svc = kc.generateService();
assertThat(svc.getMetadata().getLabels().entrySet().containsAll(svcLabels.entrySet()), is(true));
assertThat(svc.getMetadata().getAnnotations().entrySet().containsAll(svcAnnotations.entrySet()), is(true));
assertThat(svc.getSpec().getIpFamilyPolicy(), is("PreferDualStack"));
assertThat(svc.getSpec().getIpFamilies(), contains("IPv6", "IPv4"));
// Check Headless Service
svc = kc.generateHeadlessService();
assertThat(svc.getMetadata().getLabels().entrySet().containsAll(hSvcLabels.entrySet()), is(true));
assertThat(svc.getMetadata().getAnnotations().entrySet().containsAll(hSvcAnnotations.entrySet()), is(true));
assertThat(svc.getSpec().getIpFamilyPolicy(), is("SingleStack"));
assertThat(svc.getSpec().getIpFamilies(), contains("IPv6"));
// Check External Bootstrap service
svc = kc.generateExternalBootstrapServices().get(0);
assertThat(svc.getMetadata().getLabels().entrySet().containsAll(exSvcLabels.entrySet()), is(true));
assertThat(svc.getMetadata().getAnnotations().entrySet().containsAll(exSvcAnnotations.entrySet()), is(true));
// Check per pod service
svc = kc.generateExternalServices(0).get(0);
assertThat(svc.getMetadata().getLabels().entrySet().containsAll(perPodSvcLabels.entrySet()), is(true));
assertThat(svc.getMetadata().getAnnotations().entrySet().containsAll(perPodSvcAnnotations.entrySet()), is(true));
// Check Bootstrap Route
Route rt = kc.generateExternalBootstrapRoutes().get(0);
assertThat(rt.getMetadata().getLabels().entrySet().containsAll(exRouteLabels.entrySet()), is(true));
assertThat(rt.getMetadata().getAnnotations().entrySet().containsAll(exRouteAnnotations.entrySet()), is(true));
// Check PerPodRoute
rt = kc.generateExternalRoutes(0).get(0);
assertThat(rt.getMetadata().getLabels().entrySet().containsAll(perPodRouteLabels.entrySet()), is(true));
assertThat(rt.getMetadata().getAnnotations().entrySet().containsAll(perPodRouteAnnotations.entrySet()), is(true));
// Check PodDisruptionBudget
PodDisruptionBudget pdb = kc.generatePodDisruptionBudget();
assertThat(pdb.getMetadata().getLabels().entrySet().containsAll(pdbLabels.entrySet()), is(true));
assertThat(pdb.getMetadata().getAnnotations().entrySet().containsAll(pdbAnnotations.entrySet()), is(true));
// Check PodDisruptionBudget V1Beta1
io.fabric8.kubernetes.api.model.policy.v1beta1.PodDisruptionBudget pdbV1Beta1 = kc.generatePodDisruptionBudgetV1Beta1();
assertThat(pdbV1Beta1.getMetadata().getLabels().entrySet().containsAll(pdbLabels.entrySet()), is(true));
assertThat(pdbV1Beta1.getMetadata().getAnnotations().entrySet().containsAll(pdbAnnotations.entrySet()), is(true));
// Check ClusterRoleBinding
ClusterRoleBinding crb = kc.generateClusterRoleBinding("namespace");
assertThat(crb.getMetadata().getLabels().entrySet().containsAll(crbLabels.entrySet()), is(true));
assertThat(crb.getMetadata().getAnnotations().entrySet().containsAll(crbAnnotations.entrySet()), is(true));
// Check Service Account
ServiceAccount sa = kc.generateServiceAccount();
assertThat(sa.getMetadata().getLabels().entrySet().containsAll(saLabels.entrySet()), is(true));
assertThat(sa.getMetadata().getAnnotations().entrySet().containsAll(saAnnotations.entrySet()), is(true));
}
use of io.strimzi.api.kafka.model.KafkaBuilder in project strimzi by strimzi.
the class KafkaClusterTest method testCruiseControlWithMinISRgtReplicas.
@ParallelTest
public void testCruiseControlWithMinISRgtReplicas() {
Map<String, Object> config = new HashMap<>();
int minInsyncReplicas = 3;
config.put(CruiseControlConfigurationParameters.METRICS_TOPIC_REPLICATION_FACTOR.getValue(), 2);
config.put(CruiseControlConfigurationParameters.METRICS_TOPIC_MIN_ISR.getValue(), minInsyncReplicas);
Kafka kafkaAssembly = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, configuration, emptyMap())).editSpec().editKafka().withConfig(config).endKafka().withNewCruiseControl().endCruiseControl().endSpec().build();
assertThrows(IllegalArgumentException.class, () -> KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS));
}
use of io.strimzi.api.kafka.model.KafkaBuilder in project strimzi by strimzi.
the class KafkaClusterTest method testLoadBalancerSourceRangeFromListener.
@ParallelTest
public void testLoadBalancerSourceRangeFromListener() {
List<String> sourceRanges = List.of("10.0.0.0/8", "130.211.204.1/32");
Kafka kafkaAssembly = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, configuration, emptyMap())).editSpec().editKafka().withListeners(new GenericKafkaListenerBuilder().withName("external").withPort(9094).withType(KafkaListenerType.LOADBALANCER).withTls(true).withNewConfiguration().withLoadBalancerSourceRanges(sourceRanges).endConfiguration().build()).endKafka().endSpec().build();
KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
// Check external bootstrap service
Service ext = kc.generateExternalBootstrapServices().get(0);
assertThat(ext.getSpec().getLoadBalancerSourceRanges(), is(sourceRanges));
// Check per pod services
for (int i = 0; i < replicas; i++) {
Service srv = kc.generateExternalServices(i).get(0);
assertThat(srv.getSpec().getLoadBalancerSourceRanges(), is(sourceRanges));
}
}
use of io.strimzi.api.kafka.model.KafkaBuilder in project strimzi by strimzi.
the class KafkaClusterTest method testDefaultPodDisruptionBudget.
@ParallelTest
public void testDefaultPodDisruptionBudget() {
Kafka kafkaAssembly = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, configuration, emptyMap())).build();
KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
PodDisruptionBudget pdb = kc.generatePodDisruptionBudget();
assertThat(pdb.getSpec().getMaxUnavailable(), is(new IntOrString(1)));
}
Aggregations