Skip to content

Commit

Permalink
use type alias
Browse files Browse the repository at this point in the history
  • Loading branch information
cjc7373 committed Nov 6, 2024
1 parent 5f454eb commit b18c91c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 88 deletions.
70 changes: 4 additions & 66 deletions apis/apps/v1/componentdefinition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

workloads "github.com/apecloud/kubeblocks/apis/workloads/v1"
)

// +genclient
Expand Down Expand Up @@ -1371,72 +1373,8 @@ type ComponentAvailableProbeAssertion struct {
}

// ReplicaRole represents a role that can be assumed by a component instance.
type ReplicaRole struct {
// Name defines the role's unique identifier. This value is used to set the "apps.kubeblocks.io/role" label
// on the corresponding object to identify its role.
//
// For example, common role names include:
// - "leader": The primary/master instance that handles write operations
// - "follower": Secondary/replica instances that replicate data from the leader
// - "learner": Read-only instances that don't participate in elections
//
// This field is immutable once set.
//
// +kubebuilder:validation:Required
// +kubebuilder:validation:MaxLength=32
// +kubebuilder:validation:Pattern=`^.*[^\s]+.*$`
Name string `json:"name"`

// Required indicates if at least one replica with this role must exist for the component to be considered
// operationally running. For example, a leader role may be required for the component to function.
//
// This field is immutable once set.
//
// +kubebuilder:default=false
// +optional
Required bool `json:"required"`

// UpdatePriority determines the order in which pods with different roles are updated.
// Pods are sorted by this priority (higher numbers = higher priority) and updated accordingly.
// Roles with the highest priority will be updated last.
//
// For example:
// - Leader role may have priority 2 (updated last)
// - Follower role may have priority 1 (updated before leader)
// - Learner role may have priority 0 (updated first)
//
// This field is immutable once set.
//
// +kubebuilder:default=0
// +optional
UpdatePriority int `json:"updatePriority"`

// ParticipatesInQuorum indicates if pods with this role are counted when determining quorum.
// This affects update strategies that need to maintain quorum for availability.
//
// For example, in a 5-pod component where:
// - 2 learner pods (participatesInQuorum=false)
// - 2 follower pods (participatesInQuorum=true)
// - 1 leader pod (participatesInQuorum=true)
// The quorum size would be 3 (based on the 3 participating pods), allowing parallel updates
// of 2 learners and 1 follower while maintaining quorum.
//
// This field is immutable once set.
//
// +kubebuilder:default=false
// +optional
ParticipatesInQuorum bool `json:"participatesInQuorum"`

// SwitchoverBeforeUpdate indicates if a role switchover operation should be performed before
// updating or scaling in pods with this role. This is typically used for leader roles to
// ensure minimal disruption during updates.
//
// This field is immutable once set.
//
// +kubebuilder:default=false
// +optional
SwitchoverBeforeUpdate bool `json:"switchoverBeforeUpdate"`
}
// +kubebuilder:object:generate=false
type ReplicaRole = workloads.ReplicaRole

// UpdateStrategy defines the update strategy for cluster components. This strategy determines how updates are applied
// across the cluster.
Expand Down
18 changes: 2 additions & 16 deletions apis/apps/v1/zz_generated.deepcopy.go

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

7 changes: 4 additions & 3 deletions config/crd/bases/apps.kubeblocks.io_componentdefinitions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8472,8 +8472,8 @@ spec:

This field is immutable.
items:
description: ReplicaRole represents a role that can be assumed by
a component instance.
description: ReplicaRole represents a role that can be assigned
to a component instance, defining its behavior and responsibilities.
properties:
name:
description: |-
Expand All @@ -8491,7 +8491,7 @@ spec:
maxLength: 32
pattern: ^.*[^\s]+.*$
type: string
participatesInQuorum:
participatesInQuorum bool:
default: false
description: |-
ParticipatesInQuorum indicates if pods with this role are counted when determining quorum.
Expand Down Expand Up @@ -8533,6 +8533,7 @@ spec:
UpdatePriority determines the order in which pods with different roles are updated.
Pods are sorted by this priority (higher numbers = higher priority) and updated accordingly.
Roles with the highest priority will be updated last.
The default priority is 0.


For example:
Expand Down
7 changes: 4 additions & 3 deletions deploy/helm/crds/apps.kubeblocks.io_componentdefinitions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8472,8 +8472,8 @@ spec:

This field is immutable.
items:
description: ReplicaRole represents a role that can be assumed by
a component instance.
description: ReplicaRole represents a role that can be assigned
to a component instance, defining its behavior and responsibilities.
properties:
name:
description: |-
Expand All @@ -8491,7 +8491,7 @@ spec:
maxLength: 32
pattern: ^.*[^\s]+.*$
type: string
participatesInQuorum:
participatesInQuorum bool:
default: false
description: |-
ParticipatesInQuorum indicates if pods with this role are counted when determining quorum.
Expand Down Expand Up @@ -8533,6 +8533,7 @@ spec:
UpdatePriority determines the order in which pods with different roles are updated.
Pods are sorted by this priority (higher numbers = higher priority) and updated accordingly.
Roles with the highest priority will be updated last.
The default priority is 0.


For example:
Expand Down

0 comments on commit b18c91c

Please sign in to comment.