Skip to content

Commit d646c15

Browse files
androndoclaude
andcommitted
fix(clickhouse): scheme the backup S3_ENDPOINT on the system-bucket flow
On the useSystemBucket / cozy-default flow the chart pointed the clickhouse-backup sidecar's S3_ENDPOINT straight at the projected cozy-backups-creds.endpoint, which the backup credentials projector stores as a bare host by design. altinity/clickhouse-backup runs S3_ENDPOINT through the aws-sdk-go-v2 endpoint resolver, which rejects a scheme-less value with "Custom endpoint 's3.host' was not a valid URI", so every backup and restore on the default flow failed (reproduced on a live v1.6.2 cluster). ClickHouse was the only cozy-default app hit by this: the CNPG/etcd/velero strategies get a scheme'd URL from the backupstrategy-controller.endpoint helper, and mariadb/foundationdb deliberately pair a bare host with a TLS flag. Prepend https:// on the useSystemBucket path via a helper env plus $(VAR) expansion (a secretKeyRef value can't be string-interpolated), mirroring the platform's endpoint helper which force-prepends https for the always-TLS external S3 ingress. The legacy and bring-your-own-Secret paths keep reading endpoint verbatim, since that value is tenant-supplied and already carries its own scheme. Signed-off-by: Andrey Kolkov <[email protected]> Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
1 parent f5b957e commit d646c15

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎packages/apps/clickhouse/templates/clickhouse.yaml‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,23 @@ spec:
298298
{{- $secretOptional := .Values.backup.useSystemBucket }}
299299
- name: S3_BUCKET
300300
valueFrom: { secretKeyRef: { name: {{ $sidecarSecretName | quote }}, key: {{ $bucketKey | quote }}{{ if $secretOptional }}, optional: true{{ end }} } }
301+
{{- /*
302+
clickhouse-backup's aws-sdk-go-v2 client rejects a scheme-less
303+
S3_ENDPOINT ("was not a valid URI"). On the useSystemBucket flow
304+
the projected cozy-backups-creds.endpoint is a bare host, so
305+
prepend https:// (the platform's CNPG endpoint helper does the
306+
same). Legacy / BYO-Secret endpoints are tenant-supplied with
307+
their own scheme and are consumed verbatim.
308+
*/}}
309+
{{- if .Values.backup.useSystemBucket }}
310+
- name: S3_ENDPOINT_HOST
311+
valueFrom: { secretKeyRef: { name: {{ $sidecarSecretName | quote }}, key: {{ $endpointKey | quote }}, optional: true } }
301312
- name: S3_ENDPOINT
302-
valueFrom: { secretKeyRef: { name: {{ $sidecarSecretName | quote }}, key: {{ $endpointKey | quote }}{{ if $secretOptional }}, optional: true{{ end }} } }
313+
value: "https://$(S3_ENDPOINT_HOST)"
314+
{{- else }}
315+
- name: S3_ENDPOINT
316+
valueFrom: { secretKeyRef: { name: {{ $sidecarSecretName | quote }}, key: {{ $endpointKey | quote }} } }
317+
{{- end }}
303318
- name: S3_REGION
304319
valueFrom: { secretKeyRef: { name: {{ $sidecarSecretName | quote }}, key: {{ $regionKey | quote }}{{ if $secretOptional }}, optional: true{{ end }} } }
305320
- name: S3_ACCESS_KEY

‎packages/apps/clickhouse/tests/backup_test.yaml‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ tests:
5454
- equal:
5555
path: spec.templates.podTemplates[0].spec.containers[?(@.name=="clickhouse-backup")].env[?(@.name=="S3_SECRET_KEY")].valueFrom.secretKeyRef.name
5656
value: cozy-backups-creds
57+
# The projected endpoint is a bare host; clickhouse-backup needs a URI, so
58+
# the chart prepends https:// via env-var expansion on this flow.
59+
- equal:
60+
path: spec.templates.podTemplates[0].spec.containers[?(@.name=="clickhouse-backup")].env[?(@.name=="S3_ENDPOINT_HOST")].valueFrom.secretKeyRef.name
61+
value: cozy-backups-creds
62+
- equal:
63+
path: spec.templates.podTemplates[0].spec.containers[?(@.name=="clickhouse-backup")].env[?(@.name=="S3_ENDPOINT_HOST")].valueFrom.secretKeyRef.key
64+
value: endpoint
65+
- equal:
66+
path: spec.templates.podTemplates[0].spec.containers[?(@.name=="clickhouse-backup")].env[?(@.name=="S3_ENDPOINT")].value
67+
value: https://$(S3_ENDPOINT_HOST)
5768

5869
- it: "useSystemBucket=true: S3_FORCE_PATH_STYLE is sourced from cozy-backups-creds, not hardcoded"
5970
template: templates/clickhouse.yaml
@@ -111,6 +122,21 @@ tests:
111122
documentSelector:
112123
path: kind
113124
value: ClickHouseInstallation
125+
# Legacy endpoint is tenant-supplied (already carries a scheme), read verbatim
126+
# from the Secret with no https:// prepend and no S3_ENDPOINT_HOST indirection.
127+
- equal:
128+
path: spec.templates.podTemplates[0].spec.containers[?(@.name=="clickhouse-backup")].env[?(@.name=="S3_ENDPOINT")].valueFrom.secretKeyRef.name
129+
value: ch-test-backup-s3
130+
template: templates/clickhouse.yaml
131+
documentSelector:
132+
path: kind
133+
value: ClickHouseInstallation
134+
- notExists:
135+
path: spec.templates.podTemplates[0].spec.containers[?(@.name=="clickhouse-backup")].env[?(@.name=="S3_ENDPOINT_HOST")]
136+
template: templates/clickhouse.yaml
137+
documentSelector:
138+
path: kind
139+
value: ClickHouseInstallation
114140
- hasDocuments:
115141
count: 1
116142
template: templates/backup-strategy-secret.yaml

0 commit comments

Comments
 (0)