Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] add status and reason information when get status #313

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion config/crd/bases/starrocks.com_starrockswarehouses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 8 additions & 1 deletion deploy/starrocks.com_starrockswarehouses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions pkg/apis/starrocks/v1/starrockswarehouse_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand All @@ -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
Expand Down
43 changes: 27 additions & 16 deletions pkg/starrockswarehouse_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package pkg

import (
"context"
"errors"
"fmt"
"os"

srapi "github.com/StarRocks/starrocks-kubernetes-operator/pkg/apis/starrocks/v1"
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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)
}

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

Expand Down
Loading