Search in sources :

Example 1 with PodDisruptionBudgetTemplateBuilder

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();
}
Also used : PodAffinity(io.fabric8.kubernetes.api.model.PodAffinity) PodTemplateBuilder(io.strimzi.api.kafka.model.template.PodTemplateBuilder) PodAntiAffinityBuilder(io.fabric8.kubernetes.api.model.PodAntiAffinityBuilder) AffinityBuilder(io.fabric8.kubernetes.api.model.AffinityBuilder) KafkaClusterTemplateBuilder(io.strimzi.api.kafka.model.template.KafkaClusterTemplateBuilder) PodDisruptionBudgetTemplateBuilder(io.strimzi.api.kafka.model.template.PodDisruptionBudgetTemplateBuilder)

Example 2 with PodDisruptionBudgetTemplateBuilder

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();
}
Also used : PodAffinityTerm(io.fabric8.kubernetes.api.model.PodAffinityTerm) PodAntiAffinityBuilder(io.fabric8.kubernetes.api.model.PodAntiAffinityBuilder) AffinityBuilder(io.fabric8.kubernetes.api.model.AffinityBuilder) PodAntiAffinityBuilder(io.fabric8.kubernetes.api.model.PodAntiAffinityBuilder) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) ZookeeperClusterTemplateBuilder(io.strimzi.api.kafka.model.template.ZookeeperClusterTemplateBuilder) PodAntiAffinity(io.fabric8.kubernetes.api.model.PodAntiAffinity) PodDisruptionBudgetTemplateBuilder(io.strimzi.api.kafka.model.template.PodDisruptionBudgetTemplateBuilder)

Example 3 with PodDisruptionBudgetTemplateBuilder

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));
}
Also used : Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) PodDisruptionBudgetTemplate(io.strimzi.api.kafka.model.template.PodDisruptionBudgetTemplate) PodDisruptionBudgetTemplateBuilder(io.strimzi.api.kafka.model.template.PodDisruptionBudgetTemplateBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest) Test(org.junit.jupiter.api.Test)

Example 4 with PodDisruptionBudgetTemplateBuilder

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));
}
Also used : Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) PodDisruptionBudgetTemplate(io.strimzi.api.kafka.model.template.PodDisruptionBudgetTemplate) PodDisruptionBudgetTemplateBuilder(io.strimzi.api.kafka.model.template.PodDisruptionBudgetTemplateBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest) Test(org.junit.jupiter.api.Test)

Aggregations

PodDisruptionBudgetTemplateBuilder (io.strimzi.api.kafka.model.template.PodDisruptionBudgetTemplateBuilder)4 AffinityBuilder (io.fabric8.kubernetes.api.model.AffinityBuilder)2 PodAntiAffinityBuilder (io.fabric8.kubernetes.api.model.PodAntiAffinityBuilder)2 Kafka (io.strimzi.api.kafka.model.Kafka)2 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)2 PodDisruptionBudgetTemplate (io.strimzi.api.kafka.model.template.PodDisruptionBudgetTemplate)2 ParallelTest (io.strimzi.test.annotations.ParallelTest)2 Test (org.junit.jupiter.api.Test)2 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)1 PodAffinity (io.fabric8.kubernetes.api.model.PodAffinity)1 PodAffinityTerm (io.fabric8.kubernetes.api.model.PodAffinityTerm)1 PodAntiAffinity (io.fabric8.kubernetes.api.model.PodAntiAffinity)1 KafkaClusterTemplateBuilder (io.strimzi.api.kafka.model.template.KafkaClusterTemplateBuilder)1 PodTemplateBuilder (io.strimzi.api.kafka.model.template.PodTemplateBuilder)1 ZookeeperClusterTemplateBuilder (io.strimzi.api.kafka.model.template.ZookeeperClusterTemplateBuilder)1