Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 40 additions & 15 deletions apis/workloads/v1/instanceset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,26 @@ type InstanceSetSpec struct {
// +optional
Replicas *int32 `json:"replicas,omitempty"`

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

// AssignedOrdinals is the set of ordinals assigned to the current replicas.
//
// IMPORTANT: This field is managed automatically by the InstanceSet controller.
// Users should NOT manually modify this field.
//
// This field represents the authoritative set of ordinal identifiers currently in use by the workload.
// It enables support for non-contiguous ordinals, allowing any instance to be terminated without affecting others.
//
// The controller uses this list to maintain identity consistency and to decide which specific ordinal
// to allocate next during scaling up, or which identity is preserved during a restart.
//
// +optional
AssignedOrdinals Ordinals `json:"assignedOrdinals,omitempty"`

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

// Stop the InstanceSet.
// If set, all the computing resources will be released.
//
// +optional
Stop *bool `json:"stop,omitempty"`

// Describe the configs to be reconfigured.
//
// +optional
Expand Down Expand Up @@ -283,11 +301,6 @@ type InstanceSetStatus struct {
// replicas is the number of instances created by the InstanceSet controller.
Replicas int32 `json:"replicas"`

// Ordinals is the ordinals used by the instances of the InstanceSet except the template instances.
//
// +optional
Ordinals []int32 `json:"ordinals,omitempty"`

// readyReplicas is the number of instances created for this InstanceSet with a Ready Condition.
//
// +optional
Expand Down Expand Up @@ -402,8 +415,24 @@ type InstanceTemplate struct {
// then the instance names generated under this InstanceTemplate would be
// $(cluster.name)-$(component.name)-$(template.name)-0、$(cluster.name)-$(component.name)-$(template.name)-1 and
// $(cluster.name)-$(component.name)-$(template.name)-7
//
// +optional
Ordinals Ordinals `json:"ordinals,omitempty"`

// AssignedOrdinals is the set of ordinals assigned to the current replicas of this InstanceTemplate.
//
// IMPORTANT: This field is managed automatically by the InstanceSet controller.
// Users should NOT manually modify this field.
//
// This field represents the authoritative set of ordinal identifiers currently in use by the workload.
// It enables support for non-contiguous ordinals, allowing any instance to be terminated without affecting others.
//
// The controller uses this list to maintain identity consistency and to decide which specific ordinal
// to allocate next during scaling up, or which identity is preserved during a restart.
//
// +optional
AssignedOrdinals Ordinals `json:"assignedOrdinals,omitempty"`

// Specifies a map of key-value pairs to be merged into the Pod's existing annotations.
// Existing keys will have their values overwritten, while new keys will be added to the annotations.
//
Expand Down Expand Up @@ -579,10 +608,6 @@ type InstanceTemplateStatus struct {
// +optional
Replicas int32 `json:"replicas,omitempty"`

// Ordinals is the ordinals used by the instances of the InstanceTemplate.
// +optional
Ordinals []int32 `json:"ordinals,omitempty"`

// ReadyReplicas is the number of Pods that have a Ready Condition.
// +optional
ReadyReplicas int32 `json:"readyReplicas,omitempty"`
Expand Down
23 changes: 9 additions & 14 deletions apis/workloads/v1/zz_generated.deepcopy.go

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

160 changes: 112 additions & 48 deletions config/crd/bases/workloads.kubeblocks.io_instancesets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,45 @@ spec:
description: Defines the desired state of the state machine. It includes
the configuration details for the state machine.
properties:
assignedOrdinals:
description: |-
AssignedOrdinals is the set of ordinals assigned to the current replicas.


IMPORTANT: This field is managed automatically by the InstanceSet controller.
Users should NOT manually modify this field.


This field represents the authoritative set of ordinal identifiers currently in use by the workload.
It enables support for non-contiguous ordinals, allowing any instance to be terminated without affecting others.


The controller uses this list to maintain identity consistency and to decide which specific ordinal
to allocate next during scaling up, or which identity is preserved during a restart.
properties:
discrete:
items:
format: int32
type: integer
type: array
ranges:
items:
description: |-
Range represents a range with a start and an end value. Both start and end are included.
It is used to define a continuous segment.
properties:
end:
format: int32
type: integer
start:
format: int32
type: integer
required:
- end
- start
type: object
type: array
type: object
configs:
description: Describe the configs to be reconfigured.
items:
Expand Down Expand Up @@ -527,40 +566,6 @@ spec:
- name
type: object
type: array
defaultTemplateOrdinals:
description: |-
Specifies the desired Ordinals of the default template.
The Ordinals used to specify the ordinal of the instance (pod) names to be generated under the default template.
If Ordinals are defined, their number must be equal to or more than the corresponding replicas.


For example, if Ordinals is {ranges: [{start: 0, end: 1}], discrete: [7]},
then the instance names generated under the default template would be
$(cluster.name)-$(component.name)-0、$(cluster.name)-$(component.name)-1 and $(cluster.name)-$(component.name)-7
properties:
discrete:
items:
format: int32
type: integer
type: array
ranges:
items:
description: |-
Range represents a range with a start and an end value. Both start and end are included.
It is used to define a continuous segment.
properties:
end:
format: int32
type: integer
start:
format: int32
type: integer
required:
- end
- start
type: object
type: array
type: object
disableDefaultHeadlessService:
default: false
description: Specifies whether to create the default headless service.
Expand Down Expand Up @@ -727,6 +732,45 @@ spec:
Specifies a map of key-value pairs to be merged into the Pod's existing annotations.
Existing keys will have their values overwritten, while new keys will be added to the annotations.
type: object
assignedOrdinals:
description: |-
AssignedOrdinals is the set of ordinals assigned to the current replicas of this InstanceTemplate.


IMPORTANT: This field is managed automatically by the InstanceSet controller.
Users should NOT manually modify this field.


This field represents the authoritative set of ordinal identifiers currently in use by the workload.
It enables support for non-contiguous ordinals, allowing any instance to be terminated without affecting others.


The controller uses this list to maintain identity consistency and to decide which specific ordinal
to allocate next during scaling up, or which identity is preserved during a restart.
properties:
discrete:
items:
format: int32
type: integer
type: array
ranges:
items:
description: |-
Range represents a range with a start and an end value. Both start and end are included.
It is used to define a continuous segment.
properties:
end:
format: int32
type: integer
start:
format: int32
type: integer
required:
- end
- start
type: object
type: array
type: object
env:
description: |-
Defines Env to override.
Expand Down Expand Up @@ -3482,6 +3526,35 @@ spec:
items:
type: string
type: array
ordinals:
description: |-
Specifies the desired Ordinals.
The Ordinals used to specify the ordinal of the instance (pod) names to be generated under the InstanceSet.
If Ordinals are defined, their number must be equal to or more than the corresponding replicas.
properties:
discrete:
items:
format: int32
type: integer
type: array
ranges:
items:
description: |-
Range represents a range with a start and an end value. Both start and end are included.
It is used to define a continuous segment.
properties:
end:
format: int32
type: integer
start:
format: int32
type: integer
required:
- end
- start
type: object
type: array
type: object
parallelPodManagementConcurrency:
anyOf:
- type: integer
Expand Down Expand Up @@ -3663,6 +3736,11 @@ spec:
type: object
type: object
x-kubernetes-map-type: atomic
stop:
description: |-
Stop the InstanceSet.
If set, all the computing resources will be released.
type: boolean
template:
description: PodTemplateSpec describes the data a pod should have
when created from a template
Expand Down Expand Up @@ -11750,13 +11828,6 @@ spec:
InstanceSet's generation, which is updated on mutation by the API Server.
format: int64
type: integer
ordinals:
description: Ordinals is the ordinals used by the instances of the
InstanceSet except the template instances.
items:
format: int32
type: integer
type: array
readyInitReplicas:
description: |-
Represents the number of instances that have already reached the InstanceStatus during the cluster initialization stage.
Expand Down Expand Up @@ -11794,13 +11865,6 @@ spec:
name:
description: Name, the name of the InstanceTemplate.
type: string
ordinals:
description: Ordinals is the ordinals used by the instances
of the InstanceTemplate.
items:
format: int32
type: integer
type: array
readyReplicas:
description: ReadyReplicas is the number of Pods that have a
Ready Condition.
Expand Down
7 changes: 5 additions & 2 deletions controllers/apps/component/component_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,7 @@ var _ = Describe("Component Controller", func() {

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

itsKey := compKey
Eventually(testapps.CheckObj(&testCtx, itsKey, func(g Gomega, its *workloads.InstanceSet) {
g.Expect(*its.Spec.Replicas).To(BeEquivalentTo(0))
g.Expect(its.Spec.Stop).ShouldNot(BeNil())
g.Expect(*its.Spec.Stop).Should(BeTrue())
g.Expect(*its.Spec.Replicas).To(BeEquivalentTo(1))
g.Expect(its.Spec.PersistentVolumeClaimRetentionPolicy).ShouldNot(BeNil())
g.Expect(its.Spec.PersistentVolumeClaimRetentionPolicy.WhenScaled).Should(Equal(kbappsv1.RetainPersistentVolumeClaimRetentionPolicyType))
g.Expect(its.Spec.PersistentVolumeClaimRetentionPolicy.WhenScaled).Should(Equal(kbappsv1.DeletePersistentVolumeClaimRetentionPolicyType))
})).Should(Succeed())
}

Expand Down
Loading