8000 feat: a new pod naming rule for instanceset by cjc7373 · Pull Request #9292 · apecloud/kubeblocks · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: a new pod naming rule for instanceset #9292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions apis/apps/v1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,10 @@ type ClusterComponentSpec struct {
// +listMapKey=name
Instances []InstanceTemplate `json:"instances,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"name"`

// +optional
// +kubebuilder:default=Separated
PodNamingRule PodNamingRule `json:"podNamingRule,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this field defined outside the instance template?

9E7A
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then how does a user test the new naming rule? Use a feature gate?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question is why not defined it within the instance template?

Copy link
Contributor Author
@cjc7373 cjc7373 May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming rule applies to the whole instanceset, not just one instance template.


// Specifies the names of instances to be transitioned to offline status.
//
// Marking an instance as offline results in the following:
Expand Down
4 changes: 4 additions & 0 deletions apis/apps/v1/component_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ type ComponentSpec struct {
// +optional
Instances []InstanceTemplate `json:"instances,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"name"`

// +optional
// +kubebuilder:default=Separated
PodNamingRule PodNamingRule `json:"podNamingRule,omitempty"`

// Specifies the names of instances to be transitioned to offline status.
//
// Marking an instance as offline results in the following:
Expand Down
23 changes: 21 additions & 2 deletions apis/apps/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ type InstanceTemplate struct {
// Name specifies the unique name of the instance Pod created using this InstanceTemplate.
// This name is constructed by concatenating the Component's name, the template's name, and the instance's ordinal
// using the pattern: $(cluster.name)-$(component.name)-$(template.name)-$(ordinal). Ordinals start from 0.
// The specified name overrides any default naming conventions or patterns.
// The name can't be empty.
//
// +kubebuilder:validation:MaxLength=54
// +kubebuilder:validation:Pattern:=`^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$`
Expand Down Expand Up @@ -747,6 +747,7 @@ type InstanceTemplate struct {

// Specifies the desired Ordinals of this InstanceTemplate.
// The Ordinals used to specify the ordinal of the instance (pod) names to be generated under this InstanceTemplate.
// 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 this InstanceTemplate would be
Expand Down Expand Up @@ -789,7 +790,7 @@ type InstanceTemplate struct {
VolumeClaimTemplates []PersistentVolumeClaimTemplate `json:"volumeClaimTemplates,omitempty"`
}

// Range represents a range with a start and an end value.
// 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.
type Range struct {
Start int32 `json:"start"`
Expand All @@ -801,3 +802,21 @@ type Ordinals struct {
Ranges []Range `json:"ranges,omitempty"`
Discrete []int32 `json:"discrete,omitempty"`
}

// PodNamingRule defines the naming convention for instances (pods).
// The field is immutable once set.
//
// +kubebuilder:validation:Enum={Separated,Combined}
type PodNamingRule string

const (
// PodNamingRuleSeparated constructs pod name based on the InstanceSet Name, InstanceTemplate Name, and ordinal.
// Ordinals are unique within the template.
// The constructed instance name follows the pattern: $(instance_set.name)-$(template.name)-$(ordinal).
PodNamingRuleSeparated PodNamingRule = "Separated"

// PodNamingRuleCombined constructs pod name based on the InstanceSet Name and ordinal.
// Ordinals are unique globally.
// The constructed instance name follows the pattern: $(instance_set.name)-$(ordinal).
PodNamingRuleCombined PodNamingRule = "Combined"
)
16 changes: 10 additions & 6 deletions apis/workloads/v1/instanceset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type InstanceSetSpec struct {

// 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
Expand Down Expand Up @@ -116,8 +117,6 @@ type InstanceSetSpec struct {
// The InstanceTemplate provides a way to override values in the default template,
// allowing the InstanceSet to manage instances from different templates.
//
// The naming convention for instances (pods) based on the InstanceSet Name, InstanceTemplate Name, and ordinal.
// The constructed instance name follows the pattern: $(instance_set.name)-$(template.name)-$(ordinal).
// By default, the ordinal starts from 0 for each InstanceTemplate.
// It is important to ensure that the Name of each InstanceTemplate is unique.
//
Expand All @@ -131,6 +130,10 @@ type InstanceSetSpec struct {
// +listMapKey=name
Instances []InstanceTemplate `json:"instances,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"name"`

// +optional
// +kubebuilder:default=Separated
PodNamingRule kbappsv1.PodNamingRule `json:"podNamingRule,omitempty"`

// Specifies the names of instances to be transitioned to offline status.
//
// Marking an instance as offline results in the following:
Expand Down Expand Up @@ -311,9 +314,10 @@ type InstanceSetStatus struct {
MembersStatus []MemberStatus `json:"membersStatus,omitempty"`

// Provides the status of each instance in the ITS.
// key is pod name.
//
// +optional
InstanceStatus []InstanceStatus `json:"instanceStatus,omitempty"`
InstanceStatus map[string]InstanceStatus `json:"instanceStatus,omitempty"`

// currentRevisions, if not empty, indicates the old version of the InstanceSet used to generate the underlying workload.
// key is the pod name, value is the revision.
Expand Down Expand Up @@ -509,11 +513,11 @@ type MemberStatus struct {
}

type InstanceStatus struct {
// Represents the name of the pod.
// Represents the instance template the pod uses. Default template name is empty string.
//
// +kubebuilder:validation:Required
// +kubebuilder:default=Unknown
PodName string `json:"podName"`
// +kubebuilder:default=""
TemplateName string `json:"templateName"`

// The status of configs.
//
Expand Down
6 changes: 3 additions & 3 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.

28 changes: 24 additions & 4 deletions config/crd/bases/apps.kubeblocks.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -921,14 +921,15 @@ spec:
Name specifies the unique name of the instance Pod created using this InstanceTemplate.
This name is constructed by concatenating the Component's name, the template's name, and the instance's ordinal
using the pattern: $(cluster.name)-$(component.name)-$(template.name)-$(ordinal). Ordinals start from 0.
The specified name overrides any default naming conventions or patterns.
The name can't be empty.
maxLength: 54
pattern: ^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$
type: string
ordinals:
description: |-
Specifies the desired Ordinals of this InstanceTemplate.
The Ordinals used to specify the ordinal of the instance (pod) names to be generated under this InstanceTemplate.
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]},
Expand All @@ -944,7 +945,7 @@ spec:
ranges:
items:
description: |-
Range represents a range with a start and an end value.
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:
Expand Down Expand Up @@ -2582,6 +2583,15 @@ spec:
- Delete
type: string
type: object
podNamingRule:
default: Separated
description: |-
PodNamingRule defines the naming convention for instances (pods).
The field is immutable once set.
enum:
- Separated
- Combined
type: string
podUpdatePolicy:
description: |-
PodUpdatePolicy indicates how pods should be updated
Expand Down Expand Up @@ -8526,14 +8536,15 @@ spec:
Name specifies the unique name of the instance Pod created using this InstanceTemplate.
This name is constructed by concatenating the Component's name, the template's name, and the instance's ordinal
using the pattern: $(cluster.name)-$(component.name)-$(template.name)-$(ordinal). Ordinals start from 0.
The specified name overrides any default naming conventions or patterns.
The name can't be empty.
maxLength: 54
pattern: ^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$
type: string
ordinals:
description: |-
Specifies the desired Ordinals of this InstanceTemplate.
The Ordinals used to specify the ordinal of the instance (pod) names to be generated under this InstanceTemplate.
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]},
Expand All @@ -8549,7 +8560,7 @@ spec:
ranges:
items:
description: |-
Range represents a range with a start and an end value.
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:
Expand Down Expand Up @@ -10205,6 +10216,15 @@ spec:
- Delete
type: string
type: object
podNamingRule:
default: Separated
description: |-
PodNamingRule defines the naming convention for instances (pods).
The field is immutable once set.
enum:
- Separated
- Combined
type: string
podUpdatePolicy:
description: |-
PodUpdatePolicy indicates how pods should be updated
Expand Down
14 changes: 12 additions & 2 deletions config/crd/bases/apps.kubeblocks.io_components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -787,14 +787,15 @@ spec:
Name specifies the unique name of the instance Pod created using this InstanceTemplate.
This name is constructed by concatenating the Component's name, the template's name, and the instance's ordinal
using the pattern: $(cluster.name)-$(component.name)-$(template.name)-$(ordinal). Ordinals start from 0.
The specified name overrides any default naming conventions or patterns.
The name can't be empty.
maxLength: 54
pattern: ^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$
type: string
ordinals:
description: |-
Specifies the desired Ordinals of this InstanceTemplate.
The Ordinals used to specify the ordinal of the instance (pod) names to be generated under this InstanceTemplate.
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]},
Expand All @@ -810,7 +811,7 @@ spec:
ranges:
items:
description: |-
Range represents a range with a start and an end value.
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:
Expand Down Expand Up @@ -2364,6 +2365,15 @@ spec:
- Delete
type: string
type: object
podNamingRule:
default: Separated
description: |-
PodNamingRule defines the naming convention for instances (pods).
The field is immutable once set.
enum:
- Separated
- Combined
type: string
podUpdatePolicy:
description: |-
PodUpdatePolicy indicates how pods should be updated
Expand Down
10 changes: 6 additions & 4 deletions config/crd/bases/operations.kubeblocks.io_opsrequests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -791,14 +791,15 @@ spec:
Name specifies the unique name of the instance Pod created using this InstanceTemplate.
This name is constructed by concatenating the Component's name, the template's name, and the instance's ordinal
using the pattern: $(cluster.name)-$(component.name)-$(template.name)-$(ordinal). Ordinals start from 0.
The specified name overrides any default naming conventions or patterns.
The name can't be empty.
maxLength: 54
pattern: ^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$
type: string
ordinals:
description: |-
Specifies the desired Ordinals of this InstanceTemplate.
The Ordinals used to specify the ordinal of the instance (pod) names to be generated under this InstanceTemplate.
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]},
Expand All @@ -814,7 +815,7 @@ spec:
ranges:
items:
description: |-
Range represents a range with a start and an end value.
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:
Expand Down Expand Up @@ -3618,14 +3619,15 @@ spec:
Name specifies the unique name of the instance Pod created using this InstanceTemplate.
This name is constructed by concatenating the Component's name, the template's name, and the instance's ordinal
using the pattern: $(cluster.name)-$(component.name)-$(template.name)-$(ordinal). Ordinals start from 0.
The specified name overrides any default naming conventions or patterns.
The name can't be empty.
maxLength: 54
pattern: ^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$
type: string
ordinals:
description: |-
Specifies the desired Ordinals of this InstanceTemplate.
The Ordinals used to specify the ordinal of the instance (pod) names to be generated under this InstanceTemplate.
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]},
Expand All @@ -3641,7 +3643,7 @@ spec:
ranges:
items:
description: |-
Range represents a range with a start and an end value.
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:
Expand Down
Loading
0