Skip to content

fix: remove Backup owner field indexer from ScheduledBackup controller#9466

Closed
andrew-farries wants to merge 1 commit intocloudnative-pg:mainfrom
andrew-farries:dev/remove-backup-parent-indexer
Closed

fix: remove Backup owner field indexer from ScheduledBackup controller#9466
andrew-farries wants to merge 1 commit intocloudnative-pg:mainfrom
andrew-farries:dev/remove-backup-parent-indexer

Conversation

@andrew-farries
Copy link

Remove the indexer on Backup resources that allowed finding all Backups owned by a ScheduledBackup.

The indexer never worked because it was checking Backups for owner references of kind Backup instead of ScheduledBackup:

if owner.Kind != apiv1.BackupKind {
return nil
}

This check meant that the indexer never returned any results and so the GetChildBackups method always returned an empty slice.

Even if it had correctly looked for owners of kind ScheduledBackup, it would only have worked for the cases where the ScheduledBackup was configured with:

backupOwnerReference: self

When backupOwnerReference was set to none (the default) or cluster this indexer would also not have returned anything.

The intended purpose of the GetChildBackups method that used the indexer was to prevent concurrent Backups for a ScheduledBackup. The check never worked and the Backup controller handles concurrency itself by checking for running Backups before starting a new one. So rather than fixing this indexer it is better to simply remove it.

@andrew-farries andrew-farries requested a review from a team as a code owner December 16, 2025 16:18
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug 🐛 Something isn't working ok to merge 👌 This PR can be merged labels Dec 16, 2025
@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.25 release-1.27 release-1.28 labels Dec 16, 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

@sxd
Copy link
Member

sxd commented Dec 17, 2025

/test feature_type=backup-restore,

@github-actions
Copy link
Contributor

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

@sxd
Copy link
Member

sxd commented Dec 17, 2025

/test

@github-actions
Copy link
Contributor

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

Remove the indexer on Backup resources that allowed finding all Backups
owned by a ScheduledBackup.

The indexer never worked because it was checking for owners of kind
`Backup` instead of `ScheduledBackup`.

Even if it had correctly looked for owners of kind `ScheduledBackup`, it
would only have worked for the cases where the `ScheduledBackup` was
configured with:

```
backupOwnerReference: self
```

When `backupOwnerReference` is set to `none` (the default) or `cluster`
this indexer would not have indexed anything.

The Backup controller handles concurrency by itself by checking for
running Backups before starting a new one, so rather than fixing this indexer
we simply remove it.

Signed-off-by: Andrew Farries <andrew.farries@xata.io>
armru added a commit that referenced this pull request Dec 18, 2025
…ed indexer

The ScheduledBackup controller was using a broken field indexer on owner references
to find child Backups for concurrency checking. The indexer checked for the wrong
owner kind, making it non-functional.

This fix replaces the owner reference-based indexer with a more robust approach:
a field indexer on the ParentScheduledBackupLabel that is already set on all backups
created by ScheduledBackup. This label is always present regardless of the
backupOwnerReference configuration.

Closes #9466

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
@andrew-farries andrew-farries force-pushed the dev/remove-backup-parent-indexer branch from 9442b07 to fceb696 Compare December 18, 2025 13:20
@armru
Copy link
Member

armru commented Dec 22, 2025

Given that this patch fixes the issue but also alter the behaviour (feat) I would propose to use the more conservative: #9489 approach

mnencia pushed a commit that referenced this pull request Dec 22, 2025
…ed indexer

The ScheduledBackup controller was using a broken field indexer on owner references
to find child Backups for concurrency checking. The indexer checked for the wrong
owner kind, making it non-functional.

This fix replaces the owner reference-based indexer with a more robust approach:
a field indexer on the ParentScheduledBackupLabel that is already set on all backups
created by ScheduledBackup. This label is always present regardless of the
backupOwnerReference configuration.

Closes #9466

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
@mnencia
Copy link
Member

mnencia commented Dec 22, 2025

I agree with @armru, let's close this PR in favor of #9489

@mnencia mnencia closed this Dec 22, 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

leonardoce pushed a commit that referenced this pull request Dec 23, 2025
…ed indexer

The ScheduledBackup controller was using a broken field indexer on owner references
to find child Backups for concurrency checking. The indexer checked for the wrong
owner kind, making it non-functional.

This fix replaces the owner reference-based indexer with a more robust approach:
a field indexer on the ParentScheduledBackupLabel that is already set on all backups
created by ScheduledBackup. This label is always present regardless of the
backupOwnerReference configuration.

Closes #9466

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
@andrew-farries andrew-farries deleted the dev/remove-backup-parent-indexer branch December 28, 2025 08:47
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 ok to merge 👌 This PR can be merged release-1.25 release-1.27 release-1.28 size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants