Skip to content

fix(bootstrap): leave volumes that already hold the instance untouched - #11608

Merged
mnencia merged 5 commits into
mainfrom
dev/11505
Nov 1, 2026
Merged

mnencia merged 5 commits into
mainfrom
dev/11505

Conversation

@armru

@armru armru commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

The bootstrap-instance init container runs on a Pod whose PGDATA PVC is not ready, and Kubernetes runs it again whenever the Pod is recreated as it was, for example when a backup tool restores the Pod with its PVCs or the kubelet recreates the Pod sandbox. On a volume that already holds the instance, initdb moves the data directory aside and starts an empty instance.

The operator now creates the Pod with the cnpg.io/bootstrapPending annotation, which the container reads through the downward API, and removes it once the container succeeds. Every bootstrap command logs a warning and exits without touching the volumes when the annotation is not set. This needs no new permission and no API call, and the variable is not part of the Pod spec compared for rollouts.

The PVC classifier also took a missing init container status for a Pod without the container, so it marked a PVC ready before the kubelet reported on its Pod, and a Pod replaced then lost its bootstrap container. It now looks at the Pod spec.

Closes #11505

@armru
armru requested review from a team, NiccoloFei and litaocdl as code owners October 5, 2026 09:59
@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.28 release-1.30 labels Oct 5, 2026
@github-actions

github-actions Bot commented Oct 5, 2026

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

@armru armru changed the title wip fix(bootstrap): leave volumes that already hold the instance untouched Oct 5, 2026
@armru armru changed the title fix(bootstrap): leave volumes that already hold the instance untouched fixwipbootstrap): leave volumes that already hold the instance untouched Oct 5, 2026
@armru armru changed the title fixwipbootstrap): leave volumes that already hold the instance untouched wip(bootstrap): leave volumes that already hold the instance untouched Oct 5, 2026
@armru armru changed the title wip(bootstrap): leave volumes that already hold the instance untouched fix(bootstrap): leave volumes that already hold the instance untouched Oct 5, 2026
@armru

armru commented Oct 5, 2026

Copy link
Copy Markdown
Member Author

/test

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

@cnpg-bot cnpg-bot added the ok to merge 👌 This PR can be merged label Oct 5, 2026
@leonardoce

Copy link
Copy Markdown
Contributor

/test

@github-actions

Copy link
Copy Markdown
Contributor

armru and others added 3 commits October 30, 2026 17:08
…trap

A Pod created with the bootstrap-instance init container has no init
container status until the kubelet first reports on it. The PVC
classifier looked only at the status, so in that window it took the
missing entry for a Pod without the container, classified the PVC as
healthy and marked it ready before the bootstrap had run.

The Pod spec now decides whether the container is there, and the PVC
stays initializing until its status shows it terminated successfully.

Signed-off-by: Armando Ruocco <[email protected]>
The operator attaches the bootstrap-instance init container only to a
Pod whose PGDATA PVC is not ready, and marks it ready once the container
succeeds. Kubernetes only knows that the container belongs to the Pod:
when a backup tool restores the Pod together with its PVCs, it runs the
container again on volumes that already hold the instance. An initdb
rerun moved the restored data directory aside, or deleted it, and
started an empty instance in its place; a join rerun did the same before
cloning from a primary that may not be there.

The operator now creates the Pod with the cnpg.io/bootstrapPending
annotation together with the container, and removes it once the
container has succeeded there. The container sees the annotation through
the downward API every time it starts, and every bootstrap command
(init, join, pgbasebackup, restore and restoresnapshot) exits without
touching the volumes when it is not set. A Pod restored after its
bootstrap succeeded comes back without it, even when the tool drops the
Pod annotations. The instance needs no new access, and the variable
lives only in the bootstrap container, which the Pod spec compared for
rollouts does not include.

Closes #11505

Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Leonardo Cecchi <[email protected]>
@mnencia mnencia 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.30 labels Oct 30, 2026
Log the skipped bootstrap as a warning. Keep the full reason in
IsBootstrapCompleted and fix the foreign init container comment. In the
restored pods e2e, wait with the rollout timeout and look for moved
aside directories with find.

Signed-off-by: Marco Nenciarini <[email protected]>
@mnencia

mnencia commented Oct 30, 2026

Copy link
Copy Markdown
Member

/test

@github-actions

Copy link
Copy Markdown
Contributor

The spec deleted the Lease by hand and failed with a 404 when GC had
already removed it. The operator deletes an ownerless Lease when it
restores a Cluster from orphan PVCs, so the manual step is not needed.

Signed-off-by: Marco Nenciarini <[email protected]>
@mnencia

mnencia commented Nov 1, 2026

Copy link
Copy Markdown
Member

/test

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

@mnencia
mnencia merged commit ed8eed8 into main Nov 1, 2026
@mnencia
mnencia deleted the dev/11505 branch November 1, 2026 16:57
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 ok to merge 👌 This PR can be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Restoring a Pod along with its PVC can let a stale one-shot init container overwrite the data directory

4 participants