Skip to content

Commit

Permalink
Merge pull request radondb#561 from acekingke/ThreeJobs
Browse files Browse the repository at this point in the history
job,controllers: clear history job must do in cluster, not in namespa…
  • Loading branch information
acekingke authored Jul 1, 2022
2 parents ceec2ab + e708616 commit c6bbe25
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (b *Backup) Unwrap() *v1alhpa1.Backup {

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

// Create the backup Domain Name or leader DNS.
Expand Down
3 changes: 3 additions & 0 deletions backup/syncer/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ func (s *jobSyncer) SyncFn() error {
s.job.Labels = map[string]string{
"Host": s.backup.Spec.HostName,
"Type": utils.BackupJobTypeName,

// Cluster used as selector.
"Cluster": s.backup.Spec.ClusterName,
}
var backoff int32 = 3
s.job.Spec.Template.Spec = s.ensurePodSpec(s.job.Spec.Template.Spec)
Expand Down
8 changes: 4 additions & 4 deletions controllers/backup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,17 @@ func (r *BackupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
}

// Clear the backup, Just keep historyLimit len
if err = r.clearHistoryJob(ctx, req, *backup.Spec.HistoryLimit); err != nil {
if err = r.clearHistoryJob(ctx, req, *backup.Spec.HistoryLimit, backup.Spec.ClusterName); err != nil {
return reconcile.Result{}, err
}
return ctrl.Result{}, nil
}

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

0 comments on commit c6bbe25

Please sign in to comment.