Skip to content

Commit 965fbad

Browse files
Merge pull request #537 from element-hq/gaelg/fix-anti-affinity
fix anti-affinity schema
2 parents c1f4e3f + 9843887 commit 965fbad

3 files changed

Lines changed: 24 additions & 13 deletions

File tree

charts/matrix-stack/templates/ess-library/_pods.tpl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ SPDX-License-Identifier: AGPL-3.0-only
1717
affinity:
1818
podAntiAffinity:
1919
preferredDuringSchedulingIgnoredDuringExecution:
20-
- labelSelector:
21-
matchExpressions:
22-
- key: app.kubernetes.io/instance
23-
operator: In
24-
values:
25-
- "{{ $root.Release.Name }}-{{ $instanceSuffix }}"
26-
topologyKey: kubernetes.io/hostname
20+
- weight: 100
21+
podAffinityTerm:
22+
labelSelector:
23+
matchExpressions:
24+
- key: app.kubernetes.io/instance
25+
operator: In
26+
values:
27+
- "{{ $root.Release.Name }}-{{ $instanceSuffix }}"
28+
topologyKey: kubernetes.io/hostname
2729
{{- end }}
2830
automountServiceAccountToken: {{ $mountServiceAccountToken }}
2931
serviceAccountName: {{ include "element-io.ess-library.serviceAccountName" (dict "root" $root "context" (dict "serviceAccount" .serviceAccount "nameSuffix" $serviceAccountNameSuffix)) }}

newsfragments/537.internal.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Test that Deployments pods anti-affinity are not strict anti-affinity.

tests/manifests/test_deployments.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,26 @@ def assert_matching_replicas(template, values, release_name):
5252
f"{template_id(template)} No items in preferredDuringSchedulingIgnoredDuringExecution"
5353
)
5454

55-
item = pod_spec["affinity"]["podAntiAffinity"]["preferredDuringSchedulingIgnoredDuringExecution"][0]
56-
assert "labelSelector" in item, (
55+
preferred_item = pod_spec["affinity"]["podAntiAffinity"]["preferredDuringSchedulingIgnoredDuringExecution"][0]
56+
assert "weight" in preferred_item, (
57+
f"{template_id(template)} Missing weight in preferredDuringSchedulingIgnoredDuringExecution item"
58+
)
59+
assert "podAffinityTerm" in preferred_item, (
60+
f"{template_id(template)} Missing podAffinityTerm in preferredDuringSchedulingIgnoredDuringExecution item"
61+
)
62+
63+
pod_affinity_term = preferred_item["podAffinityTerm"]
64+
assert "labelSelector" in pod_affinity_term, (
5765
f"{template_id(template)} Missing labelSelector in preferredDuringSchedulingIgnoredDuringExecution item"
5866
)
59-
assert "matchExpressions" in item["labelSelector"], (
67+
assert "matchExpressions" in pod_affinity_term["labelSelector"], (
6068
f"{template_id(template)} Missing matchExpressions in labelSelector"
6169
)
62-
assert len(item["labelSelector"]["matchExpressions"]) >= 1, (
70+
assert len(pod_affinity_term["labelSelector"]["matchExpressions"]) >= 1, (
6371
f"{template_id(template)} No matchExpressions in labelSelector"
6472
)
6573

66-
match_expr = item["labelSelector"]["matchExpressions"][0]
74+
match_expr = pod_affinity_term["labelSelector"]["matchExpressions"][0]
6775
assert "key" in match_expr, f"{template_id(template)} Missing key in matchExpression"
6876
assert "operator" in match_expr, f"{template_id(template)} Missing operator in matchExpression"
6977
assert "values" in match_expr, f"{template_id(template)} Missing values in matchExpression"
@@ -109,7 +117,7 @@ async def test_all_deployments_can_set_replicas(values, make_templates, release_
109117

110118
@pytest.mark.parametrize("values_file", values_files_to_test)
111119
@pytest.mark.asyncio_cooperative
112-
async def test_max_unaivalable_single_replicas(values, make_templates):
120+
async def test_max_unavailable_single_replicas(values, make_templates):
113121
iterate_deployables_parts(
114122
lambda deployable_details: deployable_details.set_helm_values(values, PropertyType.Replicas, 1),
115123
lambda deployable_details: deployable_details.has_replicas,

0 commit comments

Comments
 (0)