Skip to content

Commit 34139b4

Browse files
committed
Expose the ESS version and edition in an API
1 parent 569cdae commit 34139b4

File tree

5 files changed

+74
-0
lines changed

5 files changed

+74
-0
lines changed

charts/matrix-stack/configs/synapse/partial-haproxy.cfg.tpl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,31 @@ frontend synapse-http-in
125125

126126
acl backend_unavailable str(),concat('synapse-',req.backend),nbsrv lt 1
127127

128+
acl ess_version path /_synapse/ess/version
129+
use_backend ess-version-static if ess_version
130+
128131
{{- if $hasFailoverBackend }}
129132
use_backend synapse-main-failover if has_failover backend_unavailable
130133
{{- end }}
131134

132135
use_backend synapse-%[var(req.backend)]
133136

137+
backend ess-version-static
138+
mode http
139+
140+
# Set all the same headers as the well-knowns
141+
http-after-response set-header X-Frame-Options SAMEORIGIN
142+
http-after-response set-header X-Content-Type-Options nosniff
143+
http-after-response set-header X-XSS-Protection "1; mode=block"
144+
http-after-response set-header Content-Security-Policy "frame-ancestors 'self'"
145+
http-after-response set-header X-Robots-Tag "noindex, nofollow, noarchive, noimageindex"
146+
147+
http-after-response set-header Access-Control-Allow-Origin *
148+
http-after-response set-header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
149+
http-after-response set-header Access-Control-Allow-Headers "X-Requested-With, Content-Type, Authorization"
150+
151+
http-request return status 200 content-type "application/json" file /synapse/ess-version.json
152+
134153
backend synapse-main
135154
default-server maxconn 250
136155

charts/matrix-stack/templates/synapse/_helpers.tpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ path_map_file: |
229229
{{- (tpl ($root.Files.Get "configs/synapse/path_map_file.tpl") (dict "root" $root)) | nindent 2 }}
230230
path_map_file_get: |
231231
{{- (tpl ($root.Files.Get "configs/synapse/path_map_file_get.tpl") (dict "root" $root)) | nindent 2 -}}
232+
{{- /* We accept this means that the ConfigMap & all hash labels using this helper changes on every chart version upgrade and the HAProxy will restart as a result.
233+
When we have a process to watch for file changes and send a reload signal to HAProxy this can move out of this helper and into the `ConfigMap` proper. */}}
234+
ess-version.json: |-
235+
{"version": "{{ $root.Chart.Version }}", "edition": "community"}
232236
{{- end -}}
233237

234238
{{- define "element-io.synapse.render-config-container" -}}

newsfragments/715.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add `/_synapse/ess/version` to the Synapse ingress exposing the chart version and edition.

tests/integration/test_synapse.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,40 @@
2727
)
2828

2929

30+
@pytest.mark.skipif(value_file_has("synapse.enabled", False), reason="Synapse not deployed")
31+
@pytest.mark.asyncio_cooperative
32+
async def test_synapse_exposes_chart_version_edition(
33+
ingress_ready,
34+
ssl_context,
35+
generated_data: ESSData,
36+
helm_client: pyhelm3.Client,
37+
):
38+
await ingress_ready("synapse")
39+
40+
revision = await helm_client.get_current_revision(
41+
generated_data.release_name, namespace=generated_data.ess_namespace
42+
)
43+
metadata = await revision.chart_metadata()
44+
45+
# TODO: Dropme sometime in the future when we do not care about testing against 25.8.3 any more
46+
if semver.Version.is_valid(metadata.version) and semver.VersionInfo.parse(metadata.version).compare("25.8.3") <= 0:
47+
with pytest.raises(aiohttp.client_exceptions.ClientResponseError) as execinfo:
48+
await aiohttp_get_json(
49+
f"https://synapse.{generated_data.server_name}/_synapse/ess/version", {}, ssl_context
50+
)
51+
assert execinfo.value.status == 404
52+
return
53+
54+
json_content = await aiohttp_get_json(
55+
f"https://synapse.{generated_data.server_name}/_synapse/ess/version", {}, ssl_context
56+
)
57+
assert "edition" in json_content
58+
assert json_content["edition"] == "community"
59+
60+
assert "version" in json_content
61+
assert json_content["version"] == metadata.version
62+
63+
3064
@pytest.mark.skipif(value_file_has("synapse.enabled", False), reason="Synapse not deployed")
3165
@pytest.mark.asyncio_cooperative
3266
async def test_synapse_can_access_client_api(

tests/manifests/test_pod_idempotency.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,22 @@ async def _patch_version_chart():
4242
)
4343
first_render[id]["metadata"]["labels"].pop("helm.sh/chart")
4444
second_render[id]["metadata"]["labels"].pop("helm.sh/chart")
45+
46+
# This will always vary even when we have a sidecar process to send a reload signal to HAProxy
47+
if id == f"ConfigMap/{release_name}-synapse-haproxy":
48+
first_render[id]["data"].pop("ess-version.json")
49+
second_render[id]["data"].pop("ess-version.json")
50+
# We can either remove this label as a whole or remove `ess-version.json` for the calculation for this label
51+
# when we have a sidecar process to send a reload signal to HAProxy. If we have that sidecar process the
52+
# rationale for the hash label disappears.
53+
elif id == f"Deployment/{release_name}-haproxy":
54+
first_render[id]["metadata"]["labels"].pop("k8s.element.io/synapse-haproxy-config-hash")
55+
second_render[id]["metadata"]["labels"].pop("k8s.element.io/synapse-haproxy-config-hash")
56+
first_render[id]["spec"]["template"]["metadata"]["labels"].pop("k8s.element.io/synapse-haproxy-config-hash")
57+
second_render[id]["spec"]["template"]["metadata"]["labels"].pop(
58+
"k8s.element.io/synapse-haproxy-config-hash"
59+
)
60+
4561
assert first_render[id] == second_render[id], (
4662
f"Error with {template_id(first_render[id])} : "
4763
"Templates should be the same after removing the chart version label as it should be the only difference"

0 commit comments

Comments
 (0)