Skip to content

Commit 370e09b

Browse files
authored
chore: replace the member status of ITS with instance status (#9719)
1 parent 994d952 commit 370e09b

File tree

16 files changed

+156
-427
lines changed

16 files changed

+156
-427
lines changed

apis/workloads/v1/instanceset_types.go

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,6 @@ type InstanceSetStatus struct {
343343
// +optional
344344
ReadyInitReplicas int32 `json:"readyInitReplicas,omitempty"`
345345

346-
// Provides the status of each member in the cluster.
347-
//
348-
// +optional
349-
MembersStatus []MemberStatus `json:"membersStatus,omitempty"`
350-
351346
// Provides the status of each instance in the ITS.
352347
//
353348
// +optional
@@ -533,25 +528,17 @@ type ConfigTemplate struct {
533528
Parameters map[string]string `json:"parameters,omitempty"`
534529
}
535530

536-
type MemberStatus struct {
531+
type InstanceStatus struct {
537532
// Represents the name of the pod.
538533
//
539534
// +kubebuilder:validation:Required
540535
// +kubebuilder:default=Unknown
541536
PodName string `json:"podName"`
542537

543-
// Defines the role of the replica in the cluster.
538+
// Represents the role of the instance observed.
544539
//
545540
// +optional
546-
ReplicaRole *ReplicaRole `json:"role,omitempty"`
547-
}
548-
549-
type InstanceStatus struct {
550-
// Represents the name of the pod.
551-
//
552-
// +kubebuilder:validation:Required
553-
// +kubebuilder:default=Unknown
554-
PodName string `json:"podName"`
541+
Role string `json:"role,omitempty"`
555542

556543
// The status of configs.
557544
//
@@ -675,17 +662,25 @@ func (r *InstanceSet) IsInstancesReady() bool {
675662

676663
// IsInstanceSetReady gives InstanceSet level 'ready' state:
677664
// 1. all instances are available
678-
// 2. and all members have role set (if they are role-ful)
665+
// 2. and all instances have role set (if they are role-ful)
679666
func (r *InstanceSet) IsInstanceSetReady() bool {
680667
instancesReady := r.IsInstancesReady()
681668
if !instancesReady {
682669
return false
683670
}
671+
return r.IsRoleProbeDone()
672+
}
684673

685-
// check whether role probe has done
674+
func (r *InstanceSet) IsRoleProbeDone() bool {
675+
replicas := int(*r.Spec.Replicas)
686676
if len(r.Spec.Roles) == 0 {
687-
return true
677+
replicas = 0
678+
}
679+
cnt := 0
680+
for _, inst := range r.Status.InstanceStatus {
681+
if len(inst.Role) > 0 {
682+
cnt++
683+
}
688684
}
689-
membersStatus := r.Status.MembersStatus
690-
return len(membersStatus) == int(*r.Spec.Replicas)
685+
return cnt == replicas
691686
}

apis/workloads/v1/zz_generated.deepcopy.go

Lines changed: 0 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/workloads.kubeblocks.io_instancesets.yaml

Lines changed: 2 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -11295,76 +11295,9 @@ spec:
1129511295
default: Unknown
1129611296
description: Represents the name of the pod.
1129711297
type: string
11298-
required:
11299-
- podName
11300-
type: object
11301-
type: array
11302-
membersStatus:
11303-
description: Provides the status of each member in the cluster.
11304-
items:
11305-
properties:
11306-
podName:
11307-
default: Unknown
11308-
description: Represents the name of the pod.
11309-
type: string
1131011298
role:
11311-
description: Defines the role of the replica in the cluster.
11312-
properties:
11313-
name:
11314-
description: |-
11315-
Name defines the role's unique identifier. This value is used to set the "apps.kubeblocks.io/role" label
11316-
on the corresponding object to identify its role.
11317-
11318-
11319-
For example, common role names include:
11320-
- "leader": The primary/master instance that handles write operations
11321-
- "follower": Secondary/replica instances that replicate data from the leader
11322-
- "learner": Read-only instances that don't participate in elections
11323-
11324-
11325-
This field is immutable once set.
11326-
maxLength: 32
11327-
pattern: ^.*[^\s]+.*$
11328-
type: string
11329-
participatesInQuorum:
11330-
default: false
11331-
description: |-
11332-
ParticipatesInQuorum indicates if pods with this role are counted when determining quorum.
11333-
This affects update strategies that need to maintain quorum for availability. Roles participate
11334-
in quorum should have higher update priority than roles do not participate in quorum.
11335-
The default value is false.
11336-
11337-
11338-
For example, in a 5-pod component where:
11339-
- 2 learner pods (participatesInQuorum=false)
11340-
- 2 follower pods (participatesInQuorum=true)
11341-
- 1 leader pod (participatesInQuorum=true)
11342-
The quorum size would be 3 (based on the 3 participating pods), allowing parallel updates
11343-
of 2 learners and 1 follower while maintaining quorum.
11344-
11345-
11346-
This field is immutable once set.
11347-
type: boolean
11348-
updatePriority:
11349-
default: 0
11350-
description: |-
11351-
UpdatePriority determines the order in which pods with different roles are updated.
11352-
Pods are sorted by this priority (higher numbers = higher priority) and updated accordingly.
11353-
Roles with the highest priority will be updated last.
11354-
The default priority is 0.
11355-
11356-
11357-
For example:
11358-
- Leader role may have priority 2 (updated last)
11359-
- Follower role may have priority 1 (updated before leader)
11360-
- Learner role may have priority 0 (updated first)
11361-
11362-
11363-
This field is immutable once set.
11364-
type: integer
11365-
required:
11366-
- name
11367-
type: object
11299+
description: Represents the role of the instance observed.
11300+
type: string
1136811301
required:
1136911302
- podName
1137011303
type: object

controllers/apps/component/transformer_component_status.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,7 @@ func (t *componentStatusTransformer) hasFailedPod() (bool, appsv1alpha1.Componen
299299
}
300300

301301
// all instances are in Ready condition, check role probe
302-
if len(t.runningITS.Spec.Roles) == 0 {
303-
return false, nil
304-
}
305-
if len(t.runningITS.Status.MembersStatus) == int(t.runningITS.Status.Replicas) {
302+
if t.runningITS.IsRoleProbeDone() {
306303
return false, nil
307304
}
308305
probeTimeoutDuration := time.Duration(defaultRoleProbeTimeoutAfterPodsReady) * time.Second
@@ -428,9 +425,9 @@ func (t *componentStatusTransformer) availableWithRole(transCtx *componentTransf
428425
if its == nil {
429426
return metav1.ConditionFalse, "Unavailable", "the workload is not present"
430427
}
431-
for _, member := range its.Status.MembersStatus {
432-
if member.ReplicaRole != nil {
433-
if strings.EqualFold(member.ReplicaRole.Name, *policy.WithRole) {
428+
for _, inst := range its.Status.InstanceStatus {
429+
if len(inst.Role) > 0 {
430+
if strings.EqualFold(inst.Role, *policy.WithRole) {
434431
return metav1.ConditionTrue, "Available", fmt.Sprintf("the role %s is present", *policy.WithRole)
435432
}
436433
}

controllers/workloads/instanceset_controller_2_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ var _ = Describe("InstanceSet Controller 2", func() {
142142
})).Should(Succeed())
143143
})
144144

145-
It("member status", func() {
145+
It("instance status", func() {
146146
createITSObj(itsName, func(f *testapps.MockInstanceSetFactory) {
147147
f.SetRoles([]workloads.ReplicaRole{
148148
{
@@ -176,9 +176,9 @@ var _ = Describe("InstanceSet Controller 2", func() {
176176
By("check its ready")
177177
Eventually(testapps.CheckObj(&testCtx, itsKey, func(g Gomega, its *workloads.InstanceSet) {
178178
g.Expect(its.IsInstanceSetReady()).Should(BeTrue())
179-
g.Expect(len(its.Status.MembersStatus)).Should(Equal(int(replicas)))
179+
g.Expect(len(its.Status.InstanceStatus)).Should(Equal(int(replicas)))
180180
for i := int32(0); i < replicas; i++ {
181-
g.Expect(its.Status.MembersStatus[i].ReplicaRole.Name).Should(Equal("leader"))
181+
g.Expect(its.Status.InstanceStatus[i].Role).Should(Equal("leader"))
182182
}
183183
})).Should(Succeed())
184184
})

deploy/helm/crds/workloads.kubeblocks.io_instancesets.yaml

Lines changed: 2 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -11295,76 +11295,9 @@ spec:
1129511295
default: Unknown
1129611296
description: Represents the name of the pod.
1129711297
type: string
11298-
required:
11299-
- podName
11300-
type: object
11301-
type: array
11302-
membersStatus:
11303-
description: Provides the status of each member in the cluster.
11304-
items:
11305-
properties:
11306-
podName:
11307-
default: Unknown
11308-
description: Represents the name of the pod.
11309-
type: string
1131011298
role:
11311-
description: Defines the role of the replica in the cluster.
11312-
properties:
11313-
name:
11314-
description: |-
11315-
Name defines the role's unique identifier. This value is used to set the "apps.kubeblocks.io/role" label
11316-
on the corresponding object to identify its role.
11317-
11318-
11319-
For example, common role names include:
11320-
- "leader": The primary/master instance that handles write operations
11321-
- "follower": Secondary/replica instances that replicate data from the leader
11322-
- "learner": Read-only instances that don't participate in elections
11323-
11324-
11325-
This field is immutable once set.
11326-
maxLength: 32
11327-
pattern: ^.*[^\s]+.*$
11328-
type: string
11329-
participatesInQuorum:
11330-
default: false
11331-
description: |-
11332-
ParticipatesInQuorum indicates if pods with this role are counted when determining quorum.
11333-
This affects update strategies that need to maintain quorum for availability. Roles participate
11334-
in quorum should have higher update priority than roles do not participate in quorum.
11335-
The default value is false.
11336-
11337-
11338-
For example, in a 5-pod component where:
11339-
- 2 learner pods (participatesInQuorum=false)
11340-
- 2 follower pods (participatesInQuorum=true)
11341-
- 1 leader pod (participatesInQuorum=true)
11342-
The quorum size would be 3 (based on the 3 participating pods), allowing parallel updates
11343-
of 2 learners and 1 follower while maintaining quorum.
11344-
11345-
11346-
This field is immutable once set.
11347-
type: boolean
11348-
updatePriority:
11349-
default: 0
11350-
description: |-
11351-
UpdatePriority determines the order in which pods with different roles are updated.
11352-
Pods are sorted by this priority (higher numbers = higher priority) and updated accordingly.
11353-
Roles with the highest priority will be updated last.
11354-
The default priority is 0.
11355-
11356-
11357-
For example:
11358-
- Leader role may have priority 2 (updated last)
11359-
- Follower role may have priority 1 (updated before leader)
11360-
- Learner role may have priority 0 (updated first)
11361-
11362-
11363-
This field is immutable once set.
11364-
type: integer
11365-
required:
11366-
- name
11367-
type: object
11299+
description: Represents the role of the instance observed.
11300+
type: string
1136811301
required:
1136911302
- podName
1137011303
type: object

0 commit comments

Comments
 (0)