Skip to content

Commit daa8ce7

Browse files
committed
*: fix the bug status always empty till backup complete #687
1 parent e1a8c81 commit daa8ce7

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

api/v1alpha1/backup_types.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ type BackupStatus struct {
5656

5757
// Completed indicates whether the backup is in a final state,
5858
// no matter whether its' corresponding job failed or succeeded
59-
Completed bool `json:"completed,omitempty"`
59+
// +kubebuilder:default:=false
60+
Completed bool `json:"completed"`
6061
// Get the backup path.
6162
BackupName string `json:"backupName,omitempty"`
6263
// Get the backup Date
@@ -104,6 +105,7 @@ const (
104105
BackupComplete BackupConditionType = "Complete"
105106
// BackupFailed means backup has failed
106107
BackupFailed BackupConditionType = "Failed"
108+
BackupStart BackupConditionType = "Started"
107109
)
108110

109111
//+kubebuilder:object:root=true

backup/syncer/job.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ func (s *jobSyncer) SyncFn() error {
8585

8686
func (s *jobSyncer) updateStatus(job *batchv1.Job) {
8787
// check for completion condition
88+
s.backup.Status.Completed = false
89+
s.backup.UpdateStatusCondition(v1alpha1.BackupStart, corev1.ConditionTrue, "backup has started", "backup has started")
8890
if cond := jobCondition(batchv1.JobComplete, job); cond != nil {
8991
s.backup.UpdateStatusCondition(v1alpha1.BackupComplete, cond.Status, cond.Reason, cond.Message)
9092
if cond.Status == corev1.ConditionTrue {

charts/mysql-operator/crds/mysql.radondb.com_backups.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ spec:
8989
description: Get the backup Type
9090
type: string
9191
completed:
92+
default: false
9293
description: Completed indicates whether the backup is in a final
9394
state, no matter whether its' corresponding job failed or succeeded
9495
type: boolean
@@ -124,6 +125,8 @@ spec:
124125
- type
125126
type: object
126127
type: array
128+
required:
129+
- completed
127130
type: object
128131
type: object
129132
served: true

config/crd/bases/mysql.radondb.com_backups.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ spec:
8989
description: Get the backup Type
9090
type: string
9191
completed:
92+
default: false
9293
description: Completed indicates whether the backup is in a final
9394
state, no matter whether its' corresponding job failed or succeeded
9495
type: boolean
@@ -124,6 +125,8 @@ spec:
124125
- type
125126
type: object
126127
type: array
128+
required:
129+
- completed
127130
type: object
128131
type: object
129132
served: true

controllers/backup_controller.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,8 @@ func (r *BackupReconciler) SetupWithManager(mgr ctrl.Manager) error {
169169
// Update backup Object and Status.
170170
func (r *BackupReconciler) updateBackup(savedBackup *apiv1alpha1.Backup, backup *backup.Backup) error {
171171
log := log.Log.WithName("controllers").WithName("Backup")
172-
if !reflect.DeepEqual(savedBackup, backup.Unwrap()) {
173-
if err := r.Update(context.TODO(), backup.Unwrap()); err != nil {
174-
return err
175-
}
176-
}
172+
// When update the backup, backup.Status will lost, and I don't know why,
173+
// Since it updated to go 1.17, it has got this problem. So I put the update status first.
177174
if !reflect.DeepEqual(savedBackup.Status, backup.Unwrap().Status) {
178175
log.Info("update backup object status")
179176
if err := r.Status().Update(context.TODO(), backup.Unwrap()); err != nil {
@@ -182,6 +179,12 @@ func (r *BackupReconciler) updateBackup(savedBackup *apiv1alpha1.Backup, backup
182179
return err
183180
}
184181
}
182+
if !reflect.DeepEqual(savedBackup, backup.Unwrap()) {
183+
if err := r.Update(context.TODO(), backup.Unwrap()); err != nil {
184+
return err
185+
}
186+
}
187+
185188
return nil
186189
}
187190

0 commit comments

Comments
 (0)