Skip to content

Commit

Permalink
change status to StatefulSetReady and add ReconcileSuccess, and fix u…
Browse files Browse the repository at this point in the history
…nstable test

Signed-off-by: YZ775 <yuzuki-mimura@cybozu.co.jp>
  • Loading branch information
YZ775 committed Aug 4, 2023
1 parent 8be729b commit 1e924b7
Show file tree
Hide file tree
Showing 4 changed files with 252 additions and 203 deletions.
36 changes: 17 additions & 19 deletions controllers/mysqlcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ func (r *MySQLClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request
}
result, err := reconciler(ctx, req, cluster)
if err2 := r.updateReconcileStatus(ctx, cluster, err); err2 != nil {
log.Error(err2, "failed to update reconcile status")
log.Error(err2, "failed to exec updateReconcileStatus()")
err = err2
}
return result, err
}
Expand All @@ -177,7 +178,7 @@ func (r *MySQLClusterReconciler) reconcileV1(ctx context.Context, req ctrl.Reque
log := crlog.FromContext(ctx)

defer func(ctx2 context.Context, cluster2 *mocov1beta2.MySQLCluster) {
if err2 := r.updateStatusByStatefulSet(ctx2, cluster2); err != nil {
if err2 := r.updateStatusByStatefulSet(ctx2, cluster2); err2 != nil {
err = err2
log.Error(err2, "failed to update status")
}
Expand Down Expand Up @@ -1905,10 +1906,10 @@ func (r *MySQLClusterReconciler) updateStatusByStatefulSet(ctx context.Context,
}
meta.SetStatusCondition(&cluster.Status.Conditions, cond)
if err := r.Status().Update(ctx, cluster); err != nil {
log.Error(err, "failed to update reconciliation info")
log.Error(err, "failed to update ConditionStatefulSetReady")
return err
}
log.Info("update status successfully")
log.Info("update ConditionStatefulSetReady successfully")
}
return nil
}
Expand All @@ -1923,22 +1924,19 @@ func (r *MySQLClusterReconciler) updateReconcileStatus(ctx context.Context, clus
message = "reconcile successfully"
success = metav1.ConditionTrue
}
currentConditionReconcileSuccess := meta.FindStatusCondition(cluster.Status.Conditions, mocov1beta2.ConditionReconcileSuccess)
if currentConditionReconcileSuccess == nil || currentConditionReconcileSuccess.Status != success || currentConditionReconcileSuccess.ObservedGeneration != cluster.Generation {
cond := metav1.Condition{
Type: mocov1beta2.ConditionReconcileSuccess,
Status: success,
ObservedGeneration: cluster.Generation,
Reason: reason,
Message: message,
}
meta.SetStatusCondition(&cluster.Status.Conditions, cond)
if err := r.Status().Update(ctx, cluster); err != nil {
log.Error(err, "failed to update reconciliation info")
return err
}
log.Info("update status successfully")
cond := metav1.Condition{
Type: mocov1beta2.ConditionReconcileSuccess,
Status: success,
ObservedGeneration: cluster.Generation,
Reason: reason,
Message: message,
}
meta.SetStatusCondition(&cluster.Status.Conditions, cond)
if err := r.Status().Update(ctx, cluster); err != nil {
log.Error(err, "failed to update reconcile status")
return err
}
log.Info("update reconcile status successfully")
return nil
}

Expand Down
Loading

0 comments on commit 1e924b7

Please sign in to comment.