Skip to content

Commit 53ac201

Browse files
mjudeikisclaude
andauthored
fix(infrastructure): delete application db PVC on instance teardown (#356)
The application template's Postgres StatefulSet left its data PVC behind when an Application was deleted, so recreating with the same name failed with "password authentication failed for user appuser": the pwgen Job minted a fresh password into the new credentials Secret while Postgres recovered the orphaned volume (old password). The PVC is created by the StatefulSet controller from volumeClaimTemplates, not by kro, so it has no kro labels and isn't in kro's applyset — kro never GCs it. And the StatefulSet's default persistentVolumeClaimRetentionPolicy (whenDeleted: Retain) keeps it across a StatefulSet delete. So nothing cleaned it up. Set whenDeleted: Delete so the PVC's lifecycle follows the StatefulSet kro deletes on teardown; a same-name recreate then starts from a fresh database. whenScaled stays Retain (no horizontal scaling here anyway). Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent f1f6b05 commit 53ac201

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

providers/infrastructure/install/templates/application.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,18 @@ spec:
311311
spec:
312312
serviceName: ${schema.spec.name}-db
313313
replicas: 1
314+
# Tie the data PVC's lifecycle to the StatefulSet. The PVC is
315+
# created by the StatefulSet controller from volumeClaimTemplates
316+
# (NOT by kro), so it carries no kro labels and isn't in kro's
317+
# applyset — kro never garbage-collects it. With the k8s default
318+
# (whenDeleted: Retain) the PVC also outlives a StatefulSet delete,
319+
# so deleting an Application orphaned the volume: a same-name
320+
# recreate minted a fresh db password but Postgres recovered the old
321+
# data (old password) → "password authentication failed". Delete the
322+
# PVC when kro deletes the StatefulSet so a recreate starts clean.
323+
persistentVolumeClaimRetentionPolicy:
324+
whenDeleted: Delete
325+
whenScaled: Retain
314326
selector:
315327
matchLabels:
316328
app: ${schema.spec.name}-db

0 commit comments

Comments
 (0)