diff --git a/ansible/roles/schulcloud-calendar-core/templates/deployment.yml.j2 b/ansible/roles/schulcloud-calendar-core/templates/deployment.yml.j2 index a24115b..551e356 100644 --- a/ansible/roles/schulcloud-calendar-core/templates/deployment.yml.j2 +++ b/ansible/roles/schulcloud-calendar-core/templates/deployment.yml.j2 @@ -81,3 +81,40 @@ spec: requests: cpu: {{ CALENDAR_CPU_REQUESTS|default("100m", true) }} memory: {{ CALENDAR_MEMORY_REQUESTS|default("128Mi", true) }} +{% if AFFINITY_ENABLE is defined and AFFINITY_ENABLE|bool %} + affinity: + podAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 9 + podAffinityTerm: + labelSelector: + matchExpressions: + - key: app.kubernetes.io/part-of + operator: In + values: + - schulcloud-verbund + topologyKey: "kubernetes.io/hostname" + namespaceSelector: {} + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: +{% if ANIT_AFFINITY_NODEPOOL_ENABLE is defined and ANIT_AFFINITY_NODEPOOL_ENABLE|bool %} + - weight: 10 + podAffinityTerm: + labelSelector: + matchExpressions: + - key: app.kubernetes.io/name + operator: In + values: + - calendar + topologyKey: {{ ANIT_AFFINITY_NODEPOOL_TOPOLOGY_KEY }} +{% endif %} + - weight: 20 + podAffinityTerm: + labelSelector: + matchExpressions: + - key: app.kubernetes.io/name + operator: In + values: + - calendar + topologyKey: "topology.kubernetes.io/zone" +{% endif %}