Skip to content

Commit 3c7efb9

Browse files
scooby87claude
andcommitted
fix(postgres): garbage-collect init-job after completion (cozystack#3055)
The post-install/post-upgrade init Job is a one-shot reconciler of users/databases/roles. Its hook-delete-policy was `before-hook-creation` only, which never fires on uninstall, so the completed Job and its Pod lingered in the tenant namespace forever after the Postgres CR was deleted (cozystack#3055). Add `ttlSecondsAfterFinished: 120` so the Kubernetes TTL controller GCs the Job and its Pod ~2 minutes after completion, regardless of the Helm hook lifecycle. This deliberately avoids touching the hook-timeout semantics that the bootstrap.recovery path depends on. Add a helm-unittest suite locking in the TTL and the bootstrap-skip behaviour to prevent regression. Fixes cozystack#3055 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: Алексей Артамонов <[email protected]>
1 parent 374cac1 commit 3c7efb9

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

‎packages/apps/postgres/templates/init-job.yaml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ metadata:
2020
"helm.sh/hook-weight": "-5"
2121
"helm.sh/hook-delete-policy": before-hook-creation
2222
spec:
23+
# One-shot reconciler Job: once it has applied users/databases/roles it is no
24+
# longer needed. Let the Kubernetes TTL controller garbage-collect the Job and
25+
# its Pod ~2 minutes after completion so it does not linger after the release
26+
# is deleted (cozystack/cozystack#3055). This does not touch the Helm hook
27+
# lifecycle the bootstrap.recovery path relies on.
28+
ttlSecondsAfterFinished: 120
2329
template:
2430
metadata:
2531
name: {{ .Release.Name }}-init-job
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
suite: init-job is garbage-collected after completion
2+
3+
# Locks in cozystack/cozystack#3055: the post-install/post-upgrade init Job
4+
# is a one-shot reconciler of users/databases/roles. Without a TTL it lingers
5+
# in the namespace forever after the Postgres CR is deleted (its hook-delete-policy
6+
# is `before-hook-creation` only, which never fires on uninstall). A native
7+
# ttlSecondsAfterFinished lets the Kubernetes TTL controller GC the Job and its
8+
# Pod ~2 minutes after it completes, regardless of Helm hook lifecycle — without
9+
# touching the hook-timeout semantics the recovery flow depends on.
10+
11+
templates:
12+
- templates/init-job.yaml
13+
14+
release:
15+
name: pg-test
16+
namespace: tenant-test
17+
18+
tests:
19+
- it: "init-job sets ttlSecondsAfterFinished so Kubernetes GCs it after the run"
20+
set:
21+
_cluster:
22+
scheduling: {}
23+
users:
24+
app:
25+
password: secret
26+
asserts:
27+
- hasDocuments:
28+
count: 1
29+
- isKind:
30+
of: Job
31+
- equal:
32+
path: spec.ttlSecondsAfterFinished
33+
value: 120
34+
35+
- it: "init-job is skipped entirely under bootstrap recovery"
36+
set:
37+
_cluster:
38+
scheduling: {}
39+
bootstrap:
40+
enabled: true
41+
asserts:
42+
- hasDocuments:
43+
count: 0

0 commit comments

Comments
 (0)