Skip to content

Commit

Permalink
[Enhancement] add status and reason information when get status (#313)
Browse files Browse the repository at this point in the history
Signed-off-by: yandongxiao <[email protected]>
yandongxiao authored Nov 21, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 07a993d commit 0ea7829
Showing 5 changed files with 45 additions and 29 deletions.
9 changes: 8 additions & 1 deletion config/crd/bases/starrocks.com_starrockswarehouses.yaml
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 8 additions & 1 deletion deploy/starrocks.com_starrockswarehouses.yaml
Original file line number Diff line number Diff line change
@@ -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:
5 changes: 2 additions & 3 deletions pkg/apis/starrocks/v1/starrockswarehouse_types.go
Original file line number Diff line number Diff line change
@@ -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
43 changes: 27 additions & 16 deletions pkg/starrockswarehouse_controller.go
Original file line number Diff line number Diff line change
@@ -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)
}

8 changes: 0 additions & 8 deletions pkg/sub_controller/cn/cn_controller.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 0ea7829

Please sign in to comment.