diff --git a/config/crd/bases/starrocks.com_starrockswarehouses.yaml b/config/crd/bases/starrocks.com_starrockswarehouses.yaml index 153badbe..90103fdc 100644 --- a/config/crd/bases/starrocks.com_starrockswarehouses.yaml +++ b/config/crd/bases/starrocks.com_starrockswarehouses.yaml @@ -17,7 +17,14 @@ spec: singular: starrockswarehouse scope: Namespaced versions: - - name: v1 + - additionalPrinterColumns: + - jsonPath: .status.phase + name: status + type: string + - jsonPath: .status.reason + name: reason + type: string + name: v1 schema: openAPIV3Schema: description: StarRocksWarehouse defines a starrocks warehouse. diff --git a/deploy/starrocks.com_starrockswarehouses.yaml b/deploy/starrocks.com_starrockswarehouses.yaml index 2ccbd423..2c60a76a 100644 --- a/deploy/starrocks.com_starrockswarehouses.yaml +++ b/deploy/starrocks.com_starrockswarehouses.yaml @@ -17,7 +17,14 @@ spec: singular: starrockswarehouse scope: Namespaced versions: - - name: v1 + - additionalPrinterColumns: + - jsonPath: .status.phase + name: status + type: string + - jsonPath: .status.reason + name: reason + type: string + name: v1 schema: openAPIV3Schema: properties: diff --git a/pkg/apis/starrocks/v1/starrockswarehouse_types.go b/pkg/apis/starrocks/v1/starrockswarehouse_types.go index 3c5f0083..259cab4b 100644 --- a/pkg/apis/starrocks/v1/starrockswarehouse_types.go +++ b/pkg/apis/starrocks/v1/starrockswarehouse_types.go @@ -59,9 +59,6 @@ type WarehouseComponentStatus = StarRocksCnStatus // StarRocksWarehouseStatus defines the observed state of StarRocksWarehouse. type StarRocksWarehouseStatus struct { - // Phase represents the state of a warehouse. The possible value are: running, failed, pending and deleting. - Phase Phase `json:"phase"` - // WarehouseStatus represents the status of service. The status has reconciling, failed and running. *WarehouseComponentStatus `json:",inline"` } @@ -71,6 +68,8 @@ type StarRocksWarehouseStatus struct { // +kubebuilder:resource:shortName=warehouse // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +kubebuilder:subresource:status +// +kubebuilder:printcolumn:name="status",type=string,JSONPath=`.status.phase` +// +kubebuilder:printcolumn:name="reason",type=string,JSONPath=`.status.reason` // +kubebuilder:storageversion // +k8s:openapi-gen=true // +genclient diff --git a/pkg/starrockswarehouse_controller.go b/pkg/starrockswarehouse_controller.go index acb8bea8..aeea74cd 100644 --- a/pkg/starrockswarehouse_controller.go +++ b/pkg/starrockswarehouse_controller.go @@ -18,6 +18,8 @@ package pkg import ( "context" + "errors" + "fmt" "os" srapi "github.com/StarRocks/starrocks-kubernetes-operator/pkg/apis/starrocks/v1" @@ -85,29 +87,44 @@ func (r *StarRocksWarehouseReconciler) Reconcile(ctx context.Context, req ctrl.R return ctrl.Result{}, err } - warehouse = warehouse.DeepCopy() + if warehouse.Status.WarehouseComponentStatus == nil { + warehouse.Status.WarehouseComponentStatus = &srapi.StarRocksCnStatus{ + StarRocksComponentStatus: srapi.StarRocksComponentStatus{ + Phase: srapi.ComponentReconciling, + }, + } + } for _, controller := range r.subControllers { klog.Infof("StarRocksWarehouseReconciler reconcile component, namespace=%v, name=%v, controller=%v", warehouse.Namespace, warehouse.Name, controller.GetControllerName()) if err := controller.SyncWarehouse(ctx, warehouse); err != nil { - if err == cn.SpecMissingError { - klog.Infof("the spec part is invalid, skip sync warehouse %s/%s", warehouse.Namespace, warehouse.Name) + warehouse.Status.Phase = srapi.ComponentFailed + if errors.Is(err, cn.SpecMissingError) { + reason := fmt.Sprintf("the spec part is invalid %s/%s", warehouse.Namespace, warehouse.Name) + warehouse.Status.Reason = reason + klog.Info(reason) return ctrl.Result{}, nil - } else if err == cn.StarRocksClusterMissingError { - klog.Infof("StarRocksCluster %s/%s not found, skip sync warehouse %s/%s", + } else if errors.Is(err, cn.StarRocksClusterMissingError) { + reason := fmt.Sprintf("StarRocksCluster %s/%s not found for %s/%s", warehouse.Namespace, warehouse.Spec.StarRocksCluster, warehouse.Namespace, warehouse.Name) + warehouse.Status.Reason = reason + klog.Infof(reason) return ctrl.Result{}, nil - } else if err == cn.FeNotOkError { - klog.Infof("StarRocksFe is not ok, skip sync warehouse %s/%s", warehouse.Namespace, warehouse.Name) + } else if errors.Is(err, cn.FeNotOkError) { + klog.Infof("StarRocksFe is not ready, %s/%s", warehouse.Namespace, warehouse.Name) return ctrl.Result{}, nil - } else if err == cn.GetFeFeatureInfoError { - klog.Infof("failed to get FE feature or FE does not support multi-warehouse, skip sync warehouse %s/%s", + } else if errors.Is(err, cn.GetFeFeatureInfoError) { + reason := fmt.Sprintf("failed to get FE feature or FE does not support multi-warehouse %s/%s", warehouse.Namespace, warehouse.Name) + warehouse.Status.Reason = reason + klog.Info(reason) return ctrl.Result{}, nil } - klog.Errorf("failed to reconcile component, namespace=%v, name=%v, controller=%v, error=%v", + reason := fmt.Sprintf("failed to reconcile component, namespace=%v, name=%v, controller=%v, error=%v", warehouse.Namespace, warehouse.Name, controller.GetControllerName(), err) + warehouse.Status.Reason = reason + klog.Info(err) return ctrl.Result{}, err } } @@ -122,12 +139,6 @@ func (r *StarRocksWarehouseReconciler) Reconcile(ctx context.Context, req ctrl.R } } - warehouse.Status.Phase = srapi.ClusterRunning - phase := GetPhaseFromComponent(&warehouse.Status.WarehouseComponentStatus.StarRocksComponentStatus) - if phase != "" { - warehouse.Status.Phase = phase - } - return ctrl.Result{}, r.UpdateStarRocksWarehouseStatus(ctx, warehouse) } diff --git a/pkg/sub_controller/cn/cn_controller.go b/pkg/sub_controller/cn/cn_controller.go index 444afa19..59f1c4f5 100644 --- a/pkg/sub_controller/cn/cn_controller.go +++ b/pkg/sub_controller/cn/cn_controller.go @@ -214,16 +214,8 @@ func (cc *CnController) UpdateWarehouseStatus(warehouse *srapi.StarRocksWarehous return nil } - if warehouse.Status.WarehouseComponentStatus == nil { - warehouse.Status.WarehouseComponentStatus = &srapi.StarRocksCnStatus{ - StarRocksComponentStatus: srapi.StarRocksComponentStatus{ - Phase: srapi.ComponentReconciling, - }, - } - } status := warehouse.Status.WarehouseComponentStatus status.Phase = srapi.ComponentReconciling - return cc.UpdateStatus(object.NewFromWarehouse(warehouse), template.ToCnSpec(), status) }