Skip to content

Commit 7623172

Browse files
committed
Omit the UDP port range metadata for Matrix RTC's SFU if the range is larger than 100 ports.
1 parent 7f80ff1 commit 7623172

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

charts/matrix-stack/templates/matrix-rtc/sfu_deployment.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ spec:
114114
{{- if .enabled }}
115115
{{- $portType := .type -}}
116116
{{- with .portRange }}
117+
{{- /* container.port is metadata. Omit if a large range is provided so that we don't run into document size limits when submitting to the API server */ -}}
118+
{{- if le (sub (.endPort | int) (.startPort | int)) 100 }}
117119
{{- range $port := untilStep (.startPort | int) (.endPort | int) 1 }}
118120
- containerPort: {{ $port }}
119121
name: rtc-udp-{{ $port }}
@@ -123,6 +125,7 @@ spec:
123125
{{- end }}
124126
{{- end }}
125127
{{- end }}
128+
{{- end }}
126129
{{- end }}
127130
{{- end }}
128131
{{- end }}

newsfragments/549.changed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Omit the UDP port range metadata for Matrix RTC's SFU if the range is larger than 100 ports.

tests/manifests/test_pod_containers_ports.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async def test_unique_ports_in_containers(templates):
2323
@pytest.mark.asyncio_cooperative
2424
async def test_ports_in_containers_are_named(templates):
2525
for template in templates:
26-
if template["kind"] in ["Deployment", "StatefulSet", "Job"]:
26+
if template["kind"] in ["Deployment", "StatefulSet"]:
2727
port_names = []
2828
for container in template["spec"]["template"]["spec"]["containers"]:
2929
for port in container.get("ports", []):
@@ -45,3 +45,21 @@ async def test_no_ports_in_jobs(templates):
4545
for container in template["spec"]["template"]["spec"]["containers"]:
4646
ports += [port["containerPort"] for port in container.get("ports", [])]
4747
assert len(ports) == 0, f"Ports are present in job: {template_id(template)}, {ports}"
48+
49+
50+
@pytest.mark.parametrize("values_file", values_files_to_test)
51+
@pytest.mark.asyncio_cooperative
52+
async def test_not_too_many_container_ports(templates):
53+
for template in templates:
54+
if template["kind"] in ["Deployment", "StatefulSet"]:
55+
for container in template["spec"]["template"]["spec"]["containers"]:
56+
number_of_ports = len(container.get("ports", []))
57+
# This limit is fairly arbitrary. Unlike with Services (which have a limit of 250 ports),
58+
# there doesn't appear to be a hard limit of number of ports on a Pod/container. However if
59+
# you go wild you hit maximum document size when attempting to put the manifest into the
60+
# cluster. 100 is chosen as anything more quickly makes `kubectl {describe,get}` unusable.
61+
# Container ports are "just" metadata, albeit one which helps the scheduler if `hostPorts`
62+
# are involved
63+
assert number_of_ports < 100, (
64+
f"{template_id(template)}/{container['name']} has too many ports ({number_of_ports} >= 100)"
65+
)

0 commit comments

Comments
 (0)