Skip to content

Commit 99aad1c

Browse files
authored
K8SPSMDB-1237: fix .keep for incremental backups (#1894)
* K8SPSMDB-1237: fix .keep for incremental backups https://perconadev.atlassian.net/browse/K8SPSMDB-1237 * update cr.yaml
1 parent 676b4db commit 99aad1c

File tree

2 files changed

+4
-45
lines changed

2 files changed

+4
-45
lines changed

deploy/cr.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,6 @@ spec:
731731
# - name: weekly-s3-us-west-incremental
732732
# enabled: false
733733
# schedule: "0 1 * * *"
734-
# keep: 5
735734
# type: incremental
736735
# storageName: s3-us-west
737736
# compressionType: gzip

pkg/controller/perconaservermongodb/backup.go

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ package perconaservermongodb
33
import (
44
"container/heap"
55
"context"
6-
"fmt"
76
"time"
87

98
"github.com/pkg/errors"
109
"github.com/robfig/cron/v3"
11-
batchv1 "k8s.io/api/batch/v1"
1210
corev1 "k8s.io/api/core/v1"
1311
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
1412
k8serrors "k8s.io/apimachinery/pkg/api/errors"
@@ -103,51 +101,13 @@ func (r *ReconcilePerconaServerMongoDB) createOrUpdateBackupTask(ctx context.Con
103101
func (r *ReconcilePerconaServerMongoDB) deleteOldBackupTasks(ctx context.Context, cr *api.PerconaServerMongoDB, ctasks map[string]api.BackupTaskSpec) error {
104102
log := logf.FromContext(ctx)
105103

106-
if cr.CompareVersion("1.13.0") < 0 {
107-
ls := naming.NewBackupCronJobLabels(cr, cr.Spec.Backup.Labels)
108-
tasksList := &batchv1.CronJobList{}
109-
err := r.client.List(ctx,
110-
tasksList,
111-
&client.ListOptions{
112-
Namespace: cr.Namespace,
113-
LabelSelector: labels.SelectorFromSet(ls),
114-
},
115-
)
116-
if err != nil {
117-
return fmt.Errorf("get backup list: %v", err)
118-
}
119-
120-
for _, t := range tasksList.Items {
121-
if spec, ok := ctasks[t.Name]; ok {
122-
// TODO: make .keep to work with incremental backups
123-
if spec.Type == defs.IncrementalBackup {
124-
continue
125-
}
126-
if spec.Keep > 0 {
127-
oldjobs, err := r.oldScheduledBackups(ctx, cr, t.Name, spec.Keep)
128-
if err != nil {
129-
return fmt.Errorf("remove old backups: %v", err)
130-
}
131-
132-
for _, todel := range oldjobs {
133-
err = r.client.Delete(ctx, &todel)
134-
if err != nil {
135-
return fmt.Errorf("failed to delete backup object: %v", err)
136-
}
137-
}
138-
}
139-
} else {
140-
err := r.client.Delete(ctx, &t)
141-
if err != nil && !k8sErrors.IsNotFound(err) {
142-
return fmt.Errorf("delete backup task %s: %v", t.Name, err)
143-
}
144-
}
145-
}
146-
return nil
147-
}
148104
r.crons.backupJobs.Range(func(k, v interface{}) bool {
149105
item := v.(BackupScheduleJob)
150106
if spec, ok := ctasks[item.Name]; ok {
107+
// TODO: make .keep to work with incremental backups
108+
if spec.Type == defs.IncrementalBackup {
109+
return true
110+
}
151111
if spec.Keep > 0 {
152112
oldjobs, err := r.oldScheduledBackups(ctx, cr, item.Name, spec.Keep)
153113
if err != nil {

0 commit comments

Comments
 (0)