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

[BugFix] Remove HPA when autoScalingPolicy is removed #379

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
2 changes: 1 addition & 1 deletion pkg/k8sutils/templates/service/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package service
import (
corev1 "k8s.io/api/core/v1"

"github.com/StarRocks/starrocks-kubernetes-operator/pkg/apis/starrocks/v1"
v1 "github.com/StarRocks/starrocks-kubernetes-operator/pkg/apis/starrocks/v1"
)

func MakeSearchService(serviceName string, externalService *corev1.Service, ports []corev1.ServicePort) *corev1.Service {
Expand Down
15 changes: 10 additions & 5 deletions pkg/subcontrollers/cn/cn_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,10 @@ func (cc *CnController) SyncCnSpec(ctx context.Context, object object.StarRocksO
// build and deploy HPA
if cnSpec.AutoScalingPolicy != nil {
return cc.deployAutoScaler(ctx, object, cnSpec, *cnSpec.AutoScalingPolicy, &sts)
} else {
// If the HPA policy is nil, delete the HPA resource.
return cc.deleteAutoScaler(ctx, object)
}
return nil
}

// UpdateWarehouseStatus updates the status of StarRocksWarehouse.
Expand Down Expand Up @@ -253,6 +255,9 @@ func (cc *CnController) UpdateStatus(ctx context.Context, object object.StarRock
return nil
}

// ClearWarehouse clear the warehouse resource. It is different from ClearResources, which need to clear the
// CN related resources of StarRocksCluster. ClearWarehouse only has CN related resources, when the warehouse CR
// is deleted, sub resources of CN will be deleted by k8s.
func (cc *CnController) ClearWarehouse(ctx context.Context, namespace string, name string) error {
logger := logr.FromContextOrDiscard(ctx).WithName(cc.GetControllerName()).WithValues(log.ActionKey, log.ActionClearWarehouse)
ctx = logr.NewContext(ctx, logger)
Expand Down Expand Up @@ -341,11 +346,11 @@ func (cc *CnController) deployAutoScaler(ctx context.Context, object object.Star
}

// deleteAutoScaler delete the autoscaler.
func (cc *CnController) deleteAutoScaler(ctx context.Context, src *srapi.StarRocksCluster) error {
func (cc *CnController) deleteAutoScaler(ctx context.Context, object object.StarRocksObject) error {
logger := logr.FromContextOrDiscard(ctx)

autoScalerName := cc.generateAutoScalerName(src.Name, (*srapi.StarRocksCnSpec)(nil))
if err := k8sutils.DeleteAutoscaler(ctx, cc.k8sClient, src.Namespace, autoScalerName); err != nil && !apierrors.IsNotFound(err) {
autoScalerName := cc.generateAutoScalerName(object.AliasName, (*srapi.StarRocksCnSpec)(nil))
if err := k8sutils.DeleteAutoscaler(ctx, cc.k8sClient, object.Namespace, autoScalerName); err != nil && !apierrors.IsNotFound(err) {
logger.Error(err, "delete autoscaler failed")
return err
}
Expand Down Expand Up @@ -381,7 +386,7 @@ func (cc *CnController) ClearResources(ctx context.Context, src *srapi.StarRocks
return err
}

if err := cc.deleteAutoScaler(ctx, src); err != nil && !apierrors.IsNotFound(err) {
if err := cc.deleteAutoScaler(ctx, object.NewFromCluster(src)); err != nil && !apierrors.IsNotFound(err) {
logger.Error(err, "delete autoscaler failed")
return err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/subcontrollers/subcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type ClusterSubController interface {
SyncCluster(ctx context.Context, src *srapi.StarRocksCluster) error

// ClearResources clear all resource about sub-component.
// todo(yandongxiao): rename to ClearCluster
ClearResources(ctx context.Context, src *srapi.StarRocksCluster) error

// GetControllerName return the controller name, beController, feController,cnController for log.
Expand Down
Loading