diff --git a/controllers/backup_controller.go b/controllers/backup_controller.go index 2bc22bdf..93af50ce 100644 --- a/controllers/backup_controller.go +++ b/controllers/backup_controller.go @@ -82,7 +82,7 @@ func (r *BackupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr // save the backup for later check for diff savedBackup := backup.Unwrap().DeepCopy() - + backup.ObjectMeta.Labels = labels.Set{"cluster": backup.Spec.ClusterName} jobSyncer := backupSyncer.NewJobSyncer(r.Client, r.Scheme, backup) if err := syncer.Sync(ctx, jobSyncer, r.Recorder); err != nil { backup.UpdateStatusCondition(apiv1alpha1.BackupFailed, corev1.ConditionTrue, "CreateFailure", err.Error()) diff --git a/mysqlcluster/syncer/statefulset.go b/mysqlcluster/syncer/statefulset.go index 862be6cc..5f521506 100644 --- a/mysqlcluster/syncer/statefulset.go +++ b/mysqlcluster/syncer/statefulset.go @@ -569,18 +569,17 @@ func basicEventReason(objKindName string, err error) string { // check the backup is exist and running func (s *StatefulSetSyncer) backupIsRunning(ctx context.Context) (bool, error) { backuplist := apiv1alpha1.BackupList{} + labelSet := labels.Set{"cluster": s.Name} if err := s.cli.List(ctx, &backuplist, &client.ListOptions{ - Namespace: s.sfs.Namespace, + Namespace: s.sfs.Namespace, + LabelSelector: labelSet.AsSelector(), }, ); err != nil { return false, err } for _, bcp := range backuplist.Items { - if bcp.ClusterName != s.ClusterName { - continue - } if !bcp.Status.Completed { return true, nil }