Files
cozystack/examples/backups/postgres/10-cnpg-strategy.yaml
T
Andrey KolkovandClaude Fable 5 67db8f7da7 fix(backups): make the barman-cloud serverName stable across every flow
Two defects of the same class — the WAL-archive S3 prefix (serverName)
changing or defaulting differently between components:

Recovery default regression (review blocker): native CNPG defaulted an
absent externalClusters serverName to the entry name (= bootstrap.oldName),
but the barman-cloud plugin defaults it to the NEW cluster's name, so a
legacy-flow restore with bootstrap.serverName unset would read the wrong
S3 prefix (hard failure, or silently restoring another cluster's data).
The chart now always emits serverName, defaulting to bootstrap.oldName.

Live-cluster serverName flip (found by the gated postgres backup e2e on a
real cluster): the chart renders spec.plugins without serverName
(effective prefix = cluster name) while a strategy template may name a
different one; the driver's ForceOwnership patch then flipped the prefix
mid-stream, splitting the WAL archive across two prefixes — the WAL
holding the backup's start was lost between them and the restore failed
with "WAL not found". The driver now preserves the live Cluster's
effective serverName (explicit parameter, or the cluster name when the
plugin is attached without one) and only applies the strategy's value to
a Cluster with no plugin attached; both charts pin serverName explicitly,
and the example strategy no longer sets one.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Andrey Kolkov <androndo@gmail.com>
2026-07-16 21:44:41 +04:00

43 lines
1.9 KiB
YAML

# CNPG backup strategy. String fields are go-templated against the live
# Postgres application object (.Application) and BackupClass parameters
# (.Parameters), letting one strategy CR serve every Postgres instance in
# the tenant.
---
apiVersion: strategy.backups.cozystack.io/v1alpha1
kind: CNPG
metadata:
name: cnpg-strategy-default
spec:
template:
# serverName (the WAL-archive S3 prefix) is intentionally NOT set: the
# driver preserves whatever prefix the live cnpg.io Cluster already
# archives under (the chart pins it to the Helm release name,
# postgres-<app>), and only a cluster with no plugin attached would take a
# strategy-supplied value. Setting a different name here would be ignored
# for chart-managed clusters and would only cause confusion.
barmanObjectStore:
# destinationPath uses the COSI BucketClaim's actual bucket name (look
# it up via `kubectl -n <ns> get bucketclaim bucket-<name> -o
# jsonpath='{.status.bucketName}'`). The endpointURL is the S3 endpoint
# advertised in the BucketInfo Secret.
destinationPath: "s3://REPLACE_WITH_COSI_BUCKET_NAME/{{ .Application.metadata.name }}/"
endpointURL: "https://REPLACE_WITH_S3_ENDPOINT"
retentionPolicy: "30d"
# endpointCA is required when the S3 endpoint serves a self-signed
# certificate (the cozystack default seaweedfs-s3 ingress qualifies).
# Point this Secret at a key holding the PEM-encoded CA bundle - for
# cozystack's seaweedfs you can copy `seaweedfs-ca-cert.ca.crt` from
# the parent tenant. Drop the block entirely when the endpoint's
# certificate is signed by a publicly-trusted CA.
endpointCA:
secretRef:
name: "{{ .Application.metadata.name }}-cnpg-backup-ca"
key: "ca.crt"
s3Credentials:
secretRef:
name: "{{ .Application.metadata.name }}-cnpg-backup-creds"
data:
compression: gzip
wal:
compression: gzip