Repository navigation
Description
Is there an existing issue already for this feature request/idea?
- I have searched for an existing issue, and could not find anything. I believe this is a new feature request to be evaluated.
What problem is this feature going to solve? Why should it be added?
Today, creating a new PostgreSQL instance (a primary via initdb/recovery/pgbasebackup, or a replica via join/snapshot-restore) goes through a batchv1.Job that runs instance <init|join|restore|restoresnapshot|pgbasebackup> against the PVC, and only once that Job completes does the operator create the actual instance Pod that runs postgres.
This extra Job stage carries real cost. While any bootstrap Job for a cluster is running, the operator's reconcileResources loop treats it as blocking and requeues the Pod/PVC part of reconciliation until it's done; that blocking guard, plus the separate Job-creation step, keeps inviting a class of PVC/Job split-brain deadlocks, e.g. #10985 (a join Job's Pod could never schedule, so the guard never cleared) and #11036 (a status update conflicting before the initdb Job existed wedged first-primary bootstrap). Both are fixed now, but each needed its own targeted self-heal; a single-container design removes the guard and the Job-creation window those fixes work around. Completed Jobs aren't given a TTL and have to be swept up by a separate cleanup pass. PVC readiness has to be tracked out-of-band by matching PVCs to Job completion, which is its own piece of bookkeeping.
I looked at an alternative where the bootstrap step is moved into an init container on the instance Pod itself, so there's no separate Job object. That removes the Job, but the extra machinery mostly moves rather than disappears: PVC-readiness now has to be derived from the init container's termination status on the Pod instead of Job completion, the operator still has to patch that PVC annotation from outside the Pod (the instance's own ServiceAccount has no RBAC on PVCs or Pods), and the Pod spec annotation used to detect "does this Pod need updating" has to be computed with the bootstrap init container stripped out again, otherwise a completed bootstrap looks like a spec drift and triggers a rolling update.
Describe the solution you'd like
Bootstrap the instance directly from the main container, with no separate Job and no separate init container. The instance manager already has init/join/restore logic factored as reusable library code (InitInfo.Bootstrap, InitInfo.Join, and the restore equivalents) rather than shell-outs to a subcommand, so instance run could detect an uninitialized PGDATA on startup and run the appropriate bootstrap step in-process before starting postgres, instead of requiring a prior process/container to have done it.
This would remove the Job entirely, remove the PVC-readiness tracking that only exists to compensate for the two-stage creation, and collapse instance creation down to "create one Pod, the Pod initializes itself." I'd like to use this issue to discuss the design before writing any code: what bootstrap-mode information the Pod needs at creation time instead of being told a Job's command afterwards, how failures should surface (an instance stuck failing to bootstrap forever vs. today's Job backoff-driven PhaseUnrecoverable), and whether there's anything the two-stage approach is quietly relying on that a single-container design would need to replace.
Describe alternatives you've considered
Moving bootstrap into an init container on the instance Pod instead of a Job, described above: it drops the Job object but relocates rather than removes the complexity, so it isn't a clear enough win to be worth the churn on its own.
Additional context
No response
Backport?
No
Are you willing to actively contribute to this feature?
Yes
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
test(e2e): retarget bootstrap assertions to Pods
test(e2e): cover walStorage in the bootstrap-Job assertions
feat(bootstrap): use an init container instead of a separate Job for …