Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

job,controllers: clear history job must do in cluster, not in namespa… #561

Merged
merged 2 commits into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
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