Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cffeef9

Browse files
committedDec 20, 2023
[BugFix] Remove HPA when autoScalingPolicy is removed
Signed-off-by: yandongxiao <[email protected]>
1 parent 055a744 commit cffeef9

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed
 

‎pkg/k8sutils/templates/service/spec.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package service
1717
import (
1818
corev1 "k8s.io/api/core/v1"
1919

20-
"github.com/StarRocks/starrocks-kubernetes-operator/pkg/apis/starrocks/v1"
20+
v1 "github.com/StarRocks/starrocks-kubernetes-operator/pkg/apis/starrocks/v1"
2121
)
2222

2323
func MakeSearchService(serviceName string, externalService *corev1.Service, ports []corev1.ServicePort) *corev1.Service {

‎pkg/subcontrollers/cn/cn_controller.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,10 @@ func (cc *CnController) SyncCnSpec(ctx context.Context, object object.StarRocksO
183183
// build and deploy HPA
184184
if cnSpec.AutoScalingPolicy != nil {
185185
return cc.deployAutoScaler(ctx, object, cnSpec, *cnSpec.AutoScalingPolicy, &sts)
186+
} else {
187+
// If the HPA policy is nil, delete the HPA resource.
188+
return cc.deleteAutoScaler(ctx, object)
186189
}
187-
return nil
188190
}
189191

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

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

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

347-
autoScalerName := cc.generateAutoScalerName(src.Name, (*srapi.StarRocksCnSpec)(nil))
348-
if err := k8sutils.DeleteAutoscaler(ctx, cc.k8sClient, src.Namespace, autoScalerName); err != nil && !apierrors.IsNotFound(err) {
352+
autoScalerName := cc.generateAutoScalerName(object.AliasName, (*srapi.StarRocksCnSpec)(nil))
353+
if err := k8sutils.DeleteAutoscaler(ctx, cc.k8sClient, object.Namespace, autoScalerName); err != nil && !apierrors.IsNotFound(err) {
349354
logger.Error(err, "delete autoscaler failed")
350355
return err
351356
}
@@ -381,7 +386,7 @@ func (cc *CnController) ClearResources(ctx context.Context, src *srapi.StarRocks
381386
return err
382387
}
383388

384-
if err := cc.deleteAutoScaler(ctx, src); err != nil && !apierrors.IsNotFound(err) {
389+
if err := cc.deleteAutoScaler(ctx, object.NewFromCluster(src)); err != nil && !apierrors.IsNotFound(err) {
385390
logger.Error(err, "delete autoscaler failed")
386391
return err
387392
}

‎pkg/subcontrollers/subcontroller.go

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type ClusterSubController interface {
3737
SyncCluster(ctx context.Context, src *srapi.StarRocksCluster) error
3838

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

4243
// GetControllerName return the controller name, beController, feController,cnController for log.

0 commit comments

Comments
 (0)
Please sign in to comment.