Skip to content

Commit

Permalink
chore: improved prompt message for configuration reconcile
Browse files Browse the repository at this point in the history
  • Loading branch information
sophon-zt committed Oct 7, 2023
1 parent 1f87a87 commit bf4e347
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
27 changes: 10 additions & 17 deletions controllers/apps/configuration/configuration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"

appsv1alpha1 "github.com/apecloud/kubeblocks/apis/apps/v1alpha1"
"github.com/apecloud/kubeblocks/internal/configuration/core"
cfgutil "github.com/apecloud/kubeblocks/internal/configuration/util"
"github.com/apecloud/kubeblocks/internal/controller/component"
intctrlutil "github.com/apecloud/kubeblocks/internal/controllerutil"
)
Expand Down Expand Up @@ -164,8 +162,6 @@ func (r *ConfigurationReconciler) runTasks(taskCtx TaskContext, tasks []Task) (e
for _, task := range tasks {
task.Status.UpdateRevision = revision
if err := task.Do(taskCtx.fetcher, synthesizedComp, revision); err != nil {
task.Status.Phase = appsv1alpha1.CMergeFailedPhase
task.Status.Message = cfgutil.ToPointer(err.Error())
errs = append(errs, err)
continue
}
Expand Down Expand Up @@ -194,22 +190,19 @@ func (r *ConfigurationReconciler) SetupWithManager(mgr ctrl.Manager) error {

func fromItemStatus(ctx intctrlutil.RequestCtx, status *appsv1alpha1.ConfigurationStatus, item appsv1alpha1.ConfigurationItemDetail) *appsv1alpha1.ConfigurationItemDetailStatus {
if item.ConfigSpec == nil {
ctx.Log.WithName(item.Name).Error(core.MakeError("configSpec phase is not ready and pass: %v", item), "")
ctx.Log.V(1).WithName(item.Name).Info(fmt.Sprintf("configuration is creating and pass: %s", item.Name))
return nil
}
for i := range status.ConfigurationItemStatus {
itemStatus := &status.ConfigurationItemStatus[i]
switch {
case itemStatus.Name != item.Name:
case isReconcileStatus(itemStatus.Phase):
return itemStatus
default:
ctx.Log.WithName(item.Name).Error(core.MakeError("configSpec phase is not ready and pass: %v", itemStatus), "")
return nil
}
itemStatus := status.GetItemStatus(item.Name)
if itemStatus == nil || itemStatus.Phase == "" {
ctx.Log.V(1).WithName(item.Name).Info(fmt.Sprintf("configuration cr is creating and pass: %v", item))
return nil
}
if !isReconcileStatus(itemStatus.Phase) {
ctx.Log.V(1).WithName(item.Name).Info(fmt.Sprintf("configuration cr is creating or deleting and pass: %v", itemStatus))
return nil
}
ctx.Log.WithName(item.Name).Error(core.MakeError("configSpec phase is not ready and pass: %v", item), "")
return nil
return itemStatus
}

func isReconcileStatus(phase appsv1alpha1.ConfigurationPhase) bool {
Expand Down
3 changes: 3 additions & 0 deletions controllers/apps/configuration/reconcile_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

appsv1alpha1 "github.com/apecloud/kubeblocks/apis/apps/v1alpha1"
"github.com/apecloud/kubeblocks/internal/configuration/core"
cfgutil "github.com/apecloud/kubeblocks/internal/configuration/util"
"github.com/apecloud/kubeblocks/internal/controller/component"
"github.com/apecloud/kubeblocks/internal/controller/configuration"
intctrlutil "github.com/apecloud/kubeblocks/internal/controllerutil"
Expand Down Expand Up @@ -95,8 +96,10 @@ func syncImpl(fetcher *Task,
Sync().
Complete()
if err != nil {
status.Message = cfgutil.ToPointer(err.Error())
status.Phase = appsv1alpha1.CMergeFailedPhase
} else {
status.Message = nil
status.Phase = appsv1alpha1.CMergedPhase
}
return
Expand Down

0 comments on commit bf4e347

Please sign in to comment.