Skip to content

feat(bootstrap): use an init container instead of a separate Job for new instances - #11319

Merged
mnencia merged 8 commits into
cloudnative-pg:mainfrom
leonardoce:remove-jobs-initcontainer
Aug 27, 2026
Merged

mnencia merged 8 commits into
cloudnative-pg:mainfrom
leonardoce:remove-jobs-initcontainer

Conversation

@leonardoce

@leonardoce leonardoce commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

New primary and replica instances are now bootstrapped (initdb, recovery, pg_basebackup, join, and snapshot restore) directly on the instance Pod via an init container, instead of running a separate Kubernetes Job beforehand. This removes the extra Job resource previously created for every new instance, along with its own Pod, and the wait for that Job to complete before the actual instance Pod could start.

A stuck bootstrap surfaces as PhaseUnrecoverable on the Cluster status, and a replica resuming a stalled bootstrap reports PhaseCreatingReplica with an Event.

Closes: #11228


Original PR description

New primary and replica instances are now bootstrapped (initdb, recovery,
pg_basebackup, join, and snapshot restore) directly on the instance Pod via
an init container, instead of running a separate Kubernetes Job beforehand.
This removes the extra Job resource previously created for every new
instance, along with its own Pod, and the wait for that Job to complete
before the actual instance Pod could start.

Important

This is an alternative approach for #11231 that is less invasive on the codebase.
It requires #11315 to be merged too.

@leonardoce
leonardoce marked this pull request as ready for review August 13, 2026 08:04
@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.28 release-1.29 release-1.30 labels Aug 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

❗ By default, the pull request is configured to backport to all release branches.

  • To stop backporting this pr, remove the label: backport-requested ◀️ or add the label 'do not backport'
  • To stop backporting this pr to a certain release branch, remove the specific branch label: release-x.y

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement 🪄 New feature or request labels Aug 13, 2026
@leonardoce leonardoce added do not backport This PR must not be backported - it will be in the next minor release and removed backport-requested ◀️ This pull request should be backported to all supported releases release-1.28 release-1.29 release-1.30 labels Aug 13, 2026
@leonardoce

Copy link
Copy Markdown
Contributor Author

/test bp=pr-1025 l=kind

@github-actions

Copy link
Copy Markdown
Contributor

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Aug 13, 2026
@leonardoce
leonardoce force-pushed the remove-jobs-initcontainer branch from cb78fa2 to 4987ac8 Compare August 17, 2026 08:51
@leonardoce

Copy link
Copy Markdown
Contributor Author

/test bp=pr-1025 l=kind

@github-actions

Copy link
Copy Markdown
Contributor

@cnpg-bot cnpg-bot added the ok to merge 👌 This PR can be merged label Aug 17, 2026
@NiccoloFei
NiccoloFei force-pushed the remove-jobs-initcontainer branch from 4987ac8 to 0e06aee Compare August 21, 2026 12:47
@mnencia
mnencia force-pushed the remove-jobs-initcontainer branch 2 times, most recently from 632e3d9 to 51541be Compare August 25, 2026 17:35
@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Aug 25, 2026
@mnencia
mnencia force-pushed the remove-jobs-initcontainer branch from bd21929 to a14c547 Compare August 27, 2026 14:12
@mnencia
mnencia merged commit 8179beb into cloudnative-pg:main Aug 27, 2026
29 checks passed
gabriele-wolfox added a commit to cloudnative-pg/klio that referenced this pull request Aug 31, 2026
A recent CloudNativePG change (cloudnative-pg/cloudnative-pg#11319) moved
instance bootstrap, including full and snapshot recovery, from a dedicated
Job into an init container inside the instance pod. The lifecycle hook only
injected the restore sidecar for recovery Jobs, so after that change the
recovery pod ran the instance sidecar, which does not advertise the restore
job hooks capability, and every plugin-based recovery failed with "no plugin
supports the restore job hooks capability".

Inject the restore sidecar from the Pod lifecycle hook while the cluster is
performing its initial recovery bootstrap. The Job path is kept so recovery
still works on CloudNativePG releases that bootstrap through a Job.

Assisted-by: Claude

Signed-off-by: Gabriele Quaresima <[email protected]>
gabriele-wolfox added a commit to cloudnative-pg/klio that referenced this pull request Aug 31, 2026
A recent CloudNativePG change (cloudnative-pg/cloudnative-pg#11319) moved
instance bootstrap, including full and snapshot recovery, from a dedicated
Job into an init container inside the instance pod. The lifecycle hook only
injected the restore sidecar for recovery Jobs, so after that change the
recovery pod ran the instance sidecar, which does not advertise the restore
job hooks capability, and every plugin-based recovery failed with "no plugin
supports the restore job hooks capability".

Inject the restore sidecar from the Pod lifecycle hook while the cluster is
performing its initial recovery bootstrap. The Job path is kept so recovery
still works on CloudNativePG releases that bootstrap through a Job.

Assisted-by: Claude

Signed-off-by: Gabriele Quaresima <[email protected]>
gabriele-wolfox added a commit to cloudnative-pg/klio that referenced this pull request Aug 31, 2026
A recent CloudNativePG change (cloudnative-pg/cloudnative-pg#11319) moved
instance bootstrap, including full and snapshot recovery, from a dedicated
Job into an init container inside the instance pod. The lifecycle hook only
injected the restore sidecar for recovery Jobs, so after that change the
recovery pod ran the instance sidecar, which does not advertise the restore
job hooks capability, and every plugin-based recovery failed with "no plugin
supports the restore job hooks capability".

Inject the restore sidecar from the Pod lifecycle hook while the cluster is
performing its initial recovery bootstrap. The Job path is kept so recovery
still works on CloudNativePG releases that bootstrap through a Job.

Assisted-by: Claude

Signed-off-by: Gabriele Quaresima <[email protected]>
gabriele-wolfox added a commit to cloudnative-pg/klio that referenced this pull request Aug 31, 2026
A recent CloudNativePG change (cloudnative-pg/cloudnative-pg#11319) moved
instance bootstrap, including full and snapshot recovery, from a dedicated
Job into an init container inside the instance pod. The lifecycle hook only
injected the restore sidecar for recovery Jobs, so after that change the
recovery pod ran the instance sidecar, which does not advertise the restore
job hooks capability, and every plugin-based recovery failed with "no plugin
supports the restore job hooks capability".

Inject the restore sidecar from the Pod lifecycle hook while the cluster is
performing its initial recovery bootstrap. The Job path is kept so recovery
still works on CloudNativePG releases that bootstrap through a Job.

Assisted-by: Claude

Signed-off-by: Gabriele Quaresima <[email protected]>
leonardoce pushed a commit to cloudnative-pg/klio that referenced this pull request Sep 1, 2026
A recent CloudNativePG change (cloudnative-pg/cloudnative-pg#11319)
moved instance bootstrap, including recovery, from a dedicated Job into
an init container inside the instance pod. Klio only injected the
restore sidecar for recovery Jobs, so the recovery pod ran the instance
sidecar, which does not advertise the restore job hooks capability, and
plugin-based recovery failed with `no plugin supports the restore job
hooks capability`.

Inject the restore sidecar from the Pod lifecycle hook during the
initial recovery bootstrap.
The Job path is retained for CloudNativePG releases that still bootstrap
recovery through a Job.

Closes #192

Signed-off-by: Gabriele Quaresima <[email protected]>
fcanovai pushed a commit to cloudnative-pg/klio that referenced this pull request Sep 2, 2026
A recent CloudNativePG change (cloudnative-pg/cloudnative-pg#11319)
moved instance bootstrap, including recovery, from a dedicated Job into
an init container inside the instance pod. Klio only injected the
restore sidecar for recovery Jobs, so the recovery pod ran the instance
sidecar, which does not advertise the restore job hooks capability, and
plugin-based recovery failed with `no plugin supports the restore job
hooks capability`.

Inject the restore sidecar from the Pod lifecycle hook during the
initial recovery bootstrap.
The Job path is retained for CloudNativePG releases that still bootstrap
recovery through a Job.

Closes #192

Signed-off-by: Gabriele Quaresima <[email protected]>
litaocdl pushed a commit that referenced this pull request Sep 9, 2026
Since #11319, bootstrap runs in an init container. It can start
before the operator writes Status.Certificates. When that happens,
RefreshSecrets reads an empty secret name and fails right away with
"resource name may not be empty". The container crashes, and only a
restart can fix it, and even that does not always help.

Now join and upgrade wait for Status.Certificates first, with no
time limit. This also replaces their old WaitForGetCluster call,
since the new wait already retries a failed Get too.

The main container's own reconcile loop already retries forever on
this same error before it starts PostgreSQL, so it needs no change.

Closes #11446

Signed-off-by: Marco Nenciarini <[email protected]>
litaocdl pushed a commit that referenced this pull request Sep 9, 2026
…#11450)

Since #11319, bootstrap runs in an init container. It can start
before the operator writes Status.Certificates. When that happens,
RefreshSecrets reads an empty secret name and fails right away with
"resource name may not be empty". The container crashes, and only a
restart can fix it, and even that does not always help.

Now join and upgrade wait for cluster with Status.Certificates set first, 
with no time limit. This also replaces their old WaitForGetCluster call,
since the new wait already retries a failed Get too.

The main container's own reconcile loop already retries forever on
this same error before it starts PostgreSQL, so it needs no change.

Closes #11446

Signed-off-by: Marco Nenciarini <[email protected]>
Signed-off-by: Armando Ruocco <[email protected]>
Co-authored-by: Armando Ruocco <[email protected]>
cnpg-bot pushed a commit that referenced this pull request Sep 9, 2026
…#11450)

Since #11319, bootstrap runs in an init container. It can start
before the operator writes Status.Certificates. When that happens,
RefreshSecrets reads an empty secret name and fails right away with
"resource name may not be empty". The container crashes, and only a
restart can fix it, and even that does not always help.

Now join and upgrade wait for cluster with Status.Certificates set first,
with no time limit. This also replaces their old WaitForGetCluster call,
since the new wait already retries a failed Get too.

The main container's own reconcile loop already retries forever on
this same error before it starts PostgreSQL, so it needs no change.

Closes #11446

Signed-off-by: Marco Nenciarini <[email protected]>
Signed-off-by: Armando Ruocco <[email protected]>
Co-authored-by: Armando Ruocco <[email protected]>
(cherry picked from commit 7dd2f3b)
cnpg-bot pushed a commit that referenced this pull request Sep 9, 2026
…#11450)

Since #11319, bootstrap runs in an init container. It can start
before the operator writes Status.Certificates. When that happens,
RefreshSecrets reads an empty secret name and fails right away with
"resource name may not be empty". The container crashes, and only a
restart can fix it, and even that does not always help.

Now join and upgrade wait for cluster with Status.Certificates set first,
with no time limit. This also replaces their old WaitForGetCluster call,
since the new wait already retries a failed Get too.

The main container's own reconcile loop already retries forever on
this same error before it starts PostgreSQL, so it needs no change.

Closes #11446

Signed-off-by: Marco Nenciarini <[email protected]>
Signed-off-by: Armando Ruocco <[email protected]>
Co-authored-by: Armando Ruocco <[email protected]>
(cherry picked from commit 7dd2f3b)
mnencia added a commit that referenced this pull request Sep 9, 2026
…#11450)

Since #11319, bootstrap runs in an init container. It can start
before the operator writes Status.Certificates. When that happens,
RefreshSecrets reads an empty secret name and fails right away with
"resource name may not be empty". The container crashes, and only a
restart can fix it, and even that does not always help.

Now join and upgrade wait for cluster with Status.Certificates set first,
with no time limit. This also replaces their old WaitForGetCluster call,
since the new wait already retries a failed Get too.

The main container's own reconcile loop already retries forever on
this same error before it starts PostgreSQL, so it needs no change.

Closes #11446

Signed-off-by: Marco Nenciarini <[email protected]>
Signed-off-by: Armando Ruocco <[email protected]>
Co-authored-by: Armando Ruocco <[email protected]>
(cherry picked from commit 7dd2f3b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not backport This PR must not be backported - it will be in the next minor release enhancement 🪄 New feature or request lgtm This PR has been approved by a maintainer ok to merge 👌 This PR can be merged size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Bootstrap PostgreSQL instances without a separate Job or init container

4 participants