Skip to content
Merged
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
6 changes: 4 additions & 2 deletions api/core/v1alpha1/tidb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,10 @@ type TiDBServer struct {
Ports TiDBPorts `json:"ports,omitempty"`

// Labels defines the server labels of the TiDB server.
// TiDB Operator will ignore `labels` in TiDB's config file and use this field instead.
// Note these label keys are managed by TiDB Operator, it will be set automatically and you can not modify them:
// Operator will set these `labels` by API.
// If a label in this field is conflict with the config file, this field takes precedence.
// NOTE: Different from other components, TiDB will replace all labels but not only add/update.
// NOTE: these label keys are managed by TiDB Operator, it will be set automatically and you can not modify them:
// - host
// - region
// - zone
Expand Down
11 changes: 11 additions & 0 deletions api/core/v1alpha1/tiflash_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ type TiFlashTemplateSpec struct {
type TiFlashServer struct {
// Ports defines all ports listened by tiflash
Ports TiFlashPorts `json:"ports,omitempty"`

// Labels defines the server labels of the TiFlash server.
// Operator will set these `labels` by API.
// If a label in this field is conflict with the config file, this field takes precedence.
// NOTE: If a label is removed, operator will not delete it automatically.
// NOTE: these label keys are managed by TiDB Operator, it will be set automatically and you can not modify them:
// - host
// - region
// - zone
// +kubebuilder:validation:XValidation:rule="!('host' in self) && !('region' in self) && !('zone' in self)",message="labels cannot contain 'host', 'region', or 'zone' keys"
Labels map[string]string `json:"labels,omitempty"`
}

type TiFlashPorts struct {
Expand Down
12 changes: 12 additions & 0 deletions api/core/v1alpha1/tikv_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,17 @@ type TiKVRemoteWorkers struct {
type TiKVServer struct {
// Ports defines all ports listened by tikv
Ports TiKVPorts `json:"ports,omitempty"`

// Labels defines the server labels of the TiKV server.
// Operator will set these `labels` by API dynamically.
// If a label in this field is conflict with the config file, this field takes precedence.
// NOTE: If a label is removed, operator will not delete it automatically.
// NOTE: these label keys are managed by TiDB Operator, it will be set automatically and you can not modify them:
// - host
// - region
// - zone
// +kubebuilder:validation:XValidation:rule="!('host' in self) && !('region' in self) && !('zone' in self)",message="labels cannot contain 'host', 'region', or 'zone' keys"
Labels map[string]string `json:"labels,omitempty"`
}

type TiKVPorts struct {
Expand All @@ -238,6 +249,7 @@ type TiKVGroupStatus struct {
GroupStatus `json:",inline"`
}

// TiKVSpec defines the spec of tikv instance
// +kubebuilder:validation:XValidation:rule="(!has(oldSelf.topology) && !has(self.topology)) || (has(oldSelf.topology) && has(self.topology))",fieldPath=".topology",message="topology can only be set when creating"
type TiKVSpec struct {
// Cluster is a reference of tidb cluster
Expand Down
8 changes: 5 additions & 3 deletions api/core/v1alpha1/tiproxy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,11 @@ type TiProxyServer struct {
// Port defines all ports listened by TiProxy.
Ports TiProxyPorts `json:"ports,omitempty"`

// Labels defines the server labels of the TiProxy.
// TiDB Operator will ignore `labels` in TiProxy's config file and use this field instead.
// Note these label keys are managed by TiDB Operator, it will be set automatically and you can not modify them:
// Labels defines the server labels of the TiProxy server.
// Operator will set these `labels` by API.
// If a label in this field is conflict with the config file, this field takes precedence.
// NOTE: If a label is removed, operator will not delete it automatically.
// NOTE: these label keys are managed by TiDB Operator, it will be set automatically and you can not modify them:
// - host
// - region
// - zone
Expand Down
14 changes: 14 additions & 0 deletions api/core/v1alpha1/zz_generated.deepcopy.go

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

20 changes: 18 additions & 2 deletions cmd/runtime-gen/generators/namer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ import (
"k8s.io/gengo/v2/types"
)

const (
nameTiDB = "TiDB"
nameTiProxy = "TiProxy"
nameTiKV = "TiKV"
nameTiFlash = "TiFlash"
)

type NameFunc func(t *types.Type) string

func (f NameFunc) Name(t *types.Type) string {
Expand All @@ -39,7 +46,7 @@ func GroupToInstanceName(t *types.Type) string {
func GroupToSecurityTypeName(t *types.Type) string {
name := strings.TrimSuffix(t.Name.Name, "Group")
switch name {
case "TiDB", "TiProxy":
case nameTiDB, nameTiProxy:
return name + "Security"
}

Expand All @@ -53,7 +60,7 @@ func GroupToSecurityTypeName(t *types.Type) string {
func GroupToTLSTypeName(t *types.Type) string {
name := strings.TrimSuffix(t.Name.Name, "Group")
switch name {
case "TiDB", "TiProxy":
case nameTiDB, nameTiProxy:
return name + "TLSConfig"
}

Expand All @@ -71,3 +78,12 @@ func GroupToInternalTLSTypeName(t *types.Type) string {

return "InternalTLS"
}

func InstanceToServerLabelsField(t *types.Type) string {
switch t.Name.Name {
case nameTiDB, nameTiKV, nameTiFlash, nameTiProxy:
return "in.Spec.Server.Labels"
}

return "nil"
}
15 changes: 10 additions & 5 deletions cmd/runtime-gen/generators/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ func (g *runtimeGenerator) Filter(_ *generator.Context, t *types.Type) bool {

func (g *runtimeGenerator) Namers(*generator.Context) namer.NameSystems {
return namer.NameSystems{
"pub": namer.NewPublicNamer(0),
"instance": NameFunc(GroupToInstanceName),
"security": NameFunc(GroupToSecurityTypeName),
"tls": NameFunc(GroupToTLSTypeName),
"internaltls": NameFunc(GroupToInternalTLSTypeName),
"pub": namer.NewPublicNamer(0),
"instance": NameFunc(GroupToInstanceName),
"security": NameFunc(GroupToSecurityTypeName),
"tls": NameFunc(GroupToTLSTypeName),
"internaltls": NameFunc(GroupToInternalTLSTypeName),
"serverlabels": NameFunc(InstanceToServerLabelsField),
}
}

Expand Down Expand Up @@ -281,6 +282,10 @@ func (in *$.|pub$) Subdomain() string {
return in.Spec.Subdomain
}

func (in *$.|pub$) ServerLabels() map[string]string {
return $.|serverlabels$
}

func (in *$.|pub$) ClusterCertKeyPairSecretName() string {
sec := in.Spec.Security
if sec != nil && sec.TLS != nil && sec.TLS.Cluster != nil && sec.TLS.Cluster.CertKeyPair != nil {
Expand Down
6 changes: 4 additions & 2 deletions manifests/crd/core.pingcap.com_tidbgroups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8800,8 +8800,10 @@ spec:
type: string
description: |-
Labels defines the server labels of the TiDB server.
TiDB Operator will ignore `labels` in TiDB's config file and use this field instead.
Note these label keys are managed by TiDB Operator, it will be set automatically and you can not modify them:
Operator will set these `labels` by API.
If a label in this field is conflict with the config file, this field takes precedence.
NOTE: Different from other components, TiDB will replace all labels but not only add/update.
NOTE: these label keys are managed by TiDB Operator, it will be set automatically and you can not modify them:
- host
- region
- zone
Expand Down
6 changes: 4 additions & 2 deletions manifests/crd/core.pingcap.com_tidbs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8511,8 +8511,10 @@ spec:
type: string
description: |-
Labels defines the server labels of the TiDB server.
TiDB Operator will ignore `labels` in TiDB's config file and use this field instead.
Note these label keys are managed by TiDB Operator, it will be set automatically and you can not modify them:
Operator will set these `labels` by API.
If a label in this field is conflict with the config file, this field takes precedence.
NOTE: Different from other components, TiDB will replace all labels but not only add/update.
NOTE: these label keys are managed by TiDB Operator, it will be set automatically and you can not modify them:
- host
- region
- zone
Expand Down
17 changes: 17 additions & 0 deletions manifests/crd/core.pingcap.com_tiflashes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8412,6 +8412,23 @@ spec:
server:
description: Server defines the server config of TiFlash
properties:
labels:
additionalProperties:
type: string
description: |-
Labels defines the server labels of the TiFlash server.
Operator will set these `labels` by API.
If a label in this field is conflict with the config file, this field takes precedence.
NOTE: If a label is removed, operator will not delete it automatically.
NOTE: these label keys are managed by TiDB Operator, it will be set automatically and you can not modify them:
- host
- region
- zone
type: object
x-kubernetes-validations:
- message: labels cannot contain 'host', 'region', or 'zone' keys
rule: '!(''host'' in self) && !(''region'' in self) && !(''zone''
in self)'
ports:
description: Ports defines all ports listened by tiflash
properties:
Expand Down
18 changes: 18 additions & 0 deletions manifests/crd/core.pingcap.com_tiflashgroups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8686,6 +8686,24 @@ spec:
server:
description: Server defines the server config of TiFlash
properties:
labels:
additionalProperties:
type: string
description: |-
Labels defines the server labels of the TiFlash server.
Operator will set these `labels` by API.
If a label in this field is conflict with the config file, this field takes precedence.
NOTE: If a label is removed, operator will not delete it automatically.
NOTE: these label keys are managed by TiDB Operator, it will be set automatically and you can not modify them:
- host
- region
- zone
type: object
x-kubernetes-validations:
- message: labels cannot contain 'host', 'region', or
'zone' keys
rule: '!(''host'' in self) && !(''region'' in self)
&& !(''zone'' in self)'
ports:
description: Ports defines all ports listened by tiflash
properties:
Expand Down
18 changes: 18 additions & 0 deletions manifests/crd/core.pingcap.com_tikvgroups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8703,6 +8703,24 @@ spec:
server:
description: Server defines the server config of TiKV
properties:
labels:
additionalProperties:
type: string
description: |-
Labels defines the server labels of the TiKV server.
Operator will set these `labels` by API dynamically.
If a label in this field is conflict with the config file, this field takes precedence.
NOTE: If a label is removed, operator will not delete it automatically.
NOTE: these label keys are managed by TiDB Operator, it will be set automatically and you can not modify them:
- host
- region
- zone
type: object
x-kubernetes-validations:
- message: labels cannot contain 'host', 'region', or
'zone' keys
rule: '!(''host'' in self) && !(''region'' in self)
&& !(''zone'' in self)'
ports:
description: Ports defines all ports listened by tikv
properties:
Expand Down
18 changes: 18 additions & 0 deletions manifests/crd/core.pingcap.com_tikvs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ spec:
metadata:
type: object
spec:
description: TiKVSpec defines the spec of tikv instance
properties:
cluster:
description: Cluster is a reference of tidb cluster
Expand Down Expand Up @@ -8428,6 +8429,23 @@ spec:
server:
description: Server defines the server config of TiKV
properties:
labels:
additionalProperties:
type: string
description: |-
Labels defines the server labels of the TiKV server.
Operator will set these `labels` by API dynamically.
If a label in this field is conflict with the config file, this field takes precedence.
NOTE: If a label is removed, operator will not delete it automatically.
NOTE: these label keys are managed by TiDB Operator, it will be set automatically and you can not modify them:
- host
- region
- zone
type: object
x-kubernetes-validations:
- message: labels cannot contain 'host', 'region', or 'zone' keys
rule: '!(''host'' in self) && !(''region'' in self) && !(''zone''
in self)'
ports:
description: Ports defines all ports listened by tikv
properties:
Expand Down
8 changes: 5 additions & 3 deletions manifests/crd/core.pingcap.com_tiproxies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8507,9 +8507,11 @@ spec:
additionalProperties:
type: string
description: |-
Labels defines the server labels of the TiProxy.
TiDB Operator will ignore `labels` in TiProxy's config file and use this field instead.
Note these label keys are managed by TiDB Operator, it will be set automatically and you can not modify them:
Labels defines the server labels of the TiProxy server.
Operator will set these `labels` by API.
If a label in this field is conflict with the config file, this field takes precedence.
NOTE: If a label is removed, operator will not delete it automatically.
NOTE: these label keys are managed by TiDB Operator, it will be set automatically and you can not modify them:
- host
- region
- zone
Expand Down
8 changes: 5 additions & 3 deletions manifests/crd/core.pingcap.com_tiproxygroups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8795,9 +8795,11 @@ spec:
additionalProperties:
type: string
description: |-
Labels defines the server labels of the TiProxy.
TiDB Operator will ignore `labels` in TiProxy's config file and use this field instead.
Note these label keys are managed by TiDB Operator, it will be set automatically and you can not modify them:
Labels defines the server labels of the TiProxy server.
Operator will set these `labels` by API.
If a label in this field is conflict with the config file, this field takes precedence.
NOTE: If a label is removed, operator will not delete it automatically.
NOTE: these label keys are managed by TiDB Operator, it will be set automatically and you can not modify them:
Comment on lines +8799 to +8802
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

The documentation comment says "NOTE: If a label is removed, operator will not delete it automatically" but this behavior is inconsistent across components. For TiKV and TiFlash, the Contains check only verifies that expected labels are present but doesn't remove extra labels. However, for TiDB the comment says "Different from other components, TiDB will replace all labels but not only add/update", which suggests TiDB does delete removed labels. This inconsistency should be clarified in the documentation.

Suggested change
Operator will set these `labels` by API.
If a label in this field is conflict with the config file, this field takes precedence.
NOTE: If a label is removed, operator will not delete it automatically.
NOTE: these label keys are managed by TiDB Operator, it will be set automatically and you can not modify them:
TiDB Operator will set these labels via the TiProxy API.
If a label in this field conflicts with the config file, this field takes precedence.
TiDB Operator only adds or updates the labels specified here; it does not remove any existing
labels on the TiProxy server. Removing a label key from this field will NOT delete that label
from TiProxy automatically.
NOTE: The following label keys are managed automatically by TiDB Operator. They are set by the
operator and cannot be modified in this field:

Copilot uses AI. Check for mistakes.
- host
- region
- zone
Expand Down
8 changes: 8 additions & 0 deletions pkg/apiutil/core/v1alpha1/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,11 @@ func InstanceAdvertiseAddress[
](cluster *v1alpha1.Cluster, obj F, port P) string {
return InstanceHost[S](cluster, obj) + urlPort(port)
}

func ServerLabels[
S scope.Instance[F, T],
F client.Object,
T runtime.Instance,
](obj F) map[string]string {
return scope.From[S](obj).ServerLabels()
}
4 changes: 0 additions & 4 deletions pkg/controllers/common/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,3 @@ type HealthyState interface {
type HealthyStateUpdater interface {
SetHealthy()
}

type ServerLabelsState interface {
GetServerLabels() map[string]string
}
Loading