Skip to content

Commit

Permalink
feat: Supports upper-layer modification of the InstanceSet's UpdateSt…
Browse files Browse the repository at this point in the history
…rategy

Signed-off-by: Liang Deng <[email protected]>
  • Loading branch information
YTGhost committed Aug 13, 2024
1 parent 99cb59e commit c33642b
Show file tree
Hide file tree
Showing 28 changed files with 394 additions and 281 deletions.
30 changes: 23 additions & 7 deletions apis/apps/v1alpha1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,25 @@ type UserResourceRefs struct {
ConfigMapRefs []ConfigMapRef `json:"configMapRefs,omitempty"`
}

// InstanceUpdateStrategy indicates the strategy that the InstanceSet
// controller will use to perform updates.
type InstanceUpdateStrategy struct {
// Partition indicates the ordinal at which the InstanceSet should be partitioned
// for updates. During a rolling update, all pods from ordinal Replicas-1 to
// Partition are updated. All pods from ordinal Partition-1 to 0 remain untouched.
// This is helpful in being able to do a canary based deployment. The default value is 0.
// +optional
Partition *int32 `json:"partition,omitempty"`
// The maximum number of pods that can be unavailable during the update.
// Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%).
// Absolute number is calculated from percentage by rounding up. This can not be 0.
// Defaults to 1. The field applies to all pods in the range 0 to Replicas-1.
// That means if there is any unavailable pod in the range 0 to Replicas-1,
// it will be counted towards MaxUnavailable.
// +optional
MaxUnavailable *intstr.IntOrString `json:"maxUnavailable,omitempty"`
}

// InstanceTemplate allows customization of individual replica configurations in a Component.
type InstanceTemplate struct {
// Name specifies the unique name of the instance Pod created using this InstanceTemplate.
Expand Down Expand Up @@ -790,15 +809,12 @@ type ClusterComponentSpec struct {
// +optional
ServiceAccountName string `json:"serviceAccountName,omitempty"`

// Defines the update strategy for the Component.
// Indicates the InstanceUpdateStrategy that will be
// employed to update Pods in the InstanceSet when a revision is made to
// Template.
//
// Deprecated since v0.9.
// This field is maintained for backward compatibility and its use is discouraged.
// Existing usage should be updated to the current preferred approach to avoid compatibility issues in future releases.
//
// +kubebuilder:deprecatedversion:warning="This field has been deprecated since 0.9.0"
// +optional
UpdateStrategy *UpdateStrategy `json:"updateStrategy,omitempty"`
InstanceUpdateStrategy InstanceUpdateStrategy `json:"instanceUpdateStrategy,omitempty"`

// Controls the concurrency of pods during initial scale up, when replacing pods on nodes,
// or when scaling down. It only used when `PodManagementPolicy` is set to `Parallel`.
Expand Down
7 changes: 7 additions & 0 deletions apis/apps/v1alpha1/component_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ type ComponentSpec struct {
// +optional
ServiceAccountName string `json:"serviceAccountName,omitempty"`

// Indicates the InstanceUpdateStrategy that will be
// employed to update Pods in the InstanceSet when a revision is made to
// Template.
//
// +optional
InstanceUpdateStrategy InstanceUpdateStrategy `json:"instanceUpdateStrategy,omitempty"`

// Controls the concurrency of pods during initial scale up, when replacing pods on nodes,
// or when scaling down. It only used when `PodManagementPolicy` is set to `Parallel`.
// The default Concurrency is 100%.
Expand Down
32 changes: 27 additions & 5 deletions apis/apps/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 30 additions & 12 deletions apis/workloads/v1alpha1/instanceset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,35 @@ type SchedulingPolicy struct {
TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
}

// InstanceUpdateStrategy indicates the strategy that the InstanceSet
// controller will use to perform updates. It includes any additional parameters
// necessary to perform the update for the indicated strategy.
type InstanceUpdateStrategy struct {
// Partition indicates the ordinal at which the InstanceSet should be partitioned
// for updates. During a rolling update, all pods from ordinal Replicas-1 to
// Partition are updated. All pods from ordinal Partition-1 to 0 remain untouched.
// This is helpful in being able to do a canary based deployment. The default value is 0.
// +optional
Partition *int32 `json:"partition,omitempty"`
// The maximum number of pods that can be unavailable during the update.
// Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%).
// Absolute number is calculated from percentage by rounding up. This can not be 0.
// Defaults to 1. The field applies to all pods in the range 0 to Replicas-1.
// That means if there is any unavailable pod in the range 0 to Replicas-1,
// it will be counted towards MaxUnavailable.
// +optional
MaxUnavailable *intstr.IntOrString `json:"maxUnavailable,omitempty"`
// Members(Pods) update strategy.
//
// - serial: update Members one by one that guarantee minimum component unavailable time.
// - bestEffortParallel: update Members in parallel that guarantee minimum component un-writable time.
// - parallel: force parallel
//
// +kubebuilder:validation:Enum={Serial,BestEffortParallel,Parallel}
// +optional
MemberUpdateStrategy *MemberUpdateStrategy `json:"memberUpdateStrategy,omitempty"`
}

// Range represents a range with a start and an end value.
// It is used to define a continuous segment.
type Range struct {
Expand Down Expand Up @@ -326,10 +355,9 @@ type InstanceSetSpec struct {
// Indicates the StatefulSetUpdateStrategy that will be
// employed to update Pods in the InstanceSet when a revision is made to
// Template.
// UpdateStrategy.Type will be set to appsv1.OnDeleteStatefulSetStrategyType if MemberUpdateStrategy is not nil
//
// Note: This field will be removed in future version.
UpdateStrategy appsv1.StatefulSetUpdateStrategy `json:"updateStrategy,omitempty"`
UpdateStrategy InstanceUpdateStrategy `json:"updateStrategy,omitempty"`

// A list of roles defined in the system.
//
Expand All @@ -346,16 +374,6 @@ type InstanceSetSpec struct {
// +optional
MembershipReconfiguration *MembershipReconfiguration `json:"membershipReconfiguration,omitempty"`

// Members(Pods) update strategy.
//
// - serial: update Members one by one that guarantee minimum component unavailable time.
// - bestEffortParallel: update Members in parallel that guarantee minimum component un-writable time.
// - parallel: force parallel
//
// +kubebuilder:validation:Enum={Serial,BestEffortParallel,Parallel}
// +optional
MemberUpdateStrategy *MemberUpdateStrategy `json:"memberUpdateStrategy,omitempty"`

// Indicates that the InstanceSet is paused, meaning the reconciliation of this InstanceSet object will be paused.
// +optional
Paused bool `json:"paused,omitempty"`
Expand Down
35 changes: 30 additions & 5 deletions apis/workloads/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 54 additions & 26 deletions config/crd/bases/apps.kubeblocks.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,33 @@ spec:
- name
type: object
type: array
instanceUpdateStrategy:
description: |-
Indicates the InstanceUpdateStrategy that will be
employed to update Pods in the InstanceSet when a revision is made to
Template.
properties:
maxUnavailable:
anyOf:
- type: integer
- type: string
description: |-
The maximum number of pods that can be unavailable during the update.
Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%).
Absolute number is calculated from percentage by rounding up. This can not be 0.
Defaults to 1. The field applies to all pods in the range 0 to Replicas-1.
That means if there is any unavailable pod in the range 0 to Replicas-1,
it will be counted towards MaxUnavailable.
x-kubernetes-int-or-string: true
partition:
description: |-
Partition indicates the ordinal at which the InstanceSet should be partitioned
for updates. During a rolling update, all pods from ordinal Replicas-1 to
Partition are updated. All pods from ordinal Partition-1 to 0 remain untouched.
This is helpful in being able to do a canary based deployment. The default value is 0.
format: int32
type: integer
type: object
instances:
description: |-
Allows for the customization of configuration values for each instance within a Component.
Expand Down Expand Up @@ -5680,19 +5707,6 @@ spec:
type: object
type: array
x-kubernetes-preserve-unknown-fields: true
updateStrategy:
description: |-
Defines the update strategy for the Component.


Deprecated since v0.9.
This field is maintained for backward compatibility and its use is discouraged.
Existing usage should be updated to the current preferred approach to avoid compatibility issues in future releases.
enum:
- Serial
- BestEffortParallel
- Parallel
type: string
userResourceRefs:
description: |-
Allows users to specify custom ConfigMaps and Secrets to be mounted as volumes
Expand Down Expand Up @@ -9772,6 +9786,33 @@ spec:
- name
type: object
type: array
instanceUpdateStrategy:
description: |-
Indicates the InstanceUpdateStrategy that will be
employed to update Pods in the InstanceSet when a revision is made to
Template.
properties:
maxUnavailable:
anyOf:
- type: integer
- type: string
description: |-
The maximum number of pods that can be unavailable during the update.
Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%).
Absolute number is calculated from percentage by rounding up. This can not be 0.
Defaults to 1. The field applies to all pods in the range 0 to Replicas-1.
That means if there is any unavailable pod in the range 0 to Replicas-1,
it will be counted towards MaxUnavailable.
x-kubernetes-int-or-string: true
partition:
description: |-
Partition indicates the ordinal at which the InstanceSet should be partitioned
for updates. During a rolling update, all pods from ordinal Replicas-1 to
Partition are updated. All pods from ordinal Partition-1 to 0 remain untouched.
This is helpful in being able to do a canary based deployment. The default value is 0.
format: int32
type: integer
type: object
instances:
description: |-
Allows for the customization of configuration values for each instance within a Component.
Expand Down Expand Up @@ -14859,19 +14900,6 @@ spec:
type: object
type: array
x-kubernetes-preserve-unknown-fields: true
updateStrategy:
description: |-
Defines the update strategy for the Component.


Deprecated since v0.9.
This field is maintained for backward compatibility and its use is discouraged.
Existing usage should be updated to the current preferred approach to avoid compatibility issues in future releases.
enum:
- Serial
- BestEffortParallel
- Parallel
type: string
userResourceRefs:
description: |-
Allows users to specify custom ConfigMaps and Secrets to be mounted as volumes
Expand Down
27 changes: 27 additions & 0 deletions config/crd/bases/apps.kubeblocks.io_components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,33 @@ spec:
- name
type: object
type: array
instanceUpdateStrategy:
description: |-
Indicates the InstanceUpdateStrategy that will be
employed to update Pods in the InstanceSet when a revision is made to
Template.
properties:
maxUnavailable:
anyOf:
- type: integer
- type: string
description: |-
The maximum number of pods that can be unavailable during the update.
Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%).
Absolute number is calculated from percentage by rounding up. This can not be 0.
Defaults to 1. The field applies to all pods in the range 0 to Replicas-1.
That means if there is any unavailable pod in the range 0 to Replicas-1,
it will be counted towards MaxUnavailable.
x-kubernetes-int-or-string: true
partition:
description: |-
Partition indicates the ordinal at which the InstanceSet should be partitioned
for updates. During a rolling update, all pods from ordinal Replicas-1 to
Partition are updated. All pods from ordinal Partition-1 to 0 remain untouched.
This is helpful in being able to do a canary based deployment. The default value is 0.
format: int32
type: integer
type: object
instances:
description: |-
Allows for the customization of configuration values for each instance within a Component.
Expand Down
Loading

0 comments on commit c33642b

Please sign in to comment.