K8SPSMDB-1339: Validate PiTR target before starting restore#1908
Conversation
| "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" |
There was a problem hiding this comment.
[goimports-reviser] reported by reviewdog 🐶
| psmdbv1 "github.com/percona/percona-server-mongodb-operator/pkg/apis/psmdb/v1" | |
| psmdbv1 "github.com/percona/percona-server-mongodb-operator/pkg/apis/psmdb/v1" |
There was a problem hiding this comment.
we can apply this, it makes sense.
| return errors.Wrap(err, "failed to validate backup") | ||
| } | ||
|
|
||
| if pitr := cr.Spec.PITR; pitr != nil { |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
we can apply this, it makes sense.
| }, | ||
| }, | ||
| }, | ||
| "", |
There was a problem hiding this comment.
this is not needed, the default value is empty string already.
There was a problem hiding this comment.
go forces me to set values for each field in struct
| Namespace: ns, | ||
| }, | ||
| Spec: psmdbv1.PerconaServerMongoDBBackupSpec{ | ||
| Type: defs.LogicalBackup, |
There was a problem hiding this comment.
Is this option here doing anything for the test? Seems wrong because this test is regarding physical backups.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
We can simply if tt.expectedErr != "" { here instead of calculating the len()
6880ab6
| echo "Still in progress at $(date)" | ||
| sleep 10 | ||
| sleep 120 |
There was a problem hiding this comment.
[shfmt] reported by reviewdog 🐶
| echo "Still in progress at $(date)" | |
| sleep 10 | |
| sleep 120 | |
| echo "Still in progress at $(date)" | |
| sleep 120 |
commit: 4f95fb9 |
CHANGE DESCRIPTION
This PRs add necessary validations for point-in-time-recovery target in PerconaServerMongoDBRestore objects:
pitr.typeisdate, backup's last write must not be equal topitr.date.pitr.typeisdate, backup's last write must not be later thanpitr.date.pitr.typeisdate, PBM must have required oplogs that includepitr.datein its metadata.pitr.typeislatest, PBM must have at least one oplog chunk in its metadata.CHECKLIST
Jira
Needs Doc) and QA (Needs QA)?Tests
compare/*-oc.yml)?Config/Logging/Testability