Skip to content

Commit 6ec884d

Browse files
committed
init
1 parent fcd0f17 commit 6ec884d

32 files changed

Lines changed: 715 additions & 345 deletions

apis/workloads/v1/instanceset_types.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,32 @@ type InstanceSetSpec struct {
9191
// For example, if Ordinals is {ranges: [{start: 0, end: 1}], discrete: [7]},
9292
// then the instance names generated under the default template would be
9393
// $(cluster.name)-$(component.name)-0、$(cluster.name)-$(component.name)-1 and $(cluster.name)-$(component.name)-7
94+
//
95+
// +kubebuilder:deprecatedversion:warning="This field has been deprecated since 1.1.0"
96+
// +optional
9497
DefaultTemplateOrdinals kbappsv1.Ordinals `json:"defaultTemplateOrdinals,omitempty"`
9598

99+
// Specifies the desired Ordinals.
100+
// The Ordinals used to specify the ordinal of the instance (pod) names to be generated under the InstanceSet.
101+
// If Ordinals are defined, their number must be equal to or more than the corresponding replicas.
102+
//
103+
// +optional
104+
Ordinals Ordinals `json:"ordinals,omitempty"`
105+
106+
// AssignedOrdinals is the set of ordinals assigned to the current replicas.
107+
//
108+
// IMPORTANT: This field is managed automatically by the InstanceSet controller.
109+
// Users should NOT manually modify this field.
110+
//
111+
// This field represents the authoritative set of ordinal identifiers currently in use by the workload.
112+
// It enables support for non-contiguous ordinals, allowing any instance to be terminated without affecting others.
113+
//
114+
// The controller uses this list to maintain identity consistency and to decide which specific ordinal
115+
// to allocate next during scaling up, or which identity is preserved during a restart.
116+
//
117+
// +optional
118+
AssignedOrdinals Ordinals `json:"assignedOrdinals,omitempty"`
119+
96120
// Defines the minimum number of seconds a newly created pod should be ready
97121
// without any of its container crashing to be considered available.
98122
// Defaults to 0, meaning the pod will be considered available as soon as it is ready.
@@ -236,6 +260,12 @@ type InstanceSetSpec struct {
236260
// +optional
237261
Paused bool `json:"paused,omitempty"`
238262

263+
// Stop the InstanceSet.
264+
// If set, all the computing resources will be released.
265+
//
266+
// +optional
267+
Stop *bool `json:"stop,omitempty"`
268+
239269
// Describe the configs to be reconfigured.
240270
//
241271
// +optional
@@ -402,8 +432,24 @@ type InstanceTemplate struct {
402432
// then the instance names generated under this InstanceTemplate would be
403433
// $(cluster.name)-$(component.name)-$(template.name)-0、$(cluster.name)-$(component.name)-$(template.name)-1 and
404434
// $(cluster.name)-$(component.name)-$(template.name)-7
435+
//
436+
// +optional
405437
Ordinals Ordinals `json:"ordinals,omitempty"`
406438

439+
// AssignedOrdinals is the set of ordinals assigned to the current replicas of this InstanceTemplate.
440+
//
441+
// IMPORTANT: This field is managed automatically by the InstanceSet controller.
442+
// Users should NOT manually modify this field.
443+
//
444+
// This field represents the authoritative set of ordinal identifiers currently in use by the workload.
445+
// It enables support for non-contiguous ordinals, allowing any instance to be terminated without affecting others.
446+
//
447+
// The controller uses this list to maintain identity consistency and to decide which specific ordinal
448+
// to allocate next during scaling up, or which identity is preserved during a restart.
449+
//
450+
// +optional
451+
AssignedOrdinals Ordinals `json:"assignedOrdinals,omitempty"`
452+
407453
// Specifies a map of key-value pairs to be merged into the Pod's existing annotations.
408454
// Existing keys will have their values overwritten, while new keys will be added to the annotations.
409455
//

apis/workloads/v1/zz_generated.deepcopy.go

Lines changed: 8 additions & 0 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: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,45 @@ spec:
6565
description: Defines the desired state of the state machine. It includes
6666
the configuration details for the state machine.
6767
properties:
68+
assignedOrdinals:
69+
description: |-
70+
AssignedOrdinals is the set of ordinals assigned to the current replicas.
71+
72+
73+
IMPORTANT: This field is managed automatically by the InstanceSet controller.
74+
Users should NOT manually modify this field.
75+
76+
77+
This field represents the authoritative set of ordinal identifiers currently in use by the workload.
78+
It enables support for non-contiguous ordinals, allowing any instance to be terminated without affecting others.
79+
80+
81+
The controller uses this list to maintain identity consistency and to decide which specific ordinal
82+
to allocate next during scaling up, or which identity is preserved during a restart.
83+
properties:
84+
discrete:
85+
items:
86+
format: int32
87+
type: integer
88+
type: array
89+
ranges:
90+
items:
91+
description: |-
92+
Range represents a range with a start and an end value. Both start and end are included.
93+
It is used to define a continuous segment.
94+
properties:
95+
end:
96+
format: int32
97+
type: integer
98+
start:
99+
format: int32
100+
type: integer
101+
required:
102+
- end
103+
- start
104+
type: object
105+
type: array
106+
type: object
68107
configs:
69108
description: Describe the configs to be reconfigured.
70109
items:
@@ -727,6 +766,45 @@ spec:
727766
Specifies a map of key-value pairs to be merged into the Pod's existing annotations.
728767
Existing keys will have their values overwritten, while new keys will be added to the annotations.
729768
type: object
769+
assignedOrdinals:
770+
description: |-
771+
AssignedOrdinals is the set of ordinals assigned to the current replicas of this InstanceTemplate.
772+
773+
774+
IMPORTANT: This field is managed automatically by the InstanceSet controller.
775+
Users should NOT manually modify this field.
776+
777+
778+
This field represents the authoritative set of ordinal identifiers currently in use by the workload.
779+
It enables support for non-contiguous ordinals, allowing any instance to be terminated without affecting others.
780+
781+
782+
The controller uses this list to maintain identity consistency and to decide which specific ordinal
783+
to allocate next during scaling up, or which identity is preserved during a restart.
784+
properties:
785+
discrete:
786+
items:
787+
format: int32
788+
type: integer
789+
type: array
790+
ranges:
791+
items:
792+
description: |-
793+
Range represents a range with a start and an end value. Both start and end are included.
794+
It is used to define a continuous segment.
795+
properties:
796+
end:
797+
format: int32
798+
type: integer
799+
start:
800+
format: int32
801+
type: integer
802+
required:
803+
- end
804+
- start
805+
type: object
806+
type: array
807+
type: object
730808
env:
731809
description: |-
732810
Defines Env to override.
@@ -3482,6 +3560,35 @@ spec:
34823560
items:
34833561
type: string
34843562
type: array
3563+
ordinals:
3564+
description: |-
3565+
Specifies the desired Ordinals.
3566+
The Ordinals used to specify the ordinal of the instance (pod) names to be generated under the InstanceSet.
3567+
If Ordinals are defined, their number must be equal to or more than the corresponding replicas.
3568+
properties:
3569+
discrete:
3570+
items:
3571+
format: int32
3572+
type: integer
3573+
type: array
3574+
ranges:
3575+
items:
3576+
description: |-
3577+
Range represents a range with a start and an end value. Both start and end are included.
3578+
It is used to define a continuous segment.
3579+
properties:
3580+
end:
3581+
format: int32
3582+
type: integer
3583+
start:
3584+
format: int32
3585+
type: integer
3586+
required:
3587+
- end
3588+
- start
3589+
type: object
3590+
type: array
3591+
type: object
34853592
parallelPodManagementConcurrency:
34863593
anyOf:
34873594
- type: integer
@@ -3663,6 +3770,11 @@ spec:
36633770
type: object
36643771
type: object
36653772
x-kubernetes-map-type: atomic
3773+
stop:
3774+
description: |-
3775+
Stop the InstanceSet.
3776+
If set, all the computing resources will be released.
3777+
type: boolean
36663778
template:
36673779
description: PodTemplateSpec describes the data a pod should have
36683780
when created from a template

controllers/apps/component/transformer_component_service.go

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,7 @@ var _ graph.Transformer = &componentServiceTransformer{}
5656

5757
func (t *componentServiceTransformer) Transform(ctx graph.TransformContext, dag *graph.DAG) error {
5858
transCtx, _ := ctx.(*componentTransformContext)
59-
protoITS, err := factory.BuildInstanceSet(transCtx.SynthesizeComponent, transCtx.CompDef)
60-
if err != nil {
61-
return err
62-
}
63-
// if there exists an instanceset, use its status field to replace protoITS', so that podNameBuilder can work correctly
64-
if transCtx.RunningWorkload != nil {
65-
runningITS := transCtx.RunningWorkload.(*workloadsv1.InstanceSet)
66-
if runningITS != nil {
67-
protoITS.Status = runningITS.Status
68-
}
69-
}
59+
7060
if isCompDeleting(transCtx.ComponentOrig) {
7161
return nil
7262
}
@@ -75,6 +65,15 @@ func (t *componentServiceTransformer) Transform(ctx graph.TransformContext, dag
7565
return nil
7666
}
7767

68+
var runningITS *workloadsv1.InstanceSet
69+
if transCtx.RunningWorkload != nil {
70+
runningITS = transCtx.RunningWorkload.(*workloadsv1.InstanceSet)
71+
}
72+
protoITS, err := factory.BuildInstanceSet(transCtx.SynthesizeComponent, transCtx.CompDef)
73+
if err != nil {
74+
return err
75+
}
76+
7877
synthesizeComp := transCtx.SynthesizeComponent
7978
runningServices, err := t.listOwnedServices(transCtx.Context, transCtx.Client, transCtx.Component, synthesizeComp)
8079
if err != nil {
@@ -87,7 +86,7 @@ func (t *componentServiceTransformer) Transform(ctx graph.TransformContext, dag
8786
if t.skipDefaultHeadlessSvc(synthesizeComp, &service) {
8887
continue
8988
}
90-
services, err := t.buildCompService(transCtx.Component, synthesizeComp, &service, protoITS)
89+
services, err := t.buildCompService(transCtx.Component, synthesizeComp, &service, runningITS, protoITS)
9190
if err != nil {
9291
return err
9392
}
@@ -125,13 +124,13 @@ func (t *componentServiceTransformer) listOwnedServices(ctx context.Context, cli
125124
}
126125

127126
func (t *componentServiceTransformer) buildCompService(comp *appsv1.Component,
128-
synthesizeComp *component.SynthesizedComponent, service *appsv1.ComponentService, protoITS *workloadsv1.InstanceSet) ([]*corev1.Service, error) {
127+
synthesizeComp *component.SynthesizedComponent, service *appsv1.ComponentService, runningITS, protoITS *workloadsv1.InstanceSet) ([]*corev1.Service, error) {
129128
if service.DisableAutoProvision != nil && *service.DisableAutoProvision {
130129
return nil, nil
131130
}
132131

133132
if t.isPodService(service) {
134-
return t.buildPodService(comp, synthesizeComp, service, protoITS)
133+
return t.buildPodService(comp, synthesizeComp, service, runningITS, protoITS)
135134
}
136135
return t.buildServices(comp, synthesizeComp, []*appsv1.ComponentService{service})
137136
}
@@ -141,8 +140,8 @@ func (t *componentServiceTransformer) isPodService(service *appsv1.ComponentServ
141140
}
142141

143142
func (t *componentServiceTransformer) buildPodService(comp *appsv1.Component,
144-
synthesizeComp *component.SynthesizedComponent, service *appsv1.ComponentService, protoITS *workloadsv1.InstanceSet) ([]*corev1.Service, error) {
145-
pods, err := t.podsNameNSuffix(synthesizeComp, protoITS)
143+
synthesizeComp *component.SynthesizedComponent, service *appsv1.ComponentService, runningITS, protoITS *workloadsv1.InstanceSet) ([]*corev1.Service, error) {
144+
pods, err := t.podsNameNSuffix(synthesizeComp, runningITS, protoITS)
146145
if err != nil {
147146
return nil, err
148147
}
@@ -165,8 +164,8 @@ func (t *componentServiceTransformer) buildPodService(comp *appsv1.Component,
165164
return t.buildServices(comp, synthesizeComp, services)
166165
}
167166

168-
func (t *componentServiceTransformer) podsNameNSuffix(synthesizeComp *component.SynthesizedComponent, protoITS *workloadsv1.InstanceSet) (map[string]string, error) {
169-
podNames, err := component.GeneratePodNamesByITS(protoITS)
167+
func (t *componentServiceTransformer) podsNameNSuffix(synthesizeComp *component.SynthesizedComponent, runningITS, protoITS *workloadsv1.InstanceSet) (map[string]string, error) {
168+
podNames, err := component.GenerateDesiredPodNamesByITS(runningITS, protoITS)
170169
if err != nil {
171170
return nil, err
172171
}

0 commit comments

Comments
 (0)