Skip to content

K8SPG-904 Allow no repos when restoring from dataSource#1395

Merged
hors merged 21 commits intomainfrom
K8SPG-904
Feb 26, 2026
Merged

K8SPG-904 Allow no repos when restoring from dataSource#1395
hors merged 21 commits intomainfrom
K8SPG-904

Conversation

@oksana-grishchenko
Copy link
Contributor

@oksana-grishchenko oksana-grishchenko commented Jan 8, 2026

K8SPG-904 Powered by Pull Request Badge

Allow no repos when restoring from dataSource

Problem:
K8SPG-904 When restoring from dataSource while backups are disabled, the restore job fails to be created.

Cause:
The crunchyv1beta1.Backups.PGBackRest.Image was never set if the backups were disabled which caused the following error:

Job.batch "cluster1-pgbackrest-restore" is invalid: spec.template.spec.initContainers[0].image: Required value`

Solution:
Init the crunchyv1beta1.Backups.PGBackRest.Image with the given image from the PG CR.

Note: if the crunchyv1beta1.Backups.PGBackRest.Image is set then the repohost sts appears which was the cause why the backup-enable-disable e2e test was failing on step 2.
So the following changes are also applied:

  • the codebase is updated to set the crunchyv1beta1.Backups.PGBackRest.Image only if the pg cluster has datasource
  • the backup-enable-disable test is updated so that in addition to the regular cluster creation it also creates a cluster from datasource, checks the repohost sts appearance and the presense of the image in crunchyv1beta1.Backups.PGBackRest.Image

CHECKLIST

Jira

  • Is the Jira ticket created and referenced properly?
  • Does the Jira ticket have the proper statuses for documentation (Needs Doc) and QA (Needs QA)?
  • Does the Jira ticket link to the proper milestone (Fix Version field)?

Tests

  • Is an E2E test/test case added for the new feature/change?
  • Are unit tests added where appropriate?

Config/Logging/Testability

  • Are all needed new/changed options added to default YAML files?
  • Are all needed new/changed options added to the Helm Chart?
  • Did we add proper logging messages for operator actions?
  • Did we ensure compatibility with the previous version or cluster upgrade process?
  • Does the change support oldest and newest supported PG version?
  • Does the change support oldest and newest supported Kubernetes version?

@it-percona-cla
Copy link

it-percona-cla commented Jan 8, 2026

CLA assistant check
All committers have signed the CLA.

Comment on lines 507 to 511
return crunchyv1beta1.Backups{
PGBackRest: crunchyv1beta1.PGBackRestArchive{
Image: b.PGBackRest.Image,
},
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crunchy controller decides whether backups are disabled by comparing backup spec with crunchyv1beta1.Backups{PGBackRest: crunchyv1beta1.PGBackRestArchive{}}

backupsSpecFound = !reflect.DeepEqual(postgresCluster.Spec.Backups, v1beta1.Backups{PGBackRest: v1beta1.PGBackRestArchive{}})

will this affect that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will (in a way).
That's why the backup-enable-disable test was updated to show how a cluster without repos but with dataSource is expected to work. Which is: in case we specify the image in the crunchyv1beta1.Backups{PGBackRest: crunchyv1beta1.PGBackRestArchive{}} section, crunchy considers backups as enabled indeed, however since there are no repos defined, it's only expected that the sts will be created for repohost but no backup job should be created until we enable the backups. It's being explicitly checked in this new test step

Please let me know if you have any concerns about this behaviour.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to not create the sts for repohost?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently there is this RELATED_IMAGE_PGBACKREST env var for crunchy cluster that should do the trick without defining the image in the .backups.pgbackrest section. That could potentially allow to reach the goal but avoid creating sts. I'll play around with it and get back.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

posted the current state to the related ticket, the work on it is paused until the proper solution is found.

@oksana-grishchenko oksana-grishchenko marked this pull request as draft January 20, 2026 14:58
Copilot AI review requested due to automatic review settings February 23, 2026 13:57
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request allows PostgreSQL clusters to be restored from a dataSource when backups are disabled. Previously, the restore job would fail with an error about the missing pgBackRest image when creating a cluster with a dataSource while backups were disabled.

Changes:

  • Added an Enabled field to the Backups struct to explicitly control backup functionality
  • Added validation requiring spec.backups.pgbackrest.image when spec.dataSource is set
  • Modified the backup reconciliation logic to preserve restore status and consider the Enabled flag when determining if backups are active
  • Added comprehensive E2E tests covering cluster creation from dataSource with disabled backups

Reviewed changes

Copilot reviewed 19 out of 23 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkg/apis/postgres-operator.crunchydata.com/v1beta1/postgrescluster_types.go Added Enabled *bool field to Backups struct
pkg/apis/postgres-operator.crunchydata.com/v1beta1/zz_generated.deepcopy.go Auto-generated deepcopy code for new Enabled field
pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go Added validation rule and modified ToCrunchy conversion to pass image when backups disabled
internal/controller/postgrescluster/pgbackrest.go Updated reconciliation logic to check Enabled flag and preserve Restore status
config/crd/bases/* Updated CRD definitions with new Enabled field and validation rules
deploy/*.yaml Updated deployment manifests and CRD bundles (includes test image reference)
e2e-tests/tests/backup-enable-disable/* Added comprehensive E2E tests for datasource restore with disabled backups

@pooknull pooknull marked this pull request as ready for review February 24, 2026 15:35
Copilot AI review requested due to automatic review settings February 24, 2026 15:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 23 changed files in this pull request and generated no new comments.

egegunes
egegunes previously approved these changes Feb 25, 2026
@egegunes egegunes added this to the v2.9.0 milestone Feb 25, 2026
Copilot AI review requested due to automatic review settings February 25, 2026 10:53
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 24 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings February 25, 2026 13:45
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 24 changed files in this pull request and generated 1 comment.

Comment on lines 377 to 383
// Backups defines a PostgreSQL archive configuration
type Backups struct {
Enabled *bool `json:"enabled,omitempty"`

// pgBackRest archive configuration
// +optional
PGBackRest PGBackRestArchive `json:"pgbackrest"`
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Problem: Adding Backups.Enabled changes PostgresCluster.BackupSpecFound() semantics because BackupSpecFound() still uses reflect.DeepEqual(cr.Spec.Backups, Backups{PGBackRest: ...}) and does not account for enabled=false.
  2. Why it matters: A cluster with spec.backups.enabled=false will now be treated as having a backup spec, which makes config.VerifyImageValues() start requiring a pgBackRest image even though backups are explicitly disabled (and other code paths like ObserveBackupUniverse now treat enabled=false as “no backups spec”).
  3. Fix: Update BackupSpecFound() (and any similar checks) to return false when Enabled is set to false (e.g., gate the existing DeepEqual check behind ptr.Deref(cr.Spec.Backups.Enabled, true) or an explicit Enabled != nil && !*Enabled early return).

Copilot uses AI. Check for mistakes.
@hors hors requested a review from egegunes February 25, 2026 21:54
@JNKPercona
Copy link
Collaborator

Test Name Result Time
backup-enable-disable passed 00:00:00
builtin-extensions passed 00:00:00
cert-manager-tls passed 00:00:00
custom-envs passed 00:00:00
custom-extensions passed 00:15:03
custom-tls passed 00:00:00
database-init-sql passed 00:00:00
demand-backup passed 00:00:00
demand-backup-offline-snapshot passed 00:00:00
dynamic-configuration passed 00:00:00
finalizers passed 00:00:00
init-deploy passed 00:00:00
huge-pages passed 00:00:00
monitoring passed 00:00:00
monitoring-pmm3 passed 00:00:00
one-pod passed 00:00:00
operator-self-healing passed 00:00:00
pg-tde passed 00:10:02
pitr passed 00:00:00
scaling passed 00:00:00
scheduled-backup passed 00:00:00
self-healing passed 00:00:00
sidecars passed 00:00:00
standby-pgbackrest passed 00:00:00
standby-streaming passed 00:00:00
start-from-backup passed 00:00:00
tablespaces passed 00:00:00
telemetry-transfer passed 00:00:00
upgrade-consistency passed 00:00:00
upgrade-minor passed 00:00:00
users passed 00:00:00
Summary Value
Tests Run 31/31
Job Duration 00:36:25
Total Test Time 00:25:05

commit: eed0c65
image: perconalab/percona-postgresql-operator:PR-1395-eed0c65bc

@hors hors merged commit 1219c8b into main Feb 26, 2026
15 of 16 checks passed
@hors hors deleted the K8SPG-904 branch February 26, 2026 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants