Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions charts/matrix-stack/templates/synapse/redis_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ spec:
ports:
- port: 6379
targetPort: redis
name: redis
selector:
app.kubernetes.io/instance: "{{ $.Release.Name }}-synapse-redis"
{{- end }}
Expand Down
1 change: 1 addition & 0 deletions newsfragments/244.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure all ports have names.
17 changes: 17 additions & 0 deletions tests/manifests/test_pod_containers_ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,20 @@ async def test_unique_ports_in_containers(templates):
for container in template["spec"]["template"]["spec"]["containers"]:
ports += [port["containerPort"] for port in container.get("ports", [])]
assert len(ports) == len(set(ports)), f"Ports are not unique: {id}, {ports}"


@pytest.mark.parametrize("values_file", values_files_to_test)
@pytest.mark.asyncio_cooperative
async def test_ports_in_containers_are_named(templates):
for template in templates:
if template["kind"] in ["Deployment", "StatefulSet", "Job"]:
id = f"{template['kind']}/{template['metadata']['name']}"

port_names = []
for container in template["spec"]["template"]["spec"]["containers"]:
for port in container.get("ports", []):
assert "name" in port, (
f"{id} has container {container['name']} which has a port without a name: {port}"
)
port_names.append(port["name"])
assert len(port_names) == len(set(port_names)), f"Port names are not unique: {id}, {port_names}"
23 changes: 23 additions & 0 deletions tests/manifests/test_services.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2025 New Vector Ltd
#
# SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial

import pytest

from . import values_files_to_test


@pytest.mark.parametrize("values_file", values_files_to_test)
@pytest.mark.asyncio_cooperative
async def test_ports_in_services_are_named(templates):
for template in templates:
if template["kind"] == "Service":
id = f"{template['kind']}/{template['metadata']['name']}"
assert "ports" in template["spec"], f"{id} does not specify a ports list"
assert len(template["spec"]["ports"]) > 0, f"{id} does not include any ports"

port_names = []
for port in template["spec"]["ports"]:
assert "name" in port, f"{id} has a port without a name: {port}"
port_names.append(port["name"])
assert len(port_names) == len(set(port_names)), f"Port names are not unique: {id}, {port_names}"
Loading