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

feat: extend hsacle api to support Add or Delete replicas #7393

Closed
wants to merge 15 commits into from

Conversation

wangyelei
Copy link
Contributor

@wangyelei wangyelei commented May 21, 2024

Background

Some users have reported that their Redis cluster can become very large, consisting of numerous heterogeneous instances. They frequently need to scale out or in the cluster based on business scenarios, which may involve offline specified instances.

Currently, the HorizontalScaling opsRequest only supports declarative APIs. Each scaling operation requires users to manually calculate the number of replicas in the final cluster and manage the offline instances, which can be quite cumbersome.

Therefore, there is a need to support Add and Delete operations to simplify the complexity of computing and managing offline instances.

API

  • replicasToAdd
    Adds replicas for the specified component and instance template.
  • replicasToDelete
    Deletes replicas for the specified component and instance template.
  • offlineInstancesToOnline
    Bring the specified offline instances back online.
    Replicas will be automatically adjust if the component and instance templates
    have no specified replicas and the component is not a sharding component.
  • onlineInstancesToOffline
    Specifies the instance name that needs to be taken offline.
    Replicas will be automatically adjust if the component and instance templates
    have no specified replicas and the component is not a sharding component.
  • instances.add
    Defines the configuration for new instances added during scaling, including resource requirements, labels, annotations, etc.
    New instances are created based on the provided InstanceTemplate.
  • instances.change
    Modifies the desired replicas count for existing InstanceTemplate.

Limitations

  1. If the submitted opsRequest attempts to delete instances created by a running opsRequest, it will be disallowed and will fail immediately.
  2. If there is an ongoing opsRequest targeting the final state (i.e., an opsRequest specifying replicas for component and instances), the ongoing final state opsRequest will be terminated.

Examples

The original cluster is a MySQL cluster with 3 replicas and cpu/memory(1c2Gi).

  1. scale in 2 replicas.
 horizontalScaling:
    - name: mysql
      replicasToDelete: 2
      # replicas: 1
  1. scale out 2 replicas.
horizontalScaling:
 - name: mysql
   # replicas: 5
   replicasToAdd: 2
  1. scale in 1 replicas with specified instance.
horizontalScaling:
   - name: mysql
     onlineInstancesToOffline: [pod-1]
  1. then scale out the specified instance which is offline.
 horizontalScaling:
    - name: mysql
      offlineInstancesToOnline: [pod-1]
  1. you can also scale in pod-1 but keep replicas is 3. and it will create a pod-3.
 horizontalScaling:
    - name: mysql
      replicasToDelete: 0
      onlineInstancesToOffline: [pod-1]
  1. add an heterogeneous instance with diffrentent cpu/memory
 horizontalScaling:
    - name: mysql
      replicasToAdd: 1 # must add 1 total replicas, otherwise it will delete an existing pod and create the 2c4g pod.
      instances:
        add:
        - name: 2c4g
           replicasToAdd: 1 # add 1 replicas with 2c4Gi resources.
           resources:
              limits:
                 cpu: 2
                 memory: 4Gi            
  1. delete the pod with cpu/memory 2c4g
 horizontalScaling:
    - name: mysql
      replicasToDelete: 1 # must delete 1 total replicas, otherwise it will create a new pod to keep replicas unchanged..
      instances:
        change:
        - name: 2c4g
           replicasToDelete: 1 # delete 1 replicas with 2c4Gi resources.         

@github-actions github-actions bot added the size/XXL Denotes a PR that changes 1000+ lines. label May 21, 2024
@wangyelei wangyelei linked an issue May 21, 2024 that may be closed by this pull request
@apecloud-bot apecloud-bot requested a review from realzyy May 21, 2024 06:25
Copy link

codecov bot commented May 21, 2024

Codecov Report

Attention: Patch coverage is 79.85948% with 86 lines in your changes are missing coverage. Please review.

Project coverage is 65.68%. Comparing base (07ea008) to head (da8cc4f).
Report is 14 commits behind head on main.

Files Patch % Lines
controllers/apps/operations/horizontal_scaling.go 87.71% 21 Missing and 8 partials ⚠️
apis/apps/v1alpha1/opsrequest_webhook.go 69.01% 15 Missing and 7 partials ⚠️
apis/apps/v1alpha1/opsrequest_types.go 0.00% 8 Missing ⚠️
controllers/apps/operations/upgrade.go 30.00% 6 Missing and 1 partial ⚠️
controllers/apps/operations/ops_progress_util.go 88.46% 4 Missing and 2 partials ⚠️
controllers/apps/operations/vertical_scaling.go 55.55% 3 Missing and 1 partial ⚠️
controllers/apps/operations/ops_comp_helper.go 81.25% 3 Missing ⚠️
controllers/apps/operations/volume_expansion.go 40.00% 2 Missing and 1 partial ⚠️
controllers/apps/operations/restart.go 33.33% 1 Missing and 1 partial ⚠️
controllers/apps/operations/stop.go 71.42% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7393      +/-   ##
==========================================
+ Coverage   65.54%   65.68%   +0.13%     
==========================================
  Files         342      342              
  Lines       41658    41918     +260     
==========================================
+ Hits        27306    27534     +228     
- Misses      11957    11982      +25     
- Partials     2395     2402       +7     
Flag Coverage Δ
unittests 65.68% <79.85%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@apecloud-bot apecloud-bot added approved PR Approved Test and removed approved PR Approved Test labels May 21, 2024
@wangyelei wangyelei marked this pull request as draft May 22, 2024 08:27
@wangyelei wangyelei marked this pull request as ready for review May 28, 2024 01:51
apis/apps/v1alpha1/opsrequest_types.go Show resolved Hide resolved
apis/apps/v1alpha1/opsrequest_types.go Show resolved Hide resolved
apis/apps/v1alpha1/opsrequest_webhook.go Outdated Show resolved Hide resolved
apis/apps/v1alpha1/opsrequest_webhook.go Outdated Show resolved Hide resolved
apis/apps/v1alpha1/opsrequest_webhook.go Outdated Show resolved Hide resolved
apis/apps/v1alpha1/opsrequest_webhook.go Outdated Show resolved Hide resolved
controllers/apps/operations/ops_progress_util.go Outdated Show resolved Hide resolved
@wangyelei wangyelei changed the title feat: extend hsacle api to support Add and Delete operator feat: extend hsacle api to support Add or Delete replicas May 29, 2024
@wangyelei wangyelei closed this Jun 3, 2024
@github-actions github-actions bot added this to the Release 0.9.0 milestone Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/user-interaction size/XXL Denotes a PR that changes 1000+ lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Features] Horizontalscaling supports to add or delete replicas
5 participants