Skip to content

Commit 36a5a0f

Browse files
committed
update
1 parent 7859617 commit 36a5a0f

23 files changed

+2227
-236
lines changed

apis/workloads/v1/instance_types.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,25 @@ type InstanceStatus2 struct {
183183
// +optional
184184
Role string `json:"role,omitempty"`
185185

186+
// Represents whether the instance is provisioned.
187+
//
188+
// +optional
189+
Provisioned bool `json:"provisioned,omitempty"`
190+
191+
// Represents whether the instance data is loaded.
192+
//
193+
// +optional
194+
DataLoaded *bool `json:"dataLoaded,omitempty"`
195+
196+
// Represents whether the instance is joined the cluster.
197+
//
198+
// +optional
199+
MemberJoined *bool `json:"memberJoined,omitempty"`
200+
186201
// Represents whether the instance is in volume expansion.
187202
//
188203
// +optional
189-
VolumeExpansion bool `json:"volumeExpansion,omitempty"`
204+
InVolumeExpansion bool `json:"inVolumeExpansion,omitempty"`
190205
}
191206

192207
type InstanceAssistantObject struct {

apis/workloads/v1/instanceset_types.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,11 @@ type LifecycleActions struct {
514514
// +optional
515515
MemberLeave *Action `json:"memberLeave,omitempty"`
516516

517+
// Defines the procedure for importing data into a replica.
518+
//
519+
// +optional
520+
DataLoad *Action `json:"dataLoad,omitempty"`
521+
517522
// Defines the procedure that update a replica with new configuration.
518523
//
519524
// +optional
@@ -562,15 +567,25 @@ type InstanceStatus struct {
562567
// +optional
563568
Configs []InstanceConfigStatus `json:"configs,omitempty"`
564569

570+
// Represents whether the instance is provisioned.
571+
//
572+
// +optional
573+
Provisioned bool `json:"provisioned,omitempty"`
574+
575+
// Represents whether the instance data is loaded.
576+
//
577+
// +optional
578+
DataLoaded *bool `json:"dataLoaded,omitempty"`
579+
565580
// Represents whether the instance is joined the cluster.
566581
//
567582
// +optional
568-
Joined *bool `json:"joined,omitempty"`
583+
MemberJoined *bool `json:"memberJoined,omitempty"`
569584

570585
// Represents whether the instance is in volume expansion.
571586
//
572587
// +optional
573-
VolumeExpansion bool `json:"volumeExpansion,omitempty"`
588+
InVolumeExpansion bool `json:"inVolumeExpansion,omitempty"`
574589
}
575590

576591
type InstanceConfigStatus struct {

apis/workloads/v1/zz_generated.deepcopy.go

Lines changed: 22 additions & 2 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_instances.yaml

Lines changed: 441 additions & 3 deletions
Large diffs are not rendered by default.

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

Lines changed: 439 additions & 4 deletions
Large diffs are not rendered by default.

controllers/apps/component/transformer_component_status.go

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"k8s.io/apimachinery/pkg/api/meta"
3131
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3232
"k8s.io/apimachinery/pkg/util/sets"
33+
"k8s.io/utils/ptr"
3334
"sigs.k8s.io/controller-runtime/pkg/client"
3435

3536
appsv1 "github.com/apecloud/kubeblocks/apis/apps/v1"
@@ -130,18 +131,15 @@ func (t *componentStatusTransformer) reconcileStatus(transCtx *componentTransfor
130131
// check if the component has failed pod
131132
hasFailedPod, messages := t.hasFailedPod()
132133

133-
// check if the component scale out failed
134-
hasRunningScaleOut, hasFailedScaleOut, err := t.hasScaleOutRunning(transCtx)
135-
if err != nil {
136-
return err
137-
}
134+
// check if the component has scale out running
135+
hasRunningScaleOut := t.hasScaleOutRunning()
138136

139137
// check if the volume expansion is running
140138
hasRunningVolumeExpansion := t.hasVolumeExpansionRunning()
141139

142140
// check if the component has failure
143141
hasFailure := func() bool {
144-
return hasFailedPod || hasFailedScaleOut
142+
return hasFailedPod
145143
}()
146144

147145
// check if the component is in creating phase
@@ -219,35 +217,19 @@ func (t *componentStatusTransformer) isInstanceSetRunning() bool {
219217
return t.runningITS.IsInstanceSetReady()
220218
}
221219

222-
// hasScaleOutRunning checks if the scale out is running.
223-
func (t *componentStatusTransformer) hasScaleOutRunning(transCtx *componentTransformContext) (running bool, failed bool, err error) {
220+
func (t *componentStatusTransformer) hasScaleOutRunning() bool {
224221
if t.runningITS == nil || t.runningITS.Spec.Replicas == nil {
225-
return false, false, nil
222+
return false
226223
}
227-
228-
replicas, err := component.GetReplicasStatusFunc(t.protoITS, func(status component.ReplicaStatus) bool {
229-
return status.DataLoaded != nil && !*status.DataLoaded ||
230-
status.MemberJoined != nil && !*status.MemberJoined
224+
return slices.ContainsFunc(t.runningITS.Status.InstanceStatus, func(inst workloads.InstanceStatus) bool {
225+
return !ptr.Deref(inst.DataLoaded, true) || !ptr.Deref(inst.MemberJoined, true)
231226
})
232-
if err != nil {
233-
return false, false, err
234-
}
235-
if len(replicas) == 0 {
236-
return false, false, nil
237-
}
238-
239-
// TODO: scale-out failed
240-
241-
return true, false, nil
242227
}
243228

244229
func (t *componentStatusTransformer) hasVolumeExpansionRunning() bool {
245-
for _, inst := range t.runningITS.Status.InstanceStatus {
246-
if inst.VolumeExpansion {
247-
return true
248-
}
249-
}
250-
return false
230+
return slices.ContainsFunc(t.runningITS.Status.InstanceStatus, func(inst workloads.InstanceStatus) bool {
231+
return inst.InVolumeExpansion
232+
})
251233
}
252234

253235
// hasFailedPod checks if the instance set has failed pod.

controllers/apps/component/transformer_component_workload_ops.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ type componentWorkloadOps struct {
5050
synthesizeComp *component.SynthesizedComponent
5151
dag *graph.DAG
5252

53-
// runningITS is a snapshot of the InstanceSet that is already running
54-
runningITS *workloads.InstanceSet
55-
// protoITS is the InstanceSet object that is rebuilt from scratch during each reconcile process
53+
runningITS *workloads.InstanceSet
5654
protoITS *workloads.InstanceSet
5755
desiredCompPodNameSet sets.Set[string]
5856
runningItsPodNameSet sets.Set[string]
@@ -93,7 +91,7 @@ func (r *componentWorkloadOps) horizontalScale() error {
9391
in = r.runningItsPodNameSet.Difference(r.desiredCompPodNameSet)
9492
out = r.desiredCompPodNameSet.Difference(r.runningItsPodNameSet)
9593
)
96-
if err := r.buildDataReplicationTask(); err != nil {
94+
if err := r.dataReplicationTask(); err != nil {
9795
return err
9896
}
9997
if in.Len() != 0 || out.Len() != 0 {
@@ -106,7 +104,7 @@ func (r *componentWorkloadOps) horizontalScale() error {
106104
return nil
107105
}
108106

109-
func (r *componentWorkloadOps) buildDataReplicationTask() error {
107+
func (r *componentWorkloadOps) dataReplicationTask() error {
110108
_, hasDataActionDefined := hasMemberJoinNDataActionDefined(r.synthesizeComp.LifecycleActions)
111109
if !hasDataActionDefined {
112110
return nil
@@ -119,11 +117,11 @@ func (r *componentWorkloadOps) buildDataReplicationTask() error {
119117
}
120118

121119
// replicas in provisioning that the data has not been loaded
122-
provisioningReplicas, err := component.GetReplicasStatusFunc(r.protoITS, func(s component.ReplicaStatus) bool {
123-
return s.DataLoaded != nil && !*s.DataLoaded
124-
})
125-
if err != nil {
126-
return err
120+
var provisioningReplicas []string
121+
for _, replica := range r.runningITS.Status.InstanceStatus {
122+
if replica.DataLoaded != nil && !*replica.DataLoaded {
123+
provisioningReplicas = append(provisioningReplicas, replica.PodName)
124+
}
127125
}
128126

129127
// choose the source replica

controllers/workloads/instanceset_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ func (r *InstanceSetReconciler) Reconcile(ctx context.Context, req ctrl.Request)
8484
Do(instanceset.NewDeletionReconciler()).
8585
Do(instanceset.NewValidationReconciler()).
8686
Do(instanceset.NewStatusReconciler()).
87+
Do(instanceset.NewMembershipReconciler()).
8788
Do(instanceset.NewRevisionUpdateReconciler()).
8889
Do(instanceset.NewAssistantObjectReconciler()).
89-
Do(instanceset.NewReplicasAlignmentReconciler()).
90+
Do(instanceset.NewInstanceAlignmentReconciler()).
9091
Do(instanceset.NewUpdateReconciler()).
9192
Commit()
9293

0 commit comments

Comments
 (0)