add tests for replicas and maxUnaivalable in deployments

This commit is contained in:
Gaël Goinvic committed 2025-06-04 15:25:06 +02:00
1 parent 246de8e6d8
commit 91b2a877de
3 files changed
+120 -25

No files matched your search

@@ -19,7 +19,7 @@ metadata:
name: {{ $.Release.Name }}-matrix-rtc-authorisation-service
namespace: {{ $.Release.Namespace }}
spec:
{{ include "element-io.ess-library.deployments.commonSpec" (dict "root" $ "context" (dict "nameSuffix" "matrix-rtc-authorisation-service")) | nindent 2 }}
{{ include "element-io.ess-library.deployments.commonSpec" (dict "root" $ "context" (dict "replicas" .replicas "nameSuffix" "matrix-rtc-authorisation-service")) | nindent 2 }}
template:
metadata:
labels:
+51 -24
View File
@@ -17,6 +17,7 @@ class PropertyType(Enum):
LivenessProbe = "livenessProbe"
PodSecurityContext = "podSecurityContext"
Postgres = "postgres"
Replicas = "replicas"
ReadinessProbe = "readinessProbe"
Resources = "resources"
StartupProbe = "startupProbe"
@@ -207,6 +208,7 @@ class SidecarDetails(DeployableDetails):
PropertyType.ServiceAccount: ValuesFilePath.not_supported(),
PropertyType.Tolerations: ValuesFilePath.not_supported(),
PropertyType.TopologySpreadConstraints: ValuesFilePath.not_supported(),
PropertyType.Replicas: ValuesFilePath.not_supported(),
}
if self.values_file_path_overrides is None:
self.values_file_path_overrides = {}
@@ -321,7 +323,7 @@ class ComponentDetails(DeployableDetails):
return self
def make_synapse_worker_sub_component(worker_name: str) -> SubComponentDetails:
def make_synapse_worker_sub_component(worker_name: str, worker_type: str) -> SubComponentDetails:
values_file_path_overrides: dict[PropertyType, ValuesFilePath] = {
PropertyType.Env: ValuesFilePath.read_elsewhere("synapse", "extraEnv"),
PropertyType.Image: ValuesFilePath.read_elsewhere("synapse", "image"),
@@ -333,6 +335,9 @@ def make_synapse_worker_sub_component(worker_name: str) -> SubComponentDetails:
PropertyType.TopologySpreadConstraints: ValuesFilePath.read_elsewhere("synapse", "topologySpreadConstraints"),
}
if worker_type == "single":
values_file_path_overrides[PropertyType.Replicas] = ValuesFilePath.not_supported()
return SubComponentDetails(
f"synapse-{worker_name}",
values_file_path=ValuesFilePath.read_write("synapse", "workers", worker_name),
@@ -343,29 +348,29 @@ def make_synapse_worker_sub_component(worker_name: str) -> SubComponentDetails:
synapse_workers_details = tuple(
make_synapse_worker_sub_component(worker_name)
for worker_name in [
"appservice",
"background",
"client-reader",
"encryption",
"event-creator",
"event-persister",
"federation-inbound",
"federation-reader",
"federation-sender",
"initial-synchrotron",
"media-repository",
"presence-writer",
"push-rules",
"pusher",
"receipts-account",
"sliding-sync",
"sso-login",
"synchrotron",
"typing-persister",
"user-dir",
]
make_synapse_worker_sub_component(worker_name, worker_type)
for worker_name, worker_type in {
"appservice": "single",
"background": "single",
"client-reader": "scalable",
"encryption": "single",
"event-creator": "scalable",
"event-persister": "scalable",
"federation-inbound": "scalable",
"federation-reader": "scalable",
"federation-sender": "scalable",
"initial-synchrotron": "scalable",
"media-repository": "single",
"presence-writer": "single",
"push-rules": "single",
"pusher": "scalable",
"receipts-account": "single",
"sliding-sync": "scalable",
"sso-login": "single",
"synchrotron": "scalable",
"typing-persister": "single",
"user-dir": "single",
}.items()
)
@@ -380,6 +385,8 @@ all_components_details = [
PropertyType.ReadinessProbe: ValuesFilePath.not_supported(),
# Job so no startupProbe
PropertyType.StartupProbe: ValuesFilePath.not_supported(),
# Job so no replicas
PropertyType.Replicas: ValuesFilePath.not_supported(),
},
has_image=False,
has_ingress=False,
@@ -391,6 +398,8 @@ all_components_details = [
name="init-secrets",
values_file_path=ValuesFilePath.read_write("initSecrets"),
values_file_path_overrides={
# Job so no replicas
PropertyType.Replicas: ValuesFilePath.not_supported(),
# Job so no livenessProbe
PropertyType.LivenessProbe: ValuesFilePath.not_supported(),
# Job so no readinessProbe
@@ -426,6 +435,10 @@ all_components_details = [
has_service_monitor=False,
),
),
values_file_path_overrides={
# StatefulSet without replicas
PropertyType.Replicas: ValuesFilePath.not_supported(),
},
paths_consistency_noqa=("/docker-entrypoint-initdb.d/init-ess-dbs.sh",),
is_shared_component=True,
),
@@ -439,6 +452,10 @@ all_components_details = [
values_file_path=ValuesFilePath.read_write("matrixRTC", "sfu"),
has_topology_spread_constraints=False,
has_ingress=False,
values_file_path_overrides={
# Deployment which do not support replicas
PropertyType.Replicas: ValuesFilePath.not_supported(),
},
),
),
shared_component_names=("init-secrets",),
@@ -480,6 +497,10 @@ all_components_details = [
is_synapse_process=True,
additional_values_files=("synapse-worker-example-values.yaml",),
skip_path_consistency_for_files=("path_map_file", "path_map_file_get"),
values_file_path_overrides={
# StatefulSet which do not support replicas
PropertyType.Replicas: ValuesFilePath.not_supported(),
},
sub_components=synapse_workers_details
+ (
SubComponentDetails(
@@ -488,6 +509,10 @@ all_components_details = [
has_ingress=False,
has_service_monitor=False,
has_topology_spread_constraints=False,
values_file_path_overrides={
# Deployment which do not support replicas
PropertyType.Replicas: ValuesFilePath.not_supported(),
},
),
SubComponentDetails(
name="synapse-check-config",
@@ -498,6 +523,8 @@ all_components_details = [
# Job so no livenessProbe
PropertyType.LivenessProbe: ValuesFilePath.not_supported(),
PropertyType.PodSecurityContext: ValuesFilePath.read_elsewhere("synapse", "podSecurityContext"),
# Job so no replicas
PropertyType.Replicas: ValuesFilePath.not_supported(),
PropertyType.Resources: ValuesFilePath.read_elsewhere("synapse", "resources"),
# Job so no readinessProbe
PropertyType.ReadinessProbe: ValuesFilePath.not_supported(),
+68
View File
@@ -0,0 +1,68 @@
# Copyright 2025 New Vector Ltd
#
# SPDX-License-Identifier: AGPL-3.0-only
import pytest
from . import DeployableDetails, PropertyType, ValuesFilePath, values_files_to_test
from .utils import iterate_deployables_workload_parts, template_id, template_to_deployable_details
@pytest.mark.parametrize("values_file", values_files_to_test)
@pytest.mark.asyncio_cooperative
async def test_all_deployments_set_replicas(values, make_templates):
deployments = []
for template in await make_templates(values):
if template["kind"] == "Deployment":
deployments.append(template)
for deployment in deployments:
id = deployment["metadata"]["name"]
assert "replicas" in deployment["spec"], f"{id} does not specify replicas"
def set_replicas_details(values):
# We have a counter that increments for each replicas field for each deployable details
# That way we can assert a) the correct value is going into the correct field and
# b) that the correct part of the values file is being used
counter = 100
def set_replicas_details(deployable_details: DeployableDetails):
nonlocal counter
counter += 1
deployable_details.set_helm_values(values, PropertyType.Replicas, counter)
iterate_deployables_workload_parts(set_replicas_details)
def assert_matching_replicas(template, values):
deployable_details = template_to_deployable_details(template)
replicas = template["spec"]["replicas"]
max_unavailable = template["spec"]["strategy"]["rollingUpdate"]["maxUnavailable"]
if (
not deployable_details.values_file_path_overrides
or deployable_details.values_file_path_overrides
and deployable_details.values_file_path_overrides[PropertyType.Replicas] != ValuesFilePath.not_supported()
):
value = deployable_details.get_helm_values(values, PropertyType.Replicas)
assert value == replicas, f"{template_id(template)} has replicas {replicas} where {replicas} != {value}"
assert max_unavailable == 1, (
f"{template_id(template)} has maxUnavailable {max_unavailable} where {max_unavailable} != 1"
)
else:
assert replicas == 1, (
f"{template_id(template)} has replicas {replicas} "
f"when replicas should not be settable present when it should be absent"
)
assert max_unavailable == 0, (
f"{template_id(template)} has maxUnavailable {max_unavailable} where {max_unavailable} != 0"
)
@pytest.mark.parametrize("values_file", values_files_to_test)
@pytest.mark.asyncio_cooperative
async def test_all_deployments_can_set_replicas(values, make_templates):
set_replicas_details(values)
for template in await make_templates(values):
if template["kind"] in ["Deployment"]:
assert_matching_replicas(template, values)