Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ spec:
lastTransition:
format: date-time
type: string
lastWriteAt:
format: date-time
type: string
latestRestorableTime:
format: date-time
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ spec:
lastTransition:
format: date-time
type: string
lastWriteAt:
format: date-time
type: string
latestRestorableTime:
format: date-time
type: string
Expand Down
6 changes: 6 additions & 0 deletions deploy/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ spec:
lastTransition:
format: date-time
type: string
lastWriteAt:
format: date-time
type: string
latestRestorableTime:
format: date-time
type: string
Expand Down Expand Up @@ -274,6 +277,9 @@ spec:
lastTransition:
format: date-time
type: string
lastWriteAt:
format: date-time
type: string
latestRestorableTime:
format: date-time
type: string
Expand Down
6 changes: 6 additions & 0 deletions deploy/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ spec:
lastTransition:
format: date-time
type: string
lastWriteAt:
format: date-time
type: string
latestRestorableTime:
format: date-time
type: string
Expand Down Expand Up @@ -274,6 +277,9 @@ spec:
lastTransition:
format: date-time
type: string
lastWriteAt:
format: date-time
type: string
latestRestorableTime:
format: date-time
type: string
Expand Down
6 changes: 6 additions & 0 deletions deploy/cw-bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ spec:
lastTransition:
format: date-time
type: string
lastWriteAt:
format: date-time
type: string
latestRestorableTime:
format: date-time
type: string
Expand Down Expand Up @@ -274,6 +277,9 @@ spec:
lastTransition:
format: date-time
type: string
lastWriteAt:
format: date-time
type: string
latestRestorableTime:
format: date-time
type: string
Expand Down
17 changes: 8 additions & 9 deletions e2e-tests/functions
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ wait_backup_agent() {
set_debug
}

print_operator_logs() {
kubectl_bin logs ${OPERATOR_NS:+-n $OPERATOR_NS} $(get_operator_pod)
}

wait_backup() {
local backup_name=$1
local target_state=${2:-"ready"}
Expand All @@ -243,15 +247,10 @@ wait_backup() {
let retry+=1
current_status=$(kubectl_bin get psmdb-backup $backup_name -o jsonpath='{.status.state}')
if [[ $retry -ge 600 || ${current_status} == 'error' ]]; then
kubectl_bin logs ${OPERATOR_NS:+-n $OPERATOR_NS} $(get_operator_pod) \
| grep -v 'level=info' \
| grep -v 'level=debug' \
| grep -v 'Getting tasks for pod' \
| grep -v 'Getting pods from source' \
| tail -200
print_operator_logs | tail -n 200
kubectl_bin get psmdb-backup
kubectl_bin describe psmdb-backup/${backup_name}
echo "Backup object psmdb-backup/${backup_name} is in ${current_status} state."
echo something went wrong with operator or kubernetes cluster
exit 1
fi
done
Expand Down Expand Up @@ -356,7 +355,7 @@ get_mongod_pods() {
kubectl_bin get pod \
--no-headers \
-l app.kubernetes.io/instance=${cluster} \
-l app.kubernetes.io/component=mongod
-l app.kubernetes.io/component=mongod | awk '{print $1}'

}

Expand All @@ -366,7 +365,7 @@ collect_physical_restore_logs() {

for pod in $(get_mongod_pods ${cluster}); do
desc "pbm-agent logs from ${pod}"
kubectl_bin exec -it ${pod} -- cat /tmp/pbm-agent.log || true
kubectl_bin exec ${pod} -- cat /tmp/pbm-agent.log || echo "failed to get /tmp/pbm-agent.log from ${pod}"
done
}

Expand Down
1 change: 0 additions & 1 deletion e2e-tests/pitr/conf/some-name-rs0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ spec:
enabled: true
oplogSpanMin: 2
oplogOnly: false
oplogSpanMin: 10
compressionType: gzip
compressionLevel: 6
replsets:
Expand Down
6 changes: 6 additions & 0 deletions e2e-tests/version-service/conf/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ spec:
lastTransition:
format: date-time
type: string
lastWriteAt:
format: date-time
type: string
latestRestorableTime:
format: date-time
type: string
Expand Down Expand Up @@ -274,6 +277,9 @@ spec:
lastTransition:
format: date-time
type: string
lastWriteAt:
format: date-time
type: string
latestRestorableTime:
format: date-time
type: string
Expand Down
36 changes: 19 additions & 17 deletions pkg/apis/psmdb/v1/perconaservermongodbbackup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,27 @@ const (

// PerconaServerMongoDBBackupStatus defines the observed state of PerconaServerMongoDBBackup
type PerconaServerMongoDBBackupStatus struct {
Type defs.BackupType `json:"type,omitempty"`
State BackupState `json:"state,omitempty"`
StartAt *metav1.Time `json:"start,omitempty"`
CompletedAt *metav1.Time `json:"completed,omitempty"`
LastTransition *metav1.Time `json:"lastTransition,omitempty"`
Destination string `json:"destination,omitempty"`
StorageName string `json:"storageName,omitempty"`
S3 *BackupStorageS3Spec `json:"s3,omitempty"`
Azure *BackupStorageAzureSpec `json:"azure,omitempty"`
Filesystem *BackupStorageFilesystemSpec `json:"filesystem,omitempty"`
ReplsetNames []string `json:"replsetNames,omitempty"`
PBMname string `json:"pbmName,omitempty"`
Size string `json:"size,omitempty"`
Type defs.BackupType `json:"type,omitempty"`
State BackupState `json:"state,omitempty"`
Destination string `json:"destination,omitempty"`
StorageName string `json:"storageName,omitempty"`
S3 *BackupStorageS3Spec `json:"s3,omitempty"`
Azure *BackupStorageAzureSpec `json:"azure,omitempty"`
Filesystem *BackupStorageFilesystemSpec `json:"filesystem,omitempty"`
ReplsetNames []string `json:"replsetNames,omitempty"`
PBMname string `json:"pbmName,omitempty"`
Size string `json:"size,omitempty"`

// Deprecated: Use PBMPods instead
PBMPod string `json:"pbmPod,omitempty"`
PBMPods map[string]string `json:"pbmPods,omitempty"`
Error string `json:"error,omitempty"`
LatestRestorableTime *metav1.Time `json:"latestRestorableTime,omitempty"`
PBMPod string `json:"pbmPod,omitempty"`
PBMPods map[string]string `json:"pbmPods,omitempty"`
Error string `json:"error,omitempty"`

StartAt *metav1.Time `json:"start,omitempty"`
CompletedAt *metav1.Time `json:"completed,omitempty"`
LastWriteAt *metav1.Time `json:"lastWriteAt,omitempty"`
LastTransition *metav1.Time `json:"lastTransition,omitempty"`
LatestRestorableTime *metav1.Time `json:"latestRestorableTime,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
28 changes: 16 additions & 12 deletions pkg/apis/psmdb/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/controller/perconaservermongodbbackup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ func (b *Backup) Status(ctx context.Context, cr *api.PerconaServerMongoDBBackup)
status.CompletedAt = &metav1.Time{
Time: time.Unix(meta.LastTransitionTS, 0),
}
status.LastWriteAt = &metav1.Time{
Time: time.Unix(int64(meta.LastWriteTS.T), 0),
}
case defs.StatusStarting:
passed := time.Now().UTC().Sub(time.Unix(meta.StartTS, 0))
if passed >= pbmStartingDeadline {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (r *ReconcilePerconaServerMongoDBRestore) Reconcile(ctx context.Context, re
}

if cr.Status.State == psmdbv1.RestoreStateNew {
err := r.validate(ctx, cr, cluster)
err = r.validate(ctx, cr, cluster)
if err != nil {
if errors.Is(err, errWaitingPBM) {
err = nil
Expand All @@ -209,7 +209,7 @@ func (r *ReconcilePerconaServerMongoDBRestore) Reconcile(ctx context.Context, re
return rr, nil
}

return rr, errors.Wrap(err, "failed to validate restore")
return reconcile.Result{}, errors.Wrap(err, "failed to validate restore")
}

if cluster.Spec.Sharding.Enabled {
Expand Down
27 changes: 27 additions & 0 deletions pkg/controller/perconaservermongodbrestore/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,32 @@ func (r *ReconcilePerconaServerMongoDBRestore) validate(ctx context.Context, cr
return errors.Wrap(err, "failed to validate backup")
}

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

switch {
case pitr.Type == psmdbv1.PITRestoreTypeDate && pitr.Date != nil:
if bcp.Status.LastWriteAt != nil {
if pitr.Date.Equal(bcp.Status.LastWriteAt) {
return errors.New("backup's last write is equal to target time")
}
if pitr.Date.Before(bcp.Status.LastWriteAt) {
return errors.New("backup's last write is later than target time")
}
}

ts := pitr.Date.Unix()
if _, err := pbmc.GetPITRChunkContains(ctx, ts); err != nil {
return err
}
case pitr.Type == psmdbv1.PITRestoreTypeLatest:
_, err := pbmc.GetLatestTimelinePITR(ctx)
if err != nil {
return err
}
}

return nil
}
Loading
Loading