Skip to content

Commit d767094

Browse files
test(postgres): pin the owner secret's recovery block after a restore
Turning bootstrap.enabled off on a restored release renders a recovery block holding only the owner secret, without recovery.source or recoveryTarget. Keeping the source would fail CNPG's webhook: it rejects a source whose externalClusters entry is missing, and the chart renders that entry only while bootstrap.enabled is on. Neither field is read after bootstrap, so dropping them is the intended outcome, and the test keeps a later change from carrying them over. Assisted-by: LLM Signed-off-by: Mattia Eleuteri <[email protected]>
1 parent 9625d77 commit d767094

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

‎packages/apps/postgres/templates/db.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ spec:
272272
because CNPG rejects a second one, and a restored Cluster keeps its recovery
273273
block. Changing bootstrap on an existing Cluster is accepted, and the
274274
remaining fields come from the live object or CNPG's defaults (app/app).
275+
A release turning bootstrap.enabled off still drops recovery.source and
276+
recoveryTarget: they are read only at bootstrap, and CNPG's webhook
277+
rejects a source once its externalClusters entry, rendered only with
278+
bootstrap.enabled, is gone.
275279
*/}}
276280
{{- $live := lookup "postgresql.cnpg.io/v1" "Cluster" .Release.Namespace .Release.Name }}
277281
{{- $liveBootstrap := dig "spec" "bootstrap" dict ($live | default dict) }}

‎packages/apps/postgres/tests/app_owner_secret_test.yaml‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,52 @@ tests:
217217
value: pg-old
218218
- notExists:
219219
path: spec.bootstrap.recovery.secret
220+
221+
- it: drops recovery.source with its external cluster once bootstrap.enabled is off
222+
# A source naming an absent externalClusters entry is rejected by CNPG's
223+
# webhook, and both are read only at bootstrap.
224+
templates:
225+
- templates/db.yaml
226+
kubernetesProvider:
227+
scheme:
228+
"postgresql.cnpg.io/v1/Cluster":
229+
gvr:
230+
group: postgresql.cnpg.io
231+
version: v1
232+
resource: clusters
233+
namespaced: true
234+
objects:
235+
- apiVersion: postgresql.cnpg.io/v1
236+
kind: Cluster
237+
metadata:
238+
name: pg-test
239+
namespace: tenant-test
240+
spec:
241+
bootstrap:
242+
recovery:
243+
database: app
244+
owner: app
245+
source: pg-old
246+
recoveryTarget:
247+
backupID: 20261019T000000
248+
externalClusters:
249+
- name: pg-old
250+
set:
251+
users:
252+
app: {}
253+
bootstrap:
254+
enabled: false
255+
oldName: pg-old
256+
backupID: 20261019T000000
257+
documentSelector:
258+
path: kind
259+
value: Cluster
260+
asserts:
261+
- equal:
262+
path: spec.bootstrap
263+
value:
264+
recovery:
265+
secret:
266+
name: pg-test-app-owner
267+
- notExists:
268+
path: spec.externalClusters

0 commit comments

Comments
 (0)