Skip to content

fix(controller,backup): select Postgres container by name instead of assuming index#8964

Merged
mnencia merged 2 commits intocloudnative-pg:mainfrom
Joda89:patch-1
Oct 28, 2025
Merged

fix(controller,backup): select Postgres container by name instead of assuming index#8964
mnencia merged 2 commits intocloudnative-pg:mainfrom
Joda89:patch-1

Conversation

@Joda89
Copy link
Contributor

@Joda89 Joda89 commented Oct 26, 2025

Ensure backups identify the Postgres container by its name rather than assuming the Postgres container is the first container in the Pod spec/status. Pods may include sidecars or other containers which can shift ordering; relying on index 0 is brittle and caused incorrect containerID/image checks.

Closes #8966

@Joda89 Joda89 requested a review from a team as a code owner October 26, 2025 21:52
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Oct 26, 2025
@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.25 release-1.26 release-1.27 labels Oct 26, 2025
@github-actions
Copy link
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 bug 🐛 Something isn't working ok to merge 👌 This PR can be merged labels Oct 26, 2025
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Oct 27, 2025
@armru
Copy link
Member

armru commented Oct 27, 2025

/test limit=local

@github-actions
Copy link
Contributor

@armru, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/18837898508

@armru armru changed the title fix(backup): fix backup function when we have sidecar fix(backup): do not assume that postgres is the first container Oct 27, 2025
@armru armru changed the title fix(backup): do not assume that postgres is the first container fix(controller,backup): select Postgres container by name instead of assuming index Oct 27, 2025
@armru
Copy link
Member

armru commented Oct 27, 2025

Proposed commit message:

Ensure backups identify the Postgres container by its name rather than assuming the Postgres container is the first container in the Pod spec/status. Pods may include sidecars or other containers which can shift ordering; relying on index 0 is brittle and caused incorrect containerID/image checks.

@Joda89
Copy link
Contributor Author

Joda89 commented Oct 27, 2025

Thanks, @armru, for the help.

@armru
Copy link
Member

armru commented Oct 28, 2025

/test limit=local

@github-actions
Copy link
Contributor

@armru, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/18868291076

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 28, 2025
Joda89 and others added 2 commits October 28, 2025 14:37
The purpose of this PR is to fix backups when there is more than one container in the Pod, which is the case when using Istio, for example.

Error message:
{‘level’:‘debug’,“ts”:" 2025-10-26T07:49:29.003680028Z‘,’msg‘:’Instance not having expected image, discarded as target for backup‘,’controller‘:’backup‘,’controllerGroup‘:’postgresql.cnpg.io‘,’controllerKind‘:“Backup”,’ Backup‘:{’name‘:’postgresql-20251026084856‘,’namespace‘:’databases‘},’namespace‘:’databases‘,“name”:’postgresql-20251026084856‘,’ reconcileID‘:’f4dd8a41-2755-4086-89f8-e1daa10bb2bc‘,“caller”:’internal/controller/backup_controller.go:692"}

Signed-off-by: Joda89 <johan.lore@free.fr>
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
@mnencia mnencia merged commit 603b10d into cloudnative-pg:main Oct 28, 2025
30 checks passed
cnpg-bot pushed a commit that referenced this pull request Oct 28, 2025
…assuming index (#8964)

Ensure backups identify the Postgres container by its name rather than
assuming the Postgres container is the first container in the Pod
spec/status. Pods may include sidecars or other containers, which can
shift ordering; relying on index zero is brittle and causes incorrect
containerID/image checks.

Closes #8966

Signed-off-by: Joda89 <johan.lore@free.fr>
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Co-authored-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
(cherry picked from commit 603b10d)
cnpg-bot pushed a commit that referenced this pull request Oct 28, 2025
…assuming index (#8964)

Ensure backups identify the Postgres container by its name rather than
assuming the Postgres container is the first container in the Pod
spec/status. Pods may include sidecars or other containers, which can
shift ordering; relying on index zero is brittle and causes incorrect
containerID/image checks.

Closes #8966

Signed-off-by: Joda89 <johan.lore@free.fr>
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Co-authored-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
(cherry picked from commit 603b10d)
mnencia pushed a commit that referenced this pull request Oct 29, 2025
…assuming index (#8964)

Ensure backups identify the Postgres container by its name rather than
assuming the Postgres container is the first container in the Pod
spec/status. Pods may include sidecars or other containers, which can
shift ordering; relying on index zero is brittle and causes incorrect
containerID/image checks.

Closes #8966

Signed-off-by: Joda89 <johan.lore@free.fr>
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Co-authored-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
(cherry picked from commit 603b10d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-requested ◀️ This pull request should be backported to all supported releases bug 🐛 Something isn't working lgtm This PR has been approved by a maintainer ok to merge 👌 This PR can be merged release-1.25 release-1.26 release-1.27 size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants