db(portal): migrate WAL archiving to the CNPG-I Barman Cloud plugin

CloudNativePG 1.30 deprecates spec.backup.barmanObjectStore and 1.31 removes
it, so the pin on 1.30.0 was a hard gate. This closes that gate:

- Vendors plugin-barman-cloud v0.16.0 verbatim into
  infrastructure/databases/base/upstream/ (the operator manifest's pattern),
  with a kustomize patch only for --log-level=info and resource bounds.
  v0.16.0 requires CNPG >= 1.30 and is registered through Service
  annotations; its operator<->plugin mTLS pair comes from cert-manager
  (previous commit).
- Adds ObjectStore sirius-growth/portal-wal: the literal translation of the
  retired barmanObjectStore block, with retentionPolicy 14d moved off the
  Cluster (in the plugin, retention belongs to the store).
- Cluster portal drops spec.backup entirely and gains spec.plugins
  (barman-cloud.cloudnative-pg.io, isWALArchiver, barmanObjectName
  portal-wal, serverName portal). The server name is the barman prefix, so
  the plugin keeps writing s3://pg-wal-archive/portal/{base,wals}/... — the
  same objects the in-tree archiver left behind; the 14-day window stays
  readable.
- ScheduledBackup portal-daily switches to method: plugin.
- databases waits on cert-manager; apps waits on databases (the ObjectStore
  CRD ships with the plugin).
- CNPG dashboard: the backup timestamp metric family changes name under the
  plugin, so the panel now accepts both.
This commit is contained in:
devops 2026-11-19 17:58:12 -05:00
commit c45255242b
11 changed files with 1312 additions and 51 deletions

View file

@ -27,49 +27,35 @@ spec:
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Point-in-time recovery: continuous WAL archiving + daily base backups into # Point-in-time recovery: continuous WAL archiving + daily base backups into
# Garage on the Linode hub (10.10.0.5), i.e. a different power and internet # Garage on the Linode hub (10.10.0.5), i.e. a different power and internet
# domain from this primary. Companion object: ScheduledBackup portal-daily. # domain from this primary. Companion objects: ObjectStore portal-wal (the
# store + 14d retention) and ScheduledBackup portal-daily.
#
# This is the CNPG-I Barman Cloud **plugin** (Deployment cnpg-system/barman-cloud,
# vendored in infrastructure/databases/base), not the operator's in-tree
# barman-cloud support: 1.30 deprecates the in-tree path and 1.31 removes it
# (`Warning: Native support for Barman Cloud backups and recovery is
# deprecated ...`). See objectstore-portal-wal.yaml for the store definition.
#
# `serverName: portal` is the barman prefix and must stay exactly the cluster
# name: the plugin writes to s3://pg-wal-archive/portal/{base,wals}/... — the
# same objects the in-tree archiver left behind, so the existing 14-day window
# stays restorable. Changing it starts a new prefix and abandons that window.
# #
# Credentials live in Secret sirius-growth/portal-wal-s3 (created out of band # Credentials live in Secret sirius-growth/portal-wal-s3 (created out of band
# from the Garage key `cnpg-portal-wal`, id GK7f2b4bb1fc9abaec50fde37b, scope # from the Garage key `cnpg-portal-wal`, id GK7f2b4bb1fc9abaec50fde37b, scope
# read+write on bucket `pg-wal-archive` only). Never commit the key values. # read+write on bucket `pg-wal-archive` only). Never commit the key values.
# #
# This uses the operator's in-tree barman-cloud integration rather than the
# CNPG-I barman-cloud plugin: same barman-cloud binaries, no extra Deployment
# and TLS plugin registration to keep alive on a 3-node homelab. The plugin is
# the migration path when 1.30's in-tree support is finally removed.
#
# `pg_dump` in forgejo/cluster-backup still runs nightly for this database as # `pg_dump` in forgejo/cluster-backup still runs nightly for this database as
# a second, logical copy: a dump survives a barman-format regression or a # a second, logical copy: a dump survives a barman-format regression or a
# store that has been emptied, and it is the only copy that is readable # store that has been emptied, and it is the only copy that is readable
# without barman. Belt and braces, not redundancy theatre — the RPO comes # without barman. Belt and braces, not redundancy theatre — the RPO comes
# from the WAL archive, not from the dump. # from the WAL archive, not from the dump.
backup: plugins:
retentionPolicy: "14d" - name: barman-cloud.cloudnative-pg.io
barmanObjectStore: isWALArchiver: true
# Bucket root, not bucket/portal: barman appends the server name (which parameters:
# defaults to the Cluster name), so the archive lives at barmanObjectName: portal-wal
# s3://pg-wal-archive/portal/{base,wals}/... — one prefix per cluster, serverName: portal
# which is what lets forgejo/pg share this bucket later without colliding.
destinationPath: s3://pg-wal-archive
endpointURL: http://10.10.0.5:3900
s3Credentials:
accessKeyId:
name: portal-wal-s3
key: ACCESS_KEY_ID
secretAccessKey:
name: portal-wal-s3
key: ACCESS_SECRET_KEY
region:
name: portal-wal-s3
key: REGION
# gzip on both: this is a WAL stream over the WireGuard mesh to a fixed
# 20 GB store, so bytes on the wire and in the bucket are the cost.
wal:
compression: gzip
maxParallel: 2
data:
compression: gzip
jobs: 2
# Scraped via podmonitor.yaml in this directory (hand-written; see the comment # Scraped via podmonitor.yaml in this directory (hand-written; see the comment
# in apps/base/forgejo/podmonitor.yaml for why enablePodMonitor is false). # in apps/base/forgejo/podmonitor.yaml for why enablePodMonitor is false).
# Only the operator's default query set here — this database needs no custom # Only the operator's default query set here — this database needs no custom

View file

@ -14,6 +14,8 @@ resources:
- service-blog.yaml - service-blog.yaml
- service-portal-gate.yaml - service-portal-gate.yaml
- httproute.yaml - httproute.yaml
# The WAL archive store must exist before the Cluster references it.
- objectstore-portal-wal.yaml
- cluster.yaml - cluster.yaml
- scheduled-backup.yaml - scheduled-backup.yaml
- podmonitor.yaml - podmonitor.yaml

View file

@ -0,0 +1,51 @@
# The WAL archive for Cluster sirius-growth/portal, in the CNPG-I Barman Cloud
# plugin's own CR instead of Cluster.spec.backup.barmanObjectStore.
#
# Same store, same layout: destinationPath is the *bucket root* and the plugin
# appends the server name (Cluster.spec.plugins[].parameters.serverName, set to
# `portal`), so the existing objects stay exactly where the in-tree archiver put
# them — s3://pg-wal-archive/portal/{base,wals}/... . Anything that changes the
# prefix silently abandons the 14-day window that is already in the bucket.
#
# `spec.configuration` is the literal translation of the retired
# `spec.backup.barmanObjectStore` block (same schema, same Secret), and
# `retentionPolicy` moved here from Cluster.spec.backup.retentionPolicy — in the
# plugin architecture retention is a property of the store, not the cluster.
#
# Credentials: Secret sirius-growth/portal-wal-s3 (Garage key `cnpg-portal-wal`,
# id GK7f2b4bb1fc9abaec50fde37b, RW on bucket `pg-wal-archive` only), created
# out of band. The key values are deliberately not in git.
apiVersion: barmancloud.cnpg.io/v1
kind: ObjectStore
metadata:
name: portal-wal
namespace: sirius-growth
spec:
configuration:
destinationPath: s3://pg-wal-archive
endpointURL: http://10.10.0.5:3900
s3Credentials:
accessKeyId:
name: portal-wal-s3
key: ACCESS_KEY_ID
secretAccessKey:
name: portal-wal-s3
key: ACCESS_SECRET_KEY
region:
name: portal-wal-s3
key: REGION
# gzip on both directions: this is a WAL stream over the WireGuard mesh into
# a 20 GB store on the Linode, so bytes on the wire and in the bucket are
# the cost. Must match what the in-tree archiver wrote (gzip) — the
# archive is read by segment, but a mismatch in base-backup compression
# would make the existing base backups unrestorable.
wal:
compression: gzip
maxParallel: 2
data:
compression: gzip
jobs: 2
# Enforced by the plugin instance sidecar every 30 min (default
# retentionPolicyIntervalSeconds) with barman-cloud's retention logic, i.e.
# the same 14-day window the in-tree archiver maintained.
retentionPolicy: "14d"

View file

@ -12,8 +12,13 @@ spec:
name: portal name: portal
# `self`: the Backup objects are owned by this ScheduledBackup, so deleting the # `self`: the Backup objects are owned by this ScheduledBackup, so deleting the
# schedule (or the namespace) does not leave orphaned Backups pointing at the # schedule (or the namespace) does not leave orphaned Backups pointing at the
# cluster. Retention/cleanup of the archive itself is the Cluster's # cluster. Retention/cleanup of the archive itself is the ObjectStore's
# spec.backup.retentionPolicy (14d), enforced by barman-cloud on each backup. # spec.retentionPolicy (14d), enforced by the plugin's sidecar.
backupOwnerReference: self backupOwnerReference: self
method: barmanObjectStore # Plugin method, not `barmanObjectStore`: the in-tree method is removed in
# CNPG 1.31. `pluginConfiguration` names the CNPG-I plugin, whose
# ObjectStore is referenced by the Cluster's spec.plugins.
method: plugin
pluginConfiguration:
name: barman-cloud.cloudnative-pg.io
immediate: false immediate: false

View file

@ -15,3 +15,7 @@ spec:
prune: true prune: true
dependsOn: dependsOn:
- name: infrastructure - name: infrastructure
# `sirius-growth` now carries an `ObjectStore` (barmancloud.cnpg.io) whose
# CRD ships with the plugin in the `databases` Kustomization, and the
# portal Cluster references it. Apply apps only after that CRD exists.
- name: databases

View file

@ -11,9 +11,15 @@ spec:
kind: GitRepository kind: GitRepository
name: flux-system name: flux-system
path: ./infrastructure/databases/base path: ./infrastructure/databases/base
# The CloudNativePG operator bundle contains its 11 CRDs. Those must never be # The CloudNativePG operator bundle contains its 11 CRDs, and the vendored
# pruned automatically: dropping them would delete every Cluster/Database # Barman Cloud plugin adds the `ObjectStore` CRD. Those must never be pruned
# automatically: dropping them would delete every Cluster/Database/Backup
# object (and the Forgejo and portal Postgres clusters with them). Same # object (and the Forgejo and portal Postgres clusters with them). Same
# reasoning as gateway-api-crds. Reverting the operator Deployment args is a # reasoning as gateway-api-crds. Reverting the operator Deployment args is a
# git change, not a prune. # git change, not a prune.
prune: false prune: false
# The plugin's operator<->plugin mTLS pair is issued by cert-manager
# (Issuer/Certificate in the vendored plugin manifest). Applying those before
# the cert-manager CRDs and webhook exist just churns; wait for it.
dependsOn:
- name: cert-manager

View file

@ -1,4 +1,4 @@
# CloudNativePG operator, pinned at 1.30.0. # CloudNativePG operator, pinned at 1.30.0, plus the CNPG-I Barman Cloud plugin.
# #
# The operator was installed by hand at some point and Flux did not own it, so # The operator was installed by hand at some point and Flux did not own it, so
# a kubectl patch was lost on every reinstall. The upstream release manifest is # a kubectl patch was lost on every reinstall. The upstream release manifest is
@ -7,9 +7,21 @@
# and patched only for the deltas that already existed live plus the widened # and patched only for the deltas that already existed live plus the widened
# leader-election window. Do not upgrade the version in this directory without # leader-election window. Do not upgrade the version in this directory without
# a separate, tested change: the CRDs are in this bundle. # a separate, tested change: the CRDs are in this bundle.
#
# The Barman Cloud plugin is the replacement for the in-tree barman-cloud
# integration that 1.30 still ships but deprecates (removed in 1.31). Also
# vendored verbatim (sha256
# aee614683892dd4b44ff9f7afaca55254f1c28de17abbaa0552bf2e1228f7155,
# https://github.com/cloudnative-pg/plugin-barman-cloud/releases/download/v0.16.0/manifest.yaml):
# a separate Deployment in cnpg-system, registered with the operator through
# Service annotations, carrying the `ObjectStore` CRD (barmancloud.cnpg.io). Its
# operator<->plugin mTLS pair is issued by cert-manager (Flux Kustomization
# `cert-manager`). v0.16.0 requires CloudNativePG >= 1.30 — satisfied above.
apiVersion: kustomize.config.k8s.io/v1beta1 apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization kind: Kustomization
resources: resources:
- upstream/cnpg-1.30.0.yaml - upstream/cnpg-1.30.0.yaml
- upstream/plugin-barman-cloud-0.16.0.yaml
patches: patches:
- path: patch-controller-manager.yaml - path: patch-controller-manager.yaml
- path: patch-barman-cloud.yaml

View file

@ -0,0 +1,36 @@
# Delta on the vendored Barman Cloud plugin manifest (0.16.0).
#
# Upstream ships the plugin operator with `--log-level=debug`. On this cluster
# nothing scrapes the plugin's logs and siriussec's root filesystem is the
# tightest disk in the estate, so the arg is lowered to `info`. Everything else
# in the release manifest is used verbatim — including the Service annotations
# (`cnpg.io/pluginName`, `cnpg.io/pluginPort`, `cnpg.io/pluginClientSecret`,
# `cnpg.io/pluginServerSecret`) that are the actual CNPG-I registration.
#
# The whole `args` list is restated because strategic merge replaces a container
# `args` list rather than merging it.
apiVersion: apps/v1
kind: Deployment
metadata:
name: barman-cloud
namespace: cnpg-system
spec:
template:
spec:
containers:
- name: barman-cloud
args:
- operator
- --server-cert=/server/tls.crt
- --server-key=/server/tls.key
- --client-cert=/client/tls.crt
- --server-address=:9090
- --leader-elect
- --log-level=info
resources:
requests:
cpu: 50m
memory: 64Mi
limits:
cpu: 500m
memory: 256Mi

File diff suppressed because it is too large Load diff

View file

@ -245,9 +245,9 @@ cnpg = [
{"h": 5, "w": 4, "x": 16, "y": 1}, {"h": 5, "w": 4, "x": 16, "y": 1},
desc="1 = the operator is asking for a manual switchover (e.g. after a fencing event).", desc="1 = the operator is asking for a manual switchover (e.g. after a fencing event).",
thresholds=[{"color": "green", "value": None}, {"color": "red", "value": 1}]), thresholds=[{"color": "green", "value": None}, {"color": "red", "value": 1}]),
stat("Last available backup", [target('max by (namespace) (cnpg_collector_last_available_backup_timestamp{%s})' % CLUSTER_NS)], stat("Last available backup", [target('max by (namespace) (cnpg_collector_last_available_backup_timestamp{%s} or barman_cloud_cloudnative_pg_io_last_available_backup_timestamp{%s})' % (CLUSTER_NS, CLUSTER_NS))],
{"h": 5, "w": 4, "x": 20, "y": 1}, unit="dateTimeAsIso", {"h": 5, "w": 4, "x": 20, "y": 1}, unit="dateTimeAsIso",
desc="0 = never. There are NO Backup/Cluster backup resources in this cluster (verified: `kubectl get backups.postgresql.cnpg.io -A` is empty), so a 0 here is the honest answer, not a broken panel.", desc="0 = never. sirius-growth/portal archives through the CNPG-I Barman Cloud plugin, which exposes its own metric family `barman_cloud_cloudnative_pg_io_*`; the in-tree `cnpg_collector_*` name is kept in the `or` for any cluster still on the deprecated path. A 0 means neither series exists.",
thresholds=[{"color": "red", "value": None}, {"color": "green", "value": 1}]), thresholds=[{"color": "red", "value": None}, {"color": "green", "value": 1}]),
row("Throughput", 6), row("Throughput", 6),
@ -280,10 +280,10 @@ cnpg = [
desc="pg_database_size. Both PVs are 10Gi (forgejo/pg) and 5Gi (sirius-growth/portal) — this is the trend that fills them."), desc="pg_database_size. Both PVs are 10Gi (forgejo/pg) and 5Gi (sirius-growth/portal) — this is the trend that fills them."),
ts("WAL generation", [target('sum by (namespace) (rate(cnpg_collector_wal_bytes{%s}[5m]))' % CLUSTER_NS, "{{namespace}}")], ts("WAL generation", [target('sum by (namespace) (rate(cnpg_collector_wal_bytes{%s}[5m]))' % CLUSTER_NS, "{{namespace}}")],
{"h": 8, "w": 8, "x": 8, "y": 25}, unit="Bps", {"h": 8, "w": 8, "x": 8, "y": 25}, unit="Bps",
desc="Bytes of WAL written per second. On a cluster with no backups, WAL has nothing archiving it away."), desc="Bytes of WAL written per second. sirius-growth/portal archives its WAL to the Linode Garage; forgejo/pg does not archive, so its WAL only ever fills the pg_wal directory."),
ts("WAL archiver failures", [target('max by (namespace) (cnpg_pg_stat_archiver_failed_count{%s})' % CLUSTER_NS, "{{namespace}}")], ts("WAL archiver failures", [target('max by (namespace) (cnpg_pg_stat_archiver_failed_count{%s})' % CLUSTER_NS, "{{namespace}}")],
{"h": 8, "w": 8, "x": 16, "y": 25}, unit="short", {"h": 8, "w": 8, "x": 16, "y": 25}, unit="short",
desc="pg_stat_archiver.failed_count. Archiving is not configured on either cluster (no ObjectStore/backup), so treat non-zero here as 'something was attempted and failed'."), desc="pg_stat_archiver.failed_count. Archiving is configured only on sirius-growth/portal (Barman Cloud plugin -> Linode Garage); forgejo/pg has no archiver, so any non-zero value is the honest signal that WAL failed to reach the archive."),
row("Replication (single instance — panels are honest about it)", 33), row("Replication (single instance — panels are honest about it)", 33),
ts("Replication lag", [target('max by (namespace) (cnpg_pg_replication_lag{%s})' % CLUSTER_NS, "{{namespace}}")], ts("Replication lag", [target('max by (namespace) (cnpg_pg_replication_lag{%s})' % CLUSTER_NS, "{{namespace}}")],
@ -294,9 +294,11 @@ cnpg = [
{"h": 6, "w": 8, "x": 8, "y": 34}, unit="short", {"h": 6, "w": 8, "x": 8, "y": 34}, unit="short",
desc="Both clusters run instances: 1, so 0 streaming replicas and in_recovery=0 is the correct reading. A future replica would light these up with no dashboard change."), desc="Both clusters run instances: 1, so 0 streaming replicas and in_recovery=0 is the correct reading. A future replica would light these up with no dashboard change."),
note("Known unknowns on the CNPG board", """\ note("Known unknowns on the CNPG board", """\
- **No backups exist.** `kubectl get backups.postgresql.cnpg.io -A` returns nothing; neither Cluster - **Backups exist on one cluster only.** `sirius-growth/portal` archives WAL + daily base backups
declares `spec.backup`. The "Last available backup" stat therefore reads 0 (never) — that is the through the CNPG-I Barman Cloud plugin (`ObjectStore portal-wal`) into the Linode Garage;
real state, not a missing metric. `forgejo/pg` has no archiver by design. The "Last available backup" stat reads 0 only if neither
the plugin's `barman_cloud_cloudnative_pg_io_last_available_backup_timestamp` nor the legacy
`cnpg_collector_last_available_backup_timestamp` series exists.
- **Single instance.** Both clusters run `instances: 1`, so replication lag / streaming replicas / - **Single instance.** Both clusters run `instances: 1`, so replication lag / streaming replicas /
in recovery are structurally zero. The panels show the zero and say so instead of hiding them. in recovery are structurally zero. The panels show the zero and say so instead of hiding them.
- **Query age vs transaction age.** CNPG's default query set exposes - **Query age vs transaction age.** CNPG's default query set exposes

View file

@ -423,7 +423,7 @@ data:
"id": 29, "id": 29,
"type": "stat", "type": "stat",
"title": "Last available backup", "title": "Last available backup",
"description": "0 = never. There are NO Backup/Cluster backup resources in this cluster (verified: `kubectl get backups.postgresql.cnpg.io -A` is empty), so a 0 here is the honest answer, not a broken panel.", "description": "0 = never. sirius-growth/portal archives through the CNPG-I Barman Cloud plugin, which exposes its own metric family `barman_cloud_cloudnative_pg_io_*`; the in-tree `cnpg_collector_*` name is kept in the `or` for any cluster still on the deprecated path. A 0 means neither series exists.",
"datasource": { "datasource": {
"type": "prometheus", "type": "prometheus",
"uid": "prometheus" "uid": "prometheus"
@ -440,7 +440,7 @@ data:
"type": "prometheus", "type": "prometheus",
"uid": "prometheus" "uid": "prometheus"
}, },
"expr": "max by (namespace) (cnpg_collector_last_available_backup_timestamp{namespace=~\"$namespace\"})", "expr": "max by (namespace) (cnpg_collector_last_available_backup_timestamp{namespace=~\"$namespace\"} or barman_cloud_cloudnative_pg_io_last_available_backup_timestamp{namespace=~\"$namespace\"})",
"refId": "A", "refId": "A",
"editorMode": "code", "editorMode": "code",
"range": true, "range": true,
@ -937,7 +937,7 @@ data:
"id": 40, "id": 40,
"type": "timeseries", "type": "timeseries",
"title": "WAL generation", "title": "WAL generation",
"description": "Bytes of WAL written per second. On a cluster with no backups, WAL has nothing archiving it away.", "description": "Bytes of WAL written per second. sirius-growth/portal archives its WAL to the Linode Garage; forgejo/pg does not archive, so its WAL only ever fills the pg_wal directory.",
"datasource": { "datasource": {
"type": "prometheus", "type": "prometheus",
"uid": "prometheus" "uid": "prometheus"
@ -994,7 +994,7 @@ data:
"id": 41, "id": 41,
"type": "timeseries", "type": "timeseries",
"title": "WAL archiver failures", "title": "WAL archiver failures",
"description": "pg_stat_archiver.failed_count. Archiving is not configured on either cluster (no ObjectStore/backup), so treat non-zero here as 'something was attempted and failed'.", "description": "pg_stat_archiver.failed_count. Archiving is configured only on sirius-growth/portal (Barman Cloud plugin -> Linode Garage); forgejo/pg has no archiver, so any non-zero value is the honest signal that WAL failed to reach the archive.",
"datasource": { "datasource": {
"type": "prometheus", "type": "prometheus",
"uid": "prometheus" "uid": "prometheus"
@ -1203,7 +1203,7 @@ data:
"showLineNumbers": false, "showLineNumbers": false,
"showMiniMap": false "showMiniMap": false
}, },
"content": "- **No backups exist.** `kubectl get backups.postgresql.cnpg.io -A` returns nothing; neither Cluster\n declares `spec.backup`. The \"Last available backup\" stat therefore reads 0 (never) \u2014 that is the\n real state, not a missing metric.\n- **Single instance.** Both clusters run `instances: 1`, so replication lag / streaming replicas /\n in recovery are structurally zero. The panels show the zero and say so instead of hiding them.\n- **Query age vs transaction age.** CNPG's default query set exposes\n `cnpg_backends_max_tx_duration_seconds` (transaction age). Per-statement `query_start` age is not in\n the default set; adding it would need another custom query in the cluster's\n `customQueriesConfigMap`.\n- **Permissions.** Custom queries run as `cnpg_metrics_exporter`, not superuser. See\n docs/monitoring-dashboards.md for the GRANT the Forgejo Actions metrics need.\n" "content": "- **Backups exist on one cluster only.** `sirius-growth/portal` archives WAL + daily base backups\n through the CNPG-I Barman Cloud plugin (`ObjectStore portal-wal`) into the Linode Garage;\n `forgejo/pg` has no archiver by design. The \"Last available backup\" stat reads 0 only if neither\n the plugin's `barman_cloud_cloudnative_pg_io_last_available_backup_timestamp` nor the legacy\n `cnpg_collector_last_available_backup_timestamp` series exists.\n- **Single instance.** Both clusters run `instances: 1`, so replication lag / streaming replicas /\n in recovery are structurally zero. The panels show the zero and say so instead of hiding them.\n- **Query age vs transaction age.** CNPG's default query set exposes\n `cnpg_backends_max_tx_duration_seconds` (transaction age). Per-statement `query_start` age is not in\n the default set; adding it would need another custom query in the cluster's\n `customQueriesConfigMap`.\n- **Permissions.** Custom queries run as `cnpg_metrics_exporter`, not superuser. See\n docs/monitoring-dashboards.md for the GRANT the Forgejo Actions metrics need.\n"
} }
} }
] ]