Skip to content
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
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