Skip to content

Commit fc63779

Browse files
leon-apeapecloud-bot
authored andcommitted
chore: support stopping clusters with flat discrete ordinals (#10002)
(cherry picked from commit 544c4a0)
1 parent 0368eb0 commit fc63779

34 files changed

+748
-605
lines changed

apis/workloads/v1/instanceset_types.go

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,12 @@ type InstanceSetSpec struct {
8484
// +optional
8585
Replicas *int32 `json:"replicas,omitempty"`
8686

87-
// Specifies the desired Ordinals of the default template.
88-
// The Ordinals used to specify the ordinal of the instance (pod) names to be generated under the default template.
87+
// Specifies the desired Ordinals.
88+
// The Ordinals used to specify the ordinal of the instance (pod) names to be generated under the InstanceSet.
8989
// If Ordinals are defined, their number must be equal to or more than the corresponding replicas.
9090
//
91-
// For example, if Ordinals is {ranges: [{start: 0, end: 1}], discrete: [7]},
92-
// then the instance names generated under the default template would be
93-
// $(cluster.name)-$(component.name)-0、$(cluster.name)-$(component.name)-1 and $(cluster.name)-$(component.name)-7
94-
DefaultTemplateOrdinals kbappsv1.Ordinals `json:"defaultTemplateOrdinals,omitempty"`
91+
// +optional
92+
Ordinals Ordinals `json:"ordinals,omitempty"`
9593

9694
// Defines the minimum number of seconds a newly created pod should be ready
9795
// without any of its container crashing to be considered available.
@@ -236,6 +234,12 @@ type InstanceSetSpec struct {
236234
// +optional
237235
Paused bool `json:"paused,omitempty"`
238236

237+
// Stop the InstanceSet.
238+
// If set, all the computing resources will be released.
239+
//
240+
// +optional
241+
Stop *bool `json:"stop,omitempty"`
242+
239243
// Describe the configs to be reconfigured.
240244
//
241245
// +optional
@@ -283,11 +287,6 @@ type InstanceSetStatus struct {
283287
// replicas is the number of instances created by the InstanceSet controller.
284288
Replicas int32 `json:"replicas"`
285289

286-
// Ordinals is the ordinals used by the instances of the InstanceSet except the template instances.
287-
//
288-
// +optional
289-
Ordinals []int32 `json:"ordinals,omitempty"`
290-
291290
// readyReplicas is the number of instances created for this InstanceSet with a Ready Condition.
292291
//
293292
// +optional
@@ -353,9 +352,21 @@ type InstanceSetStatus struct {
353352
// +optional
354353
UpdateRevisions map[string]string `json:"updateRevisions,omitempty"`
355354

356-
// TemplatesStatus represents status of each instance generated by InstanceTemplates
355+
// TemplatesStatus represents status of each instance generated by InstanceTemplates.
356+
//
357357
// +optional
358358
TemplatesStatus []InstanceTemplateStatus `json:"templatesStatus,omitempty"`
359+
360+
// AssignedOrdinals is the ordinals assigned to the workload instances.
361+
//
362+
// This field represents the authoritative set of ordinal identifiers currently in use by the workload.
363+
// It enables support for non-contiguous ordinals, allowing any instance to be terminated without affecting others.
364+
//
365+
// The controller uses this to maintain identity consistency and to decide which specific ordinal
366+
// to allocate next during scaling up, or which identity is preserved during a restart.
367+
//
368+
// +optional
369+
AssignedOrdinals map[string]Ordinals `json:"assignedOrdinals,omitempty"`
359370
}
360371

361372
// PersistentVolumeClaimRetentionPolicy describes the policy used for PVCs created from the VolumeClaimTemplates.
@@ -402,6 +413,8 @@ type InstanceTemplate struct {
402413
// then the instance names generated under this InstanceTemplate would be
403414
// $(cluster.name)-$(component.name)-$(template.name)-0、$(cluster.name)-$(component.name)-$(template.name)-1 and
404415
// $(cluster.name)-$(component.name)-$(template.name)-7
416+
//
417+
// +optional
405418
Ordinals Ordinals `json:"ordinals,omitempty"`
406419

407420
// Specifies a map of key-value pairs to be merged into the Pod's existing annotations.
@@ -579,10 +592,6 @@ type InstanceTemplateStatus struct {
579592
// +optional
580593
Replicas int32 `json:"replicas,omitempty"`
581594

582-
// Ordinals is the ordinals used by the instances of the InstanceTemplate.
583-
// +optional
584-
Ordinals []int32 `json:"ordinals,omitempty"`
585-
586595
// ReadyReplicas is the number of Pods that have a Ready Condition.
587596
// +optional
588597
ReadyReplicas int32 `json:"readyReplicas,omitempty"`

apis/workloads/v1/zz_generated.deepcopy.go

Lines changed: 13 additions & 13 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: 74 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -527,40 +527,6 @@ spec:
527527
- name
528528
type: object
529529
type: array
530-
defaultTemplateOrdinals:
531-
description: |-
532-
Specifies the desired Ordinals of the default template.
533-
The Ordinals used to specify the ordinal of the instance (pod) names to be generated under the default template.
534-
If Ordinals are defined, their number must be equal to or more than the corresponding replicas.
535-
536-
537-
For example, if Ordinals is {ranges: [{start: 0, end: 1}], discrete: [7]},
538-
then the instance names generated under the default template would be
539-
$(cluster.name)-$(component.name)-0、$(cluster.name)-$(component.name)-1 and $(cluster.name)-$(component.name)-7
540-
properties:
541-
discrete:
542-
items:
543-
format: int32
544-
type: integer
545-
type: array
546-
ranges:
547-
items:
548-
description: |-
549-
Range represents a range with a start and an end value. Both start and end are included.
550-
It is used to define a continuous segment.
551-
properties:
552-
end:
553-
format: int32
554-
type: integer
555-
start:
556-
format: int32
557-
type: integer
558-
required:
559-
- end
560-
- start
561-
type: object
562-
type: array
563-
type: object
564530
disableDefaultHeadlessService:
565531
default: false
566532
description: Specifies whether to create the default headless service.
@@ -3482,6 +3448,35 @@ spec:
34823448
items:
34833449
type: string
34843450
type: array
3451+
ordinals:
3452+
description: |-
3453+
Specifies the desired Ordinals.
3454+
The Ordinals used to specify the ordinal of the instance (pod) names to be generated under the InstanceSet.
3455+
If Ordinals are defined, their number must be equal to or more than the corresponding replicas.
3456+
properties:
3457+
discrete:
3458+
items:
3459+
format: int32
3460+
type: integer
3461+
type: array
3462+
ranges:
3463+
items:
3464+
description: |-
3465+
Range represents a range with a start and an end value. Both start and end are included.
3466+
It is used to define a continuous segment.
3467+
properties:
3468+
end:
3469+
format: int32
3470+
type: integer
3471+
start:
3472+
format: int32
3473+
type: integer
3474+
required:
3475+
- end
3476+
- start
3477+
type: object
3478+
type: array
3479+
type: object
34853480
parallelPodManagementConcurrency:
34863481
anyOf:
34873482
- type: integer
@@ -3663,6 +3658,11 @@ spec:
36633658
type: object
36643659
type: object
36653660
x-kubernetes-map-type: atomic
3661+
stop:
3662+
description: |-
3663+
Stop the InstanceSet.
3664+
If set, all the computing resources will be released.
3665+
type: boolean
36663666
template:
36673667
description: PodTemplateSpec describes the data a pod should have
36683668
when created from a template
@@ -11606,6 +11606,45 @@ spec:
1160611606
description: Represents the current information about the state machine.
1160711607
This data may be out of date.
1160811608
properties:
11609+
assignedOrdinals:
11610+
additionalProperties:
11611+
description: Ordinals represents a combination of continuous segments
11612+
and individual values.
11613+
properties:
11614+
discrete:
11615+
items:
11616+
format: int32
11617+
type: integer
11618+
type: array
11619+
ranges:
11620+
items:
11621+
description: |-
11622+
Range represents a range with a start and an end value. Both start and end are included.
11623+
It is used to define a continuous segment.
11624+
properties:
11625+
end:
11626+
format: int32
11627+
type: integer
11628+
start:
11629+
format: int32
11630+
type: integer
11631+
required:
11632+
- end
11633+
- start
11634+
type: object
11635+
type: array
11636+
type: object
11637+
description: |-
11638+
AssignedOrdinals is the ordinals assigned to the workload instances.
11639+
11640+
11641+
This field represents the authoritative set of ordinal identifiers currently in use by the workload.
11642+
It enables support for non-contiguous ordinals, allowing any instance to be terminated without affecting others.
11643+
11644+
11645+
The controller uses this to maintain identity consistency and to decide which specific ordinal
11646+
to allocate next during scaling up, or which identity is preserved during a restart.
11647+
type: object
1160911648
availableReplicas:
1161011649
description: Total number of available instances (ready for at least
1161111650
minReadySeconds) targeted by this InstanceSet.
@@ -11750,13 +11789,6 @@ spec:
1175011789
InstanceSet's generation, which is updated on mutation by the API Server.
1175111790
format: int64
1175211791
type: integer
11753-
ordinals:
11754-
description: Ordinals is the ordinals used by the instances of the
11755-
InstanceSet except the template instances.
11756-
items:
11757-
format: int32
11758-
type: integer
11759-
type: array
1176011792
readyInitReplicas:
1176111793
description: |-
1176211794
Represents the number of instances that have already reached the InstanceStatus during the cluster initialization stage.
@@ -11775,7 +11807,7 @@ spec:
1177511807
type: integer
1177611808
templatesStatus:
1177711809
description: TemplatesStatus represents status of each instance generated
11778-
by InstanceTemplates
11810+
by InstanceTemplates.
1177911811
items:
1178011812
description: InstanceTemplateStatus aggregates the status of replicas
1178111813
for each InstanceTemplate
@@ -11794,13 +11826,6 @@ spec:
1179411826
name:
1179511827
description: Name, the name of the InstanceTemplate.
1179611828
type: string
11797-
ordinals:
11798-
description: Ordinals is the ordinals used by the instances
11799-
of the InstanceTemplate.
11800-
items:
11801-
format: int32
11802-
type: integer
11803-
type: array
1180411829
readyReplicas:
1180511830
description: ReadyReplicas is the number of Pods that have a
1180611831
Ready Condition.

controllers/apps/component/component_controller_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,6 +1792,7 @@ var _ = Describe("Component Controller", func() {
17921792

17931793
itsKey := compKey
17941794
Eventually(testapps.CheckObj(&testCtx, itsKey, func(g Gomega, its *workloads.InstanceSet) {
1795+
g.Expect(its.Spec.Stop).Should(BeNil())
17951796
g.Expect(*its.Spec.Replicas).To(BeEquivalentTo(1))
17961797
g.Expect(its.Spec.PersistentVolumeClaimRetentionPolicy).ShouldNot(BeNil())
17971798
g.Expect(its.Spec.PersistentVolumeClaimRetentionPolicy.WhenScaled).Should(Equal(kbappsv1.DeletePersistentVolumeClaimRetentionPolicyType))
@@ -1816,9 +1817,11 @@ var _ = Describe("Component Controller", func() {
18161817

18171818
itsKey := compKey
18181819
Eventually(testapps.CheckObj(&testCtx, itsKey, func(g Gomega, its *workloads.InstanceSet) {
1819-
g.Expect(*its.Spec.Replicas).To(BeEquivalentTo(0))
1820+
g.Expect(its.Spec.Stop).ShouldNot(BeNil())
1821+
g.Expect(*its.Spec.Stop).Should(BeTrue())
1822+
g.Expect(*its.Spec.Replicas).To(BeEquivalentTo(1))
18201823
g.Expect(its.Spec.PersistentVolumeClaimRetentionPolicy).ShouldNot(BeNil())
1821-
g.Expect(its.Spec.PersistentVolumeClaimRetentionPolicy.WhenScaled).Should(Equal(kbappsv1.RetainPersistentVolumeClaimRetentionPolicyType))
1824+
g.Expect(its.Spec.PersistentVolumeClaimRetentionPolicy.WhenScaled).Should(Equal(kbappsv1.DeletePersistentVolumeClaimRetentionPolicyType))
18221825
})).Should(Succeed())
18231826
}
18241827

0 commit comments

Comments
 (0)