diff --git a/newsfragments/1717.internal.md b/newsfragments/1717.internal.md new file mode 100644 index 00000000..ba2a4462 --- /dev/null +++ b/newsfragments/1717.internal.md @@ -0,0 +1 @@ +CI: Validate that components depending on postgres have a `db-wait` init container. diff --git a/tests/manifests/__init__.py b/tests/manifests/__init__.py index d6153b28..d8de86fc 100644 --- a/tests/manifests/__init__.py +++ b/tests/manifests/__init__.py @@ -410,6 +410,7 @@ def make_synapse_worker_sub_component(worker_name: str, worker_type: str) -> Sub PropertyType.PreStopSleepSeconds: ValuesFilePath.read_write("synapse", "preStopSleepSeconds"), PropertyType.Affinity: ValuesFilePath.read_elsewhere("synapse", "affinity"), PropertyType.NodeSelector: ValuesFilePath.read_elsewhere("synapse", "nodeSelector"), + PropertyType.Postgres: ValuesFilePath.read_elsewhere("synapse", "postgres"), PropertyType.ContainersSecurityContext: ValuesFilePath.read_elsewhere("synapse", "containersSecurityContext"), PropertyType.PodSecurityContext: ValuesFilePath.read_elsewhere("synapse", "podSecurityContext"), PropertyType.PriorityClassName: ValuesFilePath.read_elsewhere("synapse", "priorityClassName"), @@ -430,6 +431,7 @@ def make_synapse_worker_sub_component(worker_name: str, worker_type: str) -> Sub has_ingress=False, is_synapse_process=True, has_redis=True, + has_db=True, is_singleton=(worker_type != "scalable"), has_mount_context=True, ignore_unreferenced_mounts={ @@ -715,11 +717,14 @@ all_components_details = [ PropertyType.StartupProbe: ValuesFilePath.not_supported(), # Job so no replicas PropertyType.Replicas: ValuesFilePath.not_supported(), + # The postgres database is owned by the parent component + PropertyType.Postgres: ValuesFilePath.read_elsewhere("matrixAuthenticationService", "postgres"), }, has_ingress=False, has_automount_service_account_token=True, has_service_monitor=False, is_hook=True, + has_db=True, has_mount_context=False, makes_outbound_requests=False, ephemeral_storages={"tmp-mas-cli": "tmpMasCli"}, diff --git a/tests/manifests/test_labels.py b/tests/manifests/test_labels.py index 3b54da84..1f9e8272 100644 --- a/tests/manifests/test_labels.py +++ b/tests/manifests/test_labels.py @@ -72,9 +72,7 @@ async def test_templates_have_postgres_hash_label(release_name, templates, value assert any(re.match("k8s.element.io/postgres-password-[a-z]+-hash", label) for label in labels), ( f"{id} does not have postgres password hash label" - ) # We currently assume that Postgres is for top-level components only and so there is a single segment - # write (or read) path - assert len(deployable_details.values_file_path.write_path) == 1 + ) helm_key = deployable_details.values_file_path.read_path[0] values_fragment = deployable_details.get_helm_values(values, PropertyType.Postgres) if values_fragment.get("password", {}).get("value", None): diff --git a/tests/manifests/test_pod_initContainers.py b/tests/manifests/test_pod_initContainers.py index b534d2bf..d5a45084 100644 --- a/tests/manifests/test_pod_initContainers.py +++ b/tests/manifests/test_pod_initContainers.py @@ -73,3 +73,19 @@ async def test_pod_redis_components_have_valkey_wait_init_container(values, make f"{pod_template_details.manifest_id} uses Redis/Valkey but doesn't wait for it " "with a valkey-wait initContainer" ) + + +@pytest.mark.parametrize("values_file", values_files_to_test) +@pytest.mark.asyncio_cooperative +async def test_pod_db_components_have_db_wait_init_container(values, make_templates): + for pod_template_details in iterate_pod_template(await make_templates(values)): + deployable_details = pod_template_details.deployable_details() + if not deployable_details.has_db: + continue + pod_spec = pod_template_details.pod_template["spec"] + init_container_names = [container["name"] for container in pod_spec.get("initContainers", [])] + # The syn2mas job waits for two databases, so its containers are named + # db-wait-mas and db-wait-syn. Other components use plain db-wait. + assert any(name.startswith("db-wait") for name in init_container_names), ( + f"{pod_template_details.manifest_id} uses Postgres but doesn't wait for it with a db-wait initContainer" + )