K8SPG-911: Fix pg_tde status reporting on standbys - #1750
Conversation
| "the condition should name the Secret that could not be read") | ||
| assert.Equal(t, patched, 1, | ||
| "the failure condition is useless unless it is written to the API") | ||
| assertEvent(t, r.Recorder, "PGTDEVaultProviderChangeFailed") |
There was a problem hiding this comment.
Is the deletion intended? I didn't find the logic that affects the event and the test still passes with this line added back
There was a problem hiding this comment.
i deleted it by mistake, will restore
gkech
left a comment
There was a problem hiding this comment.
Mostly tests related comments, logic seems ok. let me know if we should defer them for the future.
| // K8SPG-911 | ||
| func TestReconcilePGTDEStandby(t *testing.T) { | ||
| t.Parallel() | ||
| ctx := context.Background() |
There was a problem hiding this comment.
In some tests of the same PR we use t.context, here we use background. We should be consistent and use t.context everywhere.
| Recorder: events.NewRecorder(t, runtime.Scheme), | ||
| PodExec: execResponder(&calls, answer(true, nil)), |
There was a problem hiding this comment.
these are not needed for this test case
| Recorder: events.NewRecorder(t, runtime.Scheme), | ||
| PodExec: execResponder(&calls, answer(false, nil)), |
There was a problem hiding this comment.
again here we dont need these
| } | ||
|
|
||
| r.reconcilePGTDEStandby(ctx, cluster, standbyObserved()) | ||
| assert.Equal(t, len(calls), 0, |
There was a problem hiding this comment.
why on some of these check we have messages while on others we do not? In general, I think that they are not very useful
There was a problem hiding this comment.
¯_(ツ)_/¯
if it's okay, i won't do this change
| assert.Equal(t, call.pod, "pgc1-instance1-abcd-0") | ||
| assert.Equal(t, call.container, naming.ContainerDatabase) | ||
| assert.Equal(t, call.command[0], "psql") | ||
| assert.Assert(t, argsContain(call.command, "--tuples-only")) |
There was a problem hiding this comment.
since we decided to assert that, why we only check tuples only and not no align?
There was a problem hiding this comment.
it's claude adding a test for every change, why I use these flags described in comment:
percona-postgresql-operator/internal/pgtde/postgres.go
Lines 117 to 119 in ee3efcc
| assert.NilError(t, r.reconcilePGTDEProviders(ctx, cluster, observed, failPatch(t))) | ||
| assert.Equal(t, cluster.Status.PGTDERevision, "") | ||
| assert.Assert(t, meta.FindStatusCondition(cluster.Status.Conditions, |
There was a problem hiding this comment.
still trying to understand why on a file we introduced ourselves we are using gotest.tools/v3/assert instead of github.com/stretchr/testify/assert, which is much more expressive
There was a problem hiding this comment.
all tests in internal directory is using gotest.tools/v3/assert, that's why claude continued to use it
There was a problem hiding this comment.
Pull request overview
This PR addresses pg_tde status reporting for standby (recovery) clusters, where the operator cannot run SQL that writes system catalogs. It introduces a dedicated standby reconcile path that observes (via read-only queries on the standby leader) whether pg_tde is present and whether its principal key is reachable, then reports appropriate status conditions so downstream logic (notably WAL encryption gating) can behave correctly.
Changes:
- Added
PostgresCluster.IsStandby()helper and unit tests for standby detection. - Implemented read-only pg_tde observation (
ObserveExtension,VerifyPrincipalKey) and standby-specific condition reporting (ReportStandby). - Added a standby reconcile path that execs into the Patroni standby leader to observe pg_tde state, while ensuring the writable-only pg_tde provider reconciliation is skipped on standbys.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/apis/upstream.pgv2.percona.com/v1beta1/postgrescluster_types.go | Adds IsStandby() helper on the API type. |
| pkg/apis/upstream.pgv2.percona.com/v1beta1/postgrescluster_test.go | Adds unit coverage for IsStandby(). |
| internal/pgtde/postgres.go | Adds read-only psql helpers plus standby-oriented status reporting logic; adjusts WAL-encryption gating behavior for standby clusters. |
| internal/pgtde/postgres_test.go | Adds tests for standby WAL parameter behavior and new pg_tde observation/reporting helpers. |
| internal/controller/postgrescluster/postgres.go | Adds reconcilePGTDEStandby and prevents writable-only provider reconciliation from running on standbys. |
| internal/controller/postgrescluster/pgtde_test.go | Adds tests validating standby behavior (no writable SQL, correct status reporting) and helper utilities for exec simulation. |
| internal/controller/postgrescluster/instance.go | Adds standbyLeaderPod() selection logic for Patroni standby leader pods. |
| internal/controller/postgrescluster/instance_test.go | Adds unit tests for standbyLeaderPod(). |
| internal/controller/postgrescluster/controller.go | Invokes reconcilePGTDEStandby in the main reconcile flow. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
487ac81
CHANGE DESCRIPTION
Problem:
Operator doesn't (and can't) run any SQL statements on standby clusters to enable and configure pg_tde. This results in status conditions related to pg_tde not appear. Consequences of this is bigger than just status reporting: enabling WAL encryption depends on these conditions being true.
Solution:
Reconcile pg_tde on standby clusters separately and observe if pg_tde is enabled and configured in database by read queries.
CHECKLIST
Jira
Needs Doc) and QA (Needs QA)?Tests
Config/Logging/Testability