Skip to content

Commit

Permalink
*: fix the bug status always empty till backup complete radondb#687
Browse files Browse the repository at this point in the history
  • Loading branch information
acekingke committed Sep 8, 2022
1 parent e1a8c81 commit daa8ce7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
4 changes: 3 additions & 1 deletion api/v1alpha1/backup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ type BackupStatus struct {

// Completed indicates whether the backup is in a final state,
// no matter whether its' corresponding job failed or succeeded
Completed bool `json:"completed,omitempty"`
// +kubebuilder:default:=false
Completed bool `json:"completed"`
// Get the backup path.
BackupName string `json:"backupName,omitempty"`
// Get the backup Date
Expand Down Expand Up @@ -104,6 +105,7 @@ const (
BackupComplete BackupConditionType = "Complete"
// BackupFailed means backup has failed
BackupFailed BackupConditionType = "Failed"
BackupStart BackupConditionType = "Started"
)

//+kubebuilder:object:root=true
Expand Down
2 changes: 2 additions & 0 deletions backup/syncer/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ func (s *jobSyncer) SyncFn() error {

func (s *jobSyncer) updateStatus(job *batchv1.Job) {
// check for completion condition
s.backup.Status.Completed = false
s.backup.UpdateStatusCondition(v1alpha1.BackupStart, corev1.ConditionTrue, "backup has started", "backup has started")
if cond := jobCondition(batchv1.JobComplete, job); cond != nil {
s.backup.UpdateStatusCondition(v1alpha1.BackupComplete, cond.Status, cond.Reason, cond.Message)
if cond.Status == corev1.ConditionTrue {
Expand Down
3 changes: 3 additions & 0 deletions charts/mysql-operator/crds/mysql.radondb.com_backups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ spec:
description: Get the backup Type
type: string
completed:
default: false
description: Completed indicates whether the backup is in a final
state, no matter whether its' corresponding job failed or succeeded
type: boolean
Expand Down Expand Up @@ -124,6 +125,8 @@ spec:
- type
type: object
type: array
required:
- completed
type: object
type: object
served: true
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/mysql.radondb.com_backups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ spec:
description: Get the backup Type
type: string
completed:
default: false
description: Completed indicates whether the backup is in a final
state, no matter whether its' corresponding job failed or succeeded
type: boolean
Expand Down Expand Up @@ -124,6 +125,8 @@ spec:
- type
type: object
type: array
required:
- completed
type: object
type: object
served: true
Expand Down
13 changes: 8 additions & 5 deletions controllers/backup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,8 @@ func (r *BackupReconciler) SetupWithManager(mgr ctrl.Manager) error {
// Update backup Object and Status.
func (r *BackupReconciler) updateBackup(savedBackup *apiv1alpha1.Backup, backup *backup.Backup) error {
log := log.Log.WithName("controllers").WithName("Backup")
if !reflect.DeepEqual(savedBackup, backup.Unwrap()) {
if err := r.Update(context.TODO(), backup.Unwrap()); err != nil {
return err
}
}
// When update the backup, backup.Status will lost, and I don't know why,
// Since it updated to go 1.17, it has got this problem. So I put the update status first.
if !reflect.DeepEqual(savedBackup.Status, backup.Unwrap().Status) {
log.Info("update backup object status")
if err := r.Status().Update(context.TODO(), backup.Unwrap()); err != nil {
Expand All @@ -182,6 +179,12 @@ func (r *BackupReconciler) updateBackup(savedBackup *apiv1alpha1.Backup, backup
return err
}
}
if !reflect.DeepEqual(savedBackup, backup.Unwrap()) {
if err := r.Update(context.TODO(), backup.Unwrap()); err != nil {
return err
}
}

return nil
}

Expand Down

0 comments on commit daa8ce7

Please sign in to comment.