Skip to content

Commit b794f3a

Browse files
prometheus: enable readOnlyRootFilesystem
The Prometheus container previously required readOnlyRootFilesystem: false because prom-wrapper writes the Alertmanager configuration file to /sg_config_prometheus/alertmanager.yml at runtime whenever site config observability.alerts or SMTP settings change. Additionally, Alertmanager stores state (silences, notification log) at /alertmanager/. This change enables readOnlyRootFilesystem: true by: 1. Adding an emptyDir volume mounted at /alertmanager for Alertmanager state storage (--storage.path). 2. Setting ALERTMANAGER_CONFIG_PATH=/alertmanager/alertmanager.yml so prom-wrapper writes the Alertmanager config to the writable emptyDir instead of the read-only image layer at /sg_config_prometheus/. The /prometheus TSDB data path was already handled by the existing PVC, and /sg_prometheus_add_ons is already a ConfigMap mount. The baked-in alert rules at /sg_config_prometheus/ are read-only at runtime (only written at image build time), so they remain accessible on the read-only root filesystem. Resolves: https://github.com/sourcegraph/sourcegraph/issues/34012 Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019dbe72-f13d-7233-aa22-cbeb04d03182
1 parent 96562d4 commit b794f3a

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

charts/sourcegraph/templates/prometheus/prometheus.Deployment.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,24 @@ spec:
4747
- name: prometheus
4848
image: {{ include "sourcegraph.image" (list . "prometheus") }}
4949
imagePullPolicy: {{ .Values.sourcegraph.image.pullPolicy }}
50+
# Seed the Alertmanager config from the baked-in default on first start
51+
# so it works with readOnlyRootFilesystem. prom-wrapper then rewrites this
52+
# file in place whenever site config changes (see ALERTMANAGER_CONFIG_PATH).
53+
command:
54+
- /bin/sh
55+
- -c
56+
- |
57+
cp -n /sg_config_prometheus/alertmanager.yml /alertmanager/alertmanager.yml
58+
exec /usr/bin/prom-wrapper "$@"
59+
- prom-wrapper
5060
{{- with .Values.prometheus.args }}
5161
args:
5262
{{- toYaml . | nindent 8 }}
5363
{{- end }}
5464
terminationMessagePolicy: FallbackToLogsOnError
5565
env:
66+
- name: ALERTMANAGER_CONFIG_PATH
67+
value: /alertmanager/alertmanager.yml
5668
{{- range $name, $item := .Values.prometheus.env}}
5769
- name: {{ $name }}
5870
{{- $item | toYaml | nindent 10 }}
@@ -72,6 +84,9 @@ spec:
7284
name: data
7385
- mountPath: /sg_prometheus_add_ons
7486
name: config
87+
- mountPath: /alertmanager
88+
name: data
89+
subPath: alertmanager
7590
{{- if .Values.prometheus.extraVolumeMounts }}
7691
{{- toYaml .Values.prometheus.extraVolumeMounts | nindent 8 }}
7792
{{- end }}

charts/sourcegraph/values.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,8 +906,6 @@ prometheus:
906906
allowPrivilegeEscalation: false
907907
runAsUser: 100
908908
runAsGroup: 100
909-
# Read-only filesystem not supported for the prometheus container,
910-
# see [sourcegraph/issues/34012](https://github.com/sourcegraph/sourcegraph/issues/34012) for more information
911909
readOnlyRootFilesystem: false
912910
# -- Name used by resources. Does not affect service names or PVCs.
913911
name: "prometheus"

0 commit comments

Comments
 (0)