Search in sources :

Example 1 with PodAntiAffinity

use of io.fabric8.kubernetes.api.model.PodAntiAffinity 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 2 with PodAntiAffinity

use of io.fabric8.kubernetes.api.model.PodAntiAffinity in project strimzi by strimzi.

the class KafkaCluster method getMergedAffinity.

/**
 * Returns a combined affinity: Adding the affinity needed for the "kafka-rack" to the {@link #getUserAffinity()}.
 */
@Override
protected Affinity getMergedAffinity() {
    Affinity userAffinity = getUserAffinity();
    AffinityBuilder builder = new AffinityBuilder(userAffinity == null ? new Affinity() : userAffinity);
    if (rack != null) {
        // If there's a rack config, we need to add a podAntiAffinity to spread the brokers among the racks
        builder = builder.editOrNewPodAntiAffinity().addNewPreferredDuringSchedulingIgnoredDuringExecution().withWeight(100).withNewPodAffinityTerm().withTopologyKey(rack.getTopologyKey()).withNewLabelSelector().addToMatchLabels(Labels.STRIMZI_CLUSTER_LABEL, cluster).addToMatchLabels(Labels.STRIMZI_NAME_LABEL, name).endLabelSelector().endPodAffinityTerm().endPreferredDuringSchedulingIgnoredDuringExecution().endPodAntiAffinity();
        builder = ModelUtils.populateAffinityBuilderWithRackLabelSelector(builder, userAffinity, rack.getTopologyKey());
    }
    return builder.build();
}
Also used : AffinityBuilder(io.fabric8.kubernetes.api.model.AffinityBuilder) Affinity(io.fabric8.kubernetes.api.model.Affinity)

Example 3 with PodAntiAffinity

use of io.fabric8.kubernetes.api.model.PodAntiAffinity in project strimzi-kafka-operator by strimzi.

the class KafkaCluster method getMergedAffinity.

/**
 * Returns a combined affinity: Adding the affinity needed for the "kafka-rack" to the {@link #getUserAffinity()}.
 */
@Override
protected Affinity getMergedAffinity() {
    Affinity userAffinity = getUserAffinity();
    AffinityBuilder builder = new AffinityBuilder(userAffinity == null ? new Affinity() : userAffinity);
    if (rack != null) {
        // If there's a rack config, we need to add a podAntiAffinity to spread the brokers among the racks
        builder = builder.editOrNewPodAntiAffinity().addNewPreferredDuringSchedulingIgnoredDuringExecution().withWeight(100).withNewPodAffinityTerm().withTopologyKey(rack.getTopologyKey()).withNewLabelSelector().addToMatchLabels(Labels.STRIMZI_CLUSTER_LABEL, cluster).addToMatchLabels(Labels.STRIMZI_NAME_LABEL, name).endLabelSelector().endPodAffinityTerm().endPreferredDuringSchedulingIgnoredDuringExecution().endPodAntiAffinity();
        builder = ModelUtils.populateAffinityBuilderWithRackLabelSelector(builder, userAffinity, rack.getTopologyKey());
    }
    return builder.build();
}
Also used : AffinityBuilder(io.fabric8.kubernetes.api.model.AffinityBuilder) Affinity(io.fabric8.kubernetes.api.model.Affinity)

Aggregations

AffinityBuilder (io.fabric8.kubernetes.api.model.AffinityBuilder)3 Affinity (io.fabric8.kubernetes.api.model.Affinity)2 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)1 PodAffinityTerm (io.fabric8.kubernetes.api.model.PodAffinityTerm)1 PodAntiAffinity (io.fabric8.kubernetes.api.model.PodAntiAffinity)1 PodAntiAffinityBuilder (io.fabric8.kubernetes.api.model.PodAntiAffinityBuilder)1 PodDisruptionBudgetTemplateBuilder (io.strimzi.api.kafka.model.template.PodDisruptionBudgetTemplateBuilder)1 ZookeeperClusterTemplateBuilder (io.strimzi.api.kafka.model.template.ZookeeperClusterTemplateBuilder)1