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