Skip to content

K8SPSMDB-1339: Validate PiTR target before starting restore#1908

Merged
hors merged 18 commits intomainfrom
K8SPSMDB-1339
Jun 4, 2025
Merged

K8SPSMDB-1339: Validate PiTR target before starting restore#1908
hors merged 18 commits intomainfrom
K8SPSMDB-1339

Conversation

@egegunes
Copy link
Copy Markdown
Contributor

@egegunes egegunes commented May 5, 2025

K8SPSMDB-1339 Powered by Pull Request Badge

CHANGE DESCRIPTION

This PRs add necessary validations for point-in-time-recovery target in PerconaServerMongoDBRestore objects:

  1. if pitr.type is date, backup's last write must not be equal to pitr.date.
  2. if pitr.type is date, backup's last write must not be later than pitr.date.
  3. if pitr.type is date, PBM must have required oplogs that include pitr.date in its metadata.
  4. if pitr.type is latest, PBM must have at least one oplog chunk in its metadata.

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?
  • Are OpenShift compare files changed for E2E tests (compare/*-oc.yml)?

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 MongoDB version?
  • Does the change support oldest and newest supported Kubernetes version?

@pull-request-size pull-request-size bot added the size/S 10-29 lines label May 5, 2025
@egegunes egegunes added this to the v1.21.0 milestone May 5, 2025
@pull-request-size pull-request-size bot added size/M 30-99 lines and removed size/S 10-29 lines labels May 5, 2025
@github-actions github-actions bot added the tests label May 5, 2025
@pull-request-size pull-request-size bot added size/L 100-499 lines and removed size/M 30-99 lines labels May 5, 2025
"sigs.k8s.io/controller-runtime/pkg/client/fake"

"github.com/percona/percona-backup-mongodb/pbm/defs"
psmdbv1 "github.com/percona/percona-server-mongodb-operator/pkg/apis/psmdb/v1"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[goimports-reviser] reported by reviewdog 🐶

Suggested change
psmdbv1 "github.com/percona/percona-server-mongodb-operator/pkg/apis/psmdb/v1"
psmdbv1 "github.com/percona/percona-server-mongodb-operator/pkg/apis/psmdb/v1"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we can apply this, it makes sense.

@egegunes egegunes marked this pull request as ready for review May 20, 2025 15:47
return errors.Wrap(err, "failed to validate backup")
}

if pitr := cr.Spec.PITR; pitr != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Given that the nesting here with alll these if else and switch statements does not help readability a lot, maybe we can early return the opposite check like that:

	pitr := cr.Spec.PITR
	if pitr == nil {
		return nil
	}

After that the switch can be moved on the same level.

"sigs.k8s.io/controller-runtime/pkg/client/fake"

"github.com/percona/percona-backup-mongodb/pbm/defs"
psmdbv1 "github.com/percona/percona-server-mongodb-operator/pkg/apis/psmdb/v1"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we can apply this, it makes sense.

},
},
},
"",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is not needed, the default value is empty string already.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

go forces me to set values for each field in struct

Namespace: ns,
},
Spec: psmdbv1.PerconaServerMongoDBBackupSpec{
Type: defs.LogicalBackup,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this option here doing anything for the test? Seems wrong because this test is regarding physical backups.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we use the status field for our logic, but fixed

runtimeObjs := []client.Object{&secret, tt.restore, cluster, tt.backup}
r := fakeReconciler(runtimeObjs...)
err := r.validate(ctx, tt.restore, cluster)
if len(tt.expectedErr) > 0 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can simply if tt.expectedErr != "" { here instead of calculating the len()

@egegunes egegunes requested a review from valmiranogueira as a code owner May 27, 2025 17:56
@pull-request-size pull-request-size bot added size/XL 500-999 lines and removed size/L 100-499 lines labels May 27, 2025
@pull-request-size pull-request-size bot added size/L 100-499 lines and removed size/XL 500-999 lines labels May 28, 2025
@egegunes egegunes requested a review from gkech May 29, 2025 11:05
gkech
gkech previously approved these changes May 29, 2025
nmarukovich
nmarukovich previously approved these changes May 29, 2025
pooknull
pooknull previously approved these changes May 29, 2025
@egegunes egegunes dismissed stale reviews from pooknull, gkech, and nmarukovich via 6880ab6 June 2, 2025 10:45
gkech
gkech previously approved these changes Jun 3, 2025
@pull-request-size pull-request-size bot added size/XL 500-999 lines and removed size/L 100-499 lines labels Jun 3, 2025
@github-actions github-actions bot added the build label Jun 3, 2025
Comment on lines 41 to +42
echo "Still in progress at $(date)"
sleep 10
sleep 120
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[shfmt] reported by reviewdog 🐶

Suggested change
echo "Still in progress at $(date)"
sleep 10
sleep 120
echo "Still in progress at $(date)"
sleep 120

@JNKPercona
Copy link
Copy Markdown
Collaborator

Test name Status
arbiter passed
balancer passed
cross-site-sharded passed
custom-replset-name passed
custom-tls passed
custom-users-roles passed
custom-users-roles-sharded passed
data-at-rest-encryption passed
data-sharded passed
demand-backup passed
demand-backup-eks-credentials-irsa passed
demand-backup-fs passed
demand-backup-incremental passed
demand-backup-incremental-sharded passed
demand-backup-physical-parallel passed
demand-backup-physical-aws passed
demand-backup-physical-azure passed
demand-backup-physical-gcp passed
demand-backup-physical-minio passed
demand-backup-physical-sharded-parallel passed
demand-backup-physical-sharded-aws passed
demand-backup-physical-sharded-azure passed
demand-backup-physical-sharded-gcp passed
demand-backup-physical-sharded-minio passed
demand-backup-sharded passed
expose-sharded passed
finalizer passed
ignore-labels-annotations passed
init-deploy passed
ldap passed
ldap-tls passed
limits passed
liveness passed
mongod-major-upgrade passed
mongod-major-upgrade-sharded passed
monitoring-2-0 passed
monitoring-pmm3 passed
multi-cluster-service passed
multi-storage passed
non-voting-and-hidden passed
one-pod passed
operator-self-healing-chaos passed
pitr passed
pitr-physical passed
pitr-sharded passed
pitr-physical-backup-source passed
preinit-updates passed
pvc-resize passed
recover-no-primary passed
replset-overrides passed
rs-shard-migration passed
scaling passed
scheduled-backup passed
security-context passed
self-healing-chaos passed
service-per-pod passed
serviceless-external-nodes passed
smart-update passed
split-horizon passed
stable-resource-version passed
storage passed
tls-issue-cert-manager passed
upgrade passed
upgrade-consistency passed
upgrade-consistency-sharded-tls passed
upgrade-sharded passed
users passed
version-service passed
We run 68 out of 68

commit: 4f95fb9
image: perconalab/percona-server-mongodb-operator:PR-1908-4f95fb92

@hors hors merged commit 13cee14 into main Jun 4, 2025
17 of 19 checks passed
@hors hors deleted the K8SPSMDB-1339 branch June 4, 2025 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants