use of io.strimzi.api.kafka.model.template.PodDisruptionBudgetTemplateBuilder in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class KafkaCluster method buildKafkaTemplate.
private KafkaClusterTemplate buildKafkaTemplate(ManagedKafka managedKafka) {
AffinityBuilder affinityBuilder = new AffinityBuilder();
// ensures even distribution of the Kafka pods in a given cluster across the availability zones
// the previous affinity make sure single per node or not
// this only comes into picture when there are more number of nodes than the brokers
PodTemplateBuilder podTemplateBuilder = new PodTemplateBuilder().withImagePullSecrets(imagePullSecretManager.getOperatorImagePullSecrets(managedKafka)).withTopologySpreadConstraints(azAwareTopologySpreadConstraint(managedKafka.getMetadata().getName() + "-kafka", DO_NOT_SCHEDULE));
if (this.config.getKafka().isColocateWithZookeeper()) {
// adds preference to co-locate Kafka broker pods with ZK pods with same cluster label
PodAffinity zkPodAffinity = OperandUtils.buildZookeeperPodAffinity(managedKafka).getPodAffinity();
affinityBuilder.withPodAffinity(zkPodAffinity);
podTemplateBuilder.withAffinity(affinityBuilder.build());
}
// add toleration on broker pod such that it can be placed on specific worker nodes
// note that the affinity/topology stuff make sure they are evenly spread across
// the availability zone and worker nodes, but all worker nodes are same as
// some of them will have ZK, admin-server, canary and broker needs to be on its own
podTemplateBuilder.withTolerations(buildKafkaBrokerToleration());
KafkaClusterTemplateBuilder templateBuilder = new KafkaClusterTemplateBuilder().withPod(podTemplateBuilder.build());
if (drainCleanerManager.isDrainCleanerWebhookFound()) {
templateBuilder.withPodDisruptionBudget(new PodDisruptionBudgetTemplateBuilder().withMaxUnavailable(0).build());
}
return templateBuilder.build();
}
use of io.strimzi.api.kafka.model.template.PodDisruptionBudgetTemplateBuilder in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class KafkaCluster method buildZookeeperTemplate.
private ZookeeperClusterTemplate buildZookeeperTemplate(ManagedKafka managedKafka) {
// onePerNode = true - one zk per node exclusively
// onePerNode = false - one zk per node per managedkafka
boolean onePerNode = this.config.getKafka().isOneInstancePerNode();
PodNested<ZookeeperClusterTemplateBuilder> podNestedBuilder = new ZookeeperClusterTemplateBuilder().withNewPod().withImagePullSecrets(imagePullSecretManager.getOperatorImagePullSecrets(managedKafka)).withTopologySpreadConstraints(azAwareTopologySpreadConstraint(managedKafka.getMetadata().getName() + "-zookeeper", DO_NOT_SCHEDULE));
if (onePerNode) {
PodAffinityTerm affinityTerm = affinityTerm("app.kubernetes.io/name", "zookeeper");
affinityTerm.setNamespaceSelector(new LabelSelector());
PodAntiAffinity podAntiAffinity = new PodAntiAffinityBuilder().withRequiredDuringSchedulingIgnoredDuringExecution(affinityTerm).build();
AffinityBuilder affinityBuilder = new AffinityBuilder();
affinityBuilder.withPodAntiAffinity(podAntiAffinity);
podNestedBuilder.withAffinity(affinityBuilder.build());
}
ZookeeperClusterTemplateBuilder templateBuilder = podNestedBuilder.endPod();
if (drainCleanerManager.isDrainCleanerWebhookFound()) {
templateBuilder.withPodDisruptionBudget(new PodDisruptionBudgetTemplateBuilder().withMaxUnavailable(0).build());
}
return templateBuilder.build();
}
use of io.strimzi.api.kafka.model.template.PodDisruptionBudgetTemplateBuilder in project strimzi by strimzi.
the class ModelUtilsTest method testParsePodDisruptionBudgetTemplate.
@Test
public void testParsePodDisruptionBudgetTemplate() {
Kafka kafka = new KafkaBuilder().withNewMetadata().withName("my-cluster").withNamespace("my-namespace").endMetadata().build();
PodDisruptionBudgetTemplate template = new PodDisruptionBudgetTemplateBuilder().withNewMetadata().withAnnotations(Collections.singletonMap("annoKey", "annoValue")).withLabels(Collections.singletonMap("labelKey", "labelValue")).endMetadata().withMaxUnavailable(2).build();
Model model = new Model(Reconciliation.DUMMY_RECONCILIATION, kafka);
ModelUtils.parsePodDisruptionBudgetTemplate(model, template);
assertThat(model.templatePodDisruptionBudgetLabels, is(Collections.singletonMap("labelKey", "labelValue")));
assertThat(model.templatePodDisruptionBudgetAnnotations, is(Collections.singletonMap("annoKey", "annoValue")));
assertThat(model.templatePodDisruptionBudgetMaxUnavailable, is(2));
}
use of io.strimzi.api.kafka.model.template.PodDisruptionBudgetTemplateBuilder in project strimzi-kafka-operator by strimzi.
the class ModelUtilsTest method testParsePodDisruptionBudgetTemplate.
@Test
public void testParsePodDisruptionBudgetTemplate() {
Kafka kafka = new KafkaBuilder().withNewMetadata().withName("my-cluster").withNamespace("my-namespace").endMetadata().build();
PodDisruptionBudgetTemplate template = new PodDisruptionBudgetTemplateBuilder().withNewMetadata().withAnnotations(Collections.singletonMap("annoKey", "annoValue")).withLabels(Collections.singletonMap("labelKey", "labelValue")).endMetadata().withMaxUnavailable(2).build();
Model model = new Model(Reconciliation.DUMMY_RECONCILIATION, kafka);
ModelUtils.parsePodDisruptionBudgetTemplate(model, template);
assertThat(model.templatePodDisruptionBudgetLabels, is(Collections.singletonMap("labelKey", "labelValue")));
assertThat(model.templatePodDisruptionBudgetAnnotations, is(Collections.singletonMap("annoKey", "annoValue")));
assertThat(model.templatePodDisruptionBudgetMaxUnavailable, is(2));
}
Aggregations