Skip to content

Commit 5e05677

Browse files
authored
Merge pull request #561 from acekingke/ThreeJobs
job,controllers: clear history job must do in cluster, not in namespa…
2 parents dadc46f + abd4180 commit 5e05677

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

backup/backup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (b *Backup) Unwrap() *v1alhpa1.Backup {
4747

4848
// GetNameForJob returns the name of the job
4949
func (b *Backup) GetNameForJob() string {
50-
return fmt.Sprintf("%s-backup", b.Name)
50+
return fmt.Sprintf("%s-bak", b.Name)
5151
}
5252

5353
// Create the backup Domain Name or leader DNS.

backup/syncer/job.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ func (s *jobSyncer) SyncFn() error {
7373
s.job.Labels = map[string]string{
7474
"Host": s.backup.Spec.HostName,
7575
"Type": utils.BackupJobTypeName,
76+
77+
// Cluster used as selector.
78+
"Cluster": s.backup.Spec.ClusterName,
7679
}
7780
var backoff int32 = 3
7881
s.job.Spec.Template.Spec = s.ensurePodSpec(s.job.Spec.Template.Spec)

controllers/backup_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,17 @@ func (r *BackupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
9999
}
100100

101101
// Clear the backup, Just keep historyLimit len
102-
if err = r.clearHistoryJob(ctx, req, *backup.Spec.HistoryLimit); err != nil {
102+
if err = r.clearHistoryJob(ctx, req, *backup.Spec.HistoryLimit, backup.Spec.ClusterName); err != nil {
103103
return reconcile.Result{}, err
104104
}
105105
return ctrl.Result{}, nil
106106
}
107107

108108
// Clear the History finished Jobs over HistoryLimit.
109-
func (r *BackupReconciler) clearHistoryJob(ctx context.Context, req ctrl.Request, historyLimit int32) error {
109+
func (r *BackupReconciler) clearHistoryJob(ctx context.Context, req ctrl.Request, historyLimit int32, clusterName string) error {
110110
log := log.Log.WithName("controllers").WithName("Backup")
111111
backupJobs := batchv1.JobList{}
112-
labelSet := labels.Set{"Type": utils.BackupJobTypeName}
112+
labelSet := labels.Set{"Type": utils.BackupJobTypeName, "Cluster": clusterName}
113113
if err := r.List(context.TODO(), &backupJobs, &client.ListOptions{
114114
Namespace: req.Namespace, LabelSelector: labelSet.AsSelector(),
115115
}); err != nil {
@@ -137,7 +137,7 @@ func (r *BackupReconciler) clearHistoryJob(ctx context.Context, req ctrl.Request
137137
// at first check backup status completed.
138138
backup := backup.New(&apiv1alpha1.Backup{})
139139
namespacedName := types.NamespacedName{
140-
Name: strings.TrimSuffix(job.Name, "-backup"),
140+
Name: strings.TrimSuffix(job.Name, "-bak"),
141141
Namespace: job.Namespace,
142142
}
143143
if err := r.Get(context.TODO(), namespacedName, backup.Unwrap()); err != nil {

0 commit comments

Comments
 (0)