K8SPG-1086: Add logVolumeClaimSpec to store logs on a separate PVC - #1760
K8SPG-1086: Add logVolumeClaimSpec to store logs on a separate PVC#1760yoav-katz wants to merge 9 commits into
Conversation
|
questions for reviewers:
|
|
hi @yoav-katz
yes, we lack such a test. adding it would be great.
i don't think this can make into v3.1.0, we should gate on 3.2.0 |
There was a problem hiding this comment.
Pull request overview
This PR adds support for configuring a dedicated PersistentVolumeClaim for PostgreSQL + pgBackRest logs per instance set, so log storage can be sized and managed independently of the data PVC (mitigating outages due to log bursts filling the data volume).
Changes:
- Adds
logVolumeClaimSpecto instance set APIs/CRDs (Percona API v2 and upstream v1beta1) and updates generated deepcopy + CRD manifests. - Implements log-PVC reconciliation, naming/labeling, and Pod mounting at
/pglogs. - Extends the startup init script to migrate log directories via symlinks and clean up broken symlinks when the log volume is removed.
Reviewed changes
Copilot reviewed 17 out of 20 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/apis/upstream.pgv2.percona.com/v1beta1/zz_generated.deepcopy.go | Generated deepcopy updated for new LogVolumeClaimSpec. |
| pkg/apis/upstream.pgv2.percona.com/v1beta1/postgrescluster_types.go | Adds logVolumeClaimSpec to upstream PostgresInstanceSetSpec. |
| pkg/apis/pgv2.percona.com/v2/zz_generated.deepcopy.go | Generated deepcopy updated for new LogVolumeClaimSpec. |
| pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go | Plumbs CRVersion into instance-set conversion and gates logVolumeClaimSpec in ToCrunchy. |
| pkg/apis/pgv2.percona.com/v2/perconapgcluster_types_test.go | Adds/updates unit tests for ToCrunchy version gating and signature change. |
| internal/postgres/reconcile.go | Adds /pglogs mount wiring into the instance Pod spec. |
| internal/postgres/reconcile_test.go | Updates Pod spec/startup-script expectations; adds log-volume mounting test case. |
| internal/postgres/config.go | Adds startup-script logic to migrate logs to /pglogs and handle broken symlinks. |
| internal/naming/names.go | Adds deterministic naming for the log PVC (<instance>-pglogs). |
| internal/naming/labels.go | Adds RolePostgresLog (pglogs) label role. |
| internal/controller/postgrescluster/postgres.go | Implements reconcilePostgresLogVolume PVC reconciliation. |
| internal/controller/postgrescluster/postgres_test.go | Adds unit tests for log PVC creation and retention-on-removal behavior. |
| internal/controller/postgrescluster/instance.go | Threads the reconciled log PVC into postgres.InstancePod. |
| deploy/cw-bundle.yaml | Updates bundled manifests with new CRD schema field. |
| deploy/crd.yaml | Updates CRD schema with new logVolumeClaimSpec field. |
| deploy/cr.yaml | Adds example snippet for logVolumeClaimSpec. |
| deploy/bundle.yaml | Updates bundled manifests with new CRD schema field. |
| config/crd/bases/upstream.pgv2.percona.com_postgresclusters.yaml | CRD base updated to include logVolumeClaimSpec. |
| config/crd/bases/pgv2.percona.com_perconapgclusters.yaml | CRD base updated to include logVolumeClaimSpec. |
| build/crd/percona/generated/pgv2.percona.com_perconapgclusters.yaml | Generated CRD updated to include logVolumeClaimSpec. |
Files not reviewed (2)
- pkg/apis/pgv2.percona.com/v2/zz_generated.deepcopy.go: Generated file
- pkg/apis/upstream.pgv2.percona.com/v1beta1/zz_generated.deepcopy.go: Generated file
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
While looking into this I found the existing tablespaces e2e test, and it made me realize I may not have understood the e2e approach here. For now, I'll add two new e2e tests, one for the WAL volume and one for the log volume. But I think it would be worth considering a broader lifecycle/feature-interaction e2e test as well. |
We don't have a strict rule for isolating features. There are cases where we test multiple features in tandem because they make sense to be used together. In this case also I think we can add a single test for WAL and log volumes and maybe even a separate tablespace volume. |
|
Ok, will change the tests from separate wal-volume and log-volume to |
commit: 4947a02 |
Problem:
PostgreSQL and pgBackRest write their logs onto the data volume (/pgdata/logs/postgres and the pgBackRest log directory). Logs compete with database data for the same PVC, so a burst of logging can fill the data volume and take the cluster down, and log storage can't be sized, backed by a different storage class, or managed independently.
Cause:
The log directories are hardcoded under the data volume and there was no API to place them elsewhere - the operator only provisioned data, WAL and tablespace volumes per instance.
Solution:
Add an optional logVolumeClaimSpec to each instance set (spec.instances[].logVolumeClaimSpec), gated on cluster version >= 3.1.0 (I dont think it will make it to 3.1.0 but worth the try 😄 ):
Covered by unit tests for the PVC reconciler (reconcilePostgresLogVolume), the pod spec (mounts/volumes), the startup script, and the version gate on ToCrunchy.
CHECKLIST
Jira
Needs Doc) and QA (Needs QA)?Tests
Config/Logging/Testability