@@ -277,22 +277,31 @@ func (r *OpsRequest) validateHorizontalScaling(ctx context.Context, cli client.C
277277 compOpsList [i ] = v .ComponentOps
278278 hScaleMap [v .ComponentName ] = horizontalScalingList [i ]
279279 }
280- if err := r .checkComponentExistence (cluster , compOpsList ); err != nil {
280+ err := r .checkComponentExistence (cluster , compOpsList )
281+ if err != nil {
281282 return err
282283 }
284+ getMinAndMaxReplicas := func (compDefName string ) (int , int , error ) {
285+ // Default values if no limit is found
286+ minNum , maxNum := 1 , 16384
287+ if compDefName != "" {
288+ compDef := & appsv1.ComponentDefinition {}
289+ if err := cli .Get (ctx , client.ObjectKey {Name : compDefName , Namespace : r .Namespace }, compDef ); err != nil {
290+ return 0 , 9 , err
291+ }
292+ if compDef .Spec .ReplicasLimit != nil {
293+ minNum = int (compDef .Spec .ReplicasLimit .MinReplicas )
294+ maxNum = int (compDef .Spec .ReplicasLimit .MaxReplicas )
295+ }
296+ }
297+ return minNum , maxNum , nil
298+ }
299+
283300 for _ , comSpec := range cluster .Spec .ComponentSpecs {
284301 if hScale , ok := hScaleMap [comSpec .Name ]; ok {
285- // Default values if no limit is found
286- minNum , maxNum := 1 , 16384
287- if comSpec .ComponentDef != "" {
288- compDef := & appsv1.ComponentDefinition {}
289- if err := cli .Get (ctx , client.ObjectKey {Name : comSpec .ComponentDef , Namespace : r .Namespace }, compDef ); err != nil {
290- return err
291- }
292- if compDef .Spec .ReplicasLimit != nil {
293- minNum = int (compDef .Spec .ReplicasLimit .MinReplicas )
294- maxNum = int (compDef .Spec .ReplicasLimit .MaxReplicas )
295- }
302+ minNum , maxNum , err := getMinAndMaxReplicas (comSpec .ComponentDef )
303+ if err != nil {
304+ return err
296305 }
297306 if err := r .validateHorizontalScalingSpec (hScale , comSpec , cluster .Name , false , maxNum , minNum ); err != nil {
298307 return err
@@ -306,14 +315,21 @@ func (r *OpsRequest) validateHorizontalScaling(ctx context.Context, cli client.C
306315 }
307316 // Default values if no limit is found
308317 minNum , maxNum := 1 , 2048
309- if spec .ShardingDef != "" {
310- shardingDef := & appsv1.ShardingDefinition {}
311- if err := cli .Get (ctx , types.NamespacedName {Name : spec .ShardingDef , Namespace : r .Namespace }, shardingDef ); err != nil {
312- return err
318+ if hScale .Shards != nil {
319+ if spec .ShardingDef != "" {
320+ shardingDef := & appsv1.ShardingDefinition {}
321+ if err := cli .Get (ctx , types.NamespacedName {Name : spec .ShardingDef , Namespace : r .Namespace }, shardingDef ); err != nil {
322+ return err
323+ }
324+ if shardingDef .Spec .ShardsLimit != nil {
325+ minNum = int (shardingDef .Spec .ShardsLimit .MinShards )
326+ maxNum = int (shardingDef .Spec .ShardsLimit .MaxShards )
327+ }
313328 }
314- if shardingDef .Spec .ShardsLimit != nil {
315- minNum = int (shardingDef .Spec .ShardsLimit .MinShards )
316- maxNum = int (shardingDef .Spec .ShardsLimit .MaxShards )
329+ } else {
330+ minNum , maxNum , err = getMinAndMaxReplicas (spec .Template .ComponentDef )
331+ if err != nil {
332+ return err
317333 }
318334 }
319335 if err := r .validateHorizontalScalingSpec (hScale , spec .Template , cluster .Name , true , maxNum , minNum ); err != nil {
0 commit comments