From 6bd06168698b7a89db3cbfc33dc0bda583d9ead5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Goinvic?= Date: Thu, 27 Feb 2025 12:40:20 +0100 Subject: [PATCH] manifest tests: verify synapse.checkConfigHook --- tests/manifests/__init__.py | 2 ++ tests/manifests/test_pod_containers_ports.py | 13 ++++++++++++- tests/manifests/test_serviceaccounts.py | 6 ++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/tests/manifests/__init__.py b/tests/manifests/__init__.py index 1159aa09..45f41734 100644 --- a/tests/manifests/__init__.py +++ b/tests/manifests/__init__.py @@ -34,6 +34,7 @@ _raw_component_details = { "redis": { "has_service_monitor": False, }, + "checkConfigHook": {"has_service_monitor": False, "uses_parent_properties": True}, }, "shared_components": ["initSecrets", "haproxy", "postgres"], }, @@ -65,6 +66,7 @@ def _enrich_components_to_test(details) -> dict[str, Any]: _component_details[component].setdefault("sub_components", {}) for sub_component in _component_details[component]["sub_components"]: _component_details[component]["sub_components"][sub_component].setdefault("has_service_monitor", True) + _component_details[component]["sub_components"][sub_component].setdefault("uses_parent_properties", False) _component_details[component].setdefault("secret_values_files", []) if "initSecrets" in _component_details[component].setdefault("shared_components", []): diff --git a/tests/manifests/test_pod_containers_ports.py b/tests/manifests/test_pod_containers_ports.py index c851ac72..b266076a 100644 --- a/tests/manifests/test_pod_containers_ports.py +++ b/tests/manifests/test_pod_containers_ports.py @@ -11,7 +11,7 @@ from . import values_files_to_test @pytest.mark.asyncio_cooperative async def test_unique_ports_in_containers(templates): for template in templates: - if template["kind"] in ["Deployment", "StatefulSet", "Job"]: + if template["kind"] in ["Deployment", "StatefulSet"]: id = f"{template['kind']}/{template['metadata']['name']}" ports = [] for container in template["spec"]["template"]["spec"]["containers"]: @@ -34,3 +34,14 @@ async def test_ports_in_containers_are_named(templates): ) port_names.append(port["name"]) assert len(port_names) == len(set(port_names)), f"Port names are not unique: {id}, {port_names}" + + +@pytest.mark.asyncio_cooperative +async def test_no_ports_in_jobs(templates): + for template in templates: + if template["kind"] in ["Job"]: + id = f"{template['kind']}/{template['metadata']['name']}" + ports = [] + for container in template["spec"]["template"]["spec"]["containers"]: + ports += [port["containerPort"] for port in container.get("ports", [])] + assert len(ports) == 0, f"Ports are present in job: {id}, {ports}" diff --git a/tests/manifests/test_serviceaccounts.py b/tests/manifests/test_serviceaccounts.py index af6dc9a8..f3b94cff 100644 --- a/tests/manifests/test_serviceaccounts.py +++ b/tests/manifests/test_serviceaccounts.py @@ -62,7 +62,7 @@ async def test_uses_serviceaccount_named_as_values_if_specified(component, value workload.setdefault("serviceAccount", {}).setdefault("name", f"{component}-pytest") workload.setdefault("labels", {}).setdefault("expected.name", f"{component}-pytest") - iterate_component_workload_parts(component, values, service_account_name) + iterate_component_workload_parts(component, values, service_account_name, force=True) workloads_by_id = {} serviceaccount_names = [] @@ -117,7 +117,9 @@ async def test_does_not_create_serviceaccounts_if_configured_not_to(component, v serviceaccount_name = template["spec"]["template"]["spec"]["serviceAccountName"] if template["metadata"]["labels"].get("serviceAccount", "some") == "none": - assert serviceaccount_name not in serviceaccount_names + assert serviceaccount_name not in serviceaccount_names, ( + f"{id} specified an existing ServiceAccount: {serviceaccount_name}" + ) else: covered_serviceaccount_names.add(serviceaccount_name)