fix(controller,backup): select Postgres container by name instead of assuming index by Joda89 · Pull Request #8964 · cloudnative-pg/cloudnative-pg

@dosubot dosubot bot added the size:XS

This PR changes 0-9 lines, ignoring generated files.

label

Oct 26, 2025

vishnuitta

@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 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

@dosubot dosubot bot added the lgtm

This PR has been approved by a maintainer

label

Oct 28, 2025

jbattiato

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>

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)