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

fix: h-scale opsRequest validation considers replicas and shards limit #8834

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions apis/operations/v1alpha1/opsrequest_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ func (r *OpsRequest) validateHorizontalScalingSpec(hScale HorizontalScaling, com
if replicaChanger.ReplicaChanges != nil && allReplicaChanges > *replicaChanger.ReplicaChanges {
return fmt.Errorf(`%s "replicaChanges" can't be less than the sum of "replicaChanges" for specified instance templates`, msgPrefix)
}
if isScaleIn && len(offlineOrOnlineInsNames) == int(compSpec.Replicas) {
yipeng1030 marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf(`scaling down all the replicas of component "%s" is not allowed`, hScale.ComponentName)
}
return nil
}
if scaleIn != nil {
Expand Down
24 changes: 24 additions & 0 deletions controllers/operations/opsrequest_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,30 @@ var _ = Describe("OpsRequest Controller", func() {
})).Should(Succeed())
})

It("HorizontalScaling when offline the only instance in MySQL", func() {
createMysqlCluster(2)
By("mock cluster status")
Expect(testapps.ChangeObj(&testCtx, clusterObj, func(clusterObj *appsv1.Cluster) {
mockSetClusterStatusPhaseToRunning(clusterKey)
})).Should(Succeed())
ops := testops.NewOpsRequestObj("test-ops", testCtx.DefaultNamespace,
clusterObj.Name, opsv1alpha1.HorizontalScalingType)
ops.Spec.HorizontalScalingList = []opsv1alpha1.HorizontalScaling{
{
ComponentOps: opsv1alpha1.ComponentOps{ComponentName: mysqlCompName},
ScaleIn: &opsv1alpha1.ScaleIn{
OnlineInstancesToOffline: []string{clusterNamePrefix + mysqlCompName + "-0", clusterNamePrefix + mysqlCompName + "-1"},
},
},
}
ops.Labels = nil

err := ops.Validate(ctx, nil, clusterObj, true)

Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("scaling down all the replicas of component"))
})

It("delete Running opsRequest", func() {
By("Create a horizontalScaling ops")
createMysqlCluster(3)
Expand Down
Loading