Skip to content

Commit ad1f650

Browse files
authored
feat: add resource-manager support to PD microservices (#6635)
1 parent d2c8b1a commit ad1f650

File tree

44 files changed

+20506
-67
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+20506
-67
lines changed

api/core/v1alpha1/common_types.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,16 @@ const (
126126

127127
const (
128128
// Label value for meta.LabelKeyComponent
129-
LabelValComponentPD = string(meta.ComponentPD)
130-
LabelValComponentTiDB = string(meta.ComponentTiDB)
131-
LabelValComponentTiKV = string(meta.ComponentTiKV)
132-
LabelValComponentTiKVWorker = string(meta.ComponentTiKVWorker)
133-
LabelValComponentTiFlash = string(meta.ComponentTiFlash)
134-
LabelValComponentTiCDC = string(meta.ComponentTiCDC)
135-
LabelValComponentTSO = string(meta.ComponentTSO)
136-
LabelValComponentScheduling = string(meta.ComponentScheduling)
137-
LabelValComponentTiProxy = string(meta.ComponentTiProxy)
129+
LabelValComponentPD = string(meta.ComponentPD)
130+
LabelValComponentTiDB = string(meta.ComponentTiDB)
131+
LabelValComponentTiKV = string(meta.ComponentTiKV)
132+
LabelValComponentTiKVWorker = string(meta.ComponentTiKVWorker)
133+
LabelValComponentTiFlash = string(meta.ComponentTiFlash)
134+
LabelValComponentTiCDC = string(meta.ComponentTiCDC)
135+
LabelValComponentTSO = string(meta.ComponentTSO)
136+
LabelValComponentScheduling = string(meta.ComponentScheduling)
137+
LabelValComponentResourceManager = string(meta.ComponentResourceManager)
138+
LabelValComponentTiProxy = string(meta.ComponentTiProxy)
138139
// Deprecated: use LabelValComponentScheduling
139140
LabelValComponentScheduler = string(meta.ComponentScheduler)
140141

api/core/v1alpha1/names.go

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,16 @@ const (
5656
const (
5757
// Main component containers of the tidb cluster
5858
// These names are well known so the name prefix is not added.
59-
ContainerNamePD = "pd"
60-
ContainerNameTiKV = "tikv"
61-
ContainerNameTiKVWorker = "tikv-worker"
62-
ContainerNameTiDB = "tidb"
63-
ContainerNameTiFlash = "tiflash"
64-
ContainerNameTiCDC = "ticdc"
65-
ContainerNameTSO = "tso"
66-
ContainerNameScheduling = "scheduling"
67-
ContainerNameTiProxy = "tiproxy"
59+
ContainerNamePD = "pd"
60+
ContainerNameTiKV = "tikv"
61+
ContainerNameTiKVWorker = "tikv-worker"
62+
ContainerNameTiDB = "tidb"
63+
ContainerNameTiFlash = "tiflash"
64+
ContainerNameTiCDC = "ticdc"
65+
ContainerNameTSO = "tso"
66+
ContainerNameScheduling = "scheduling"
67+
ContainerNameResourceManager = "resource-manager"
68+
ContainerNameTiProxy = "tiproxy"
6869
// Deprecated: use ContainerNameScheduling
6970
ContainerNameScheduler = "scheduler"
7071

@@ -92,15 +93,16 @@ const (
9293
// All well known dir path
9394
const (
9495
// config dir path
95-
DirPathConfigPD = "/etc/pd"
96-
DirPathConfigTiKV = "/etc/tikv"
97-
DirPathConfigTiKVWorker = "/etc/tikv-worker"
98-
DirPathConfigTiDB = "/etc/tidb"
99-
DirPathConfigTiFlash = "/etc/tiflash"
100-
DirPathConfigTiCDC = "/etc/ticdc"
101-
DirPathConfigTSO = "/etc/tso"
102-
DirPathConfigScheduling = "/etc/scheduling"
103-
DirPathConfigTiProxy = "/etc/tiproxy"
96+
DirPathConfigPD = "/etc/pd"
97+
DirPathConfigTiKV = "/etc/tikv"
98+
DirPathConfigTiKVWorker = "/etc/tikv-worker"
99+
DirPathConfigTiDB = "/etc/tidb"
100+
DirPathConfigTiFlash = "/etc/tiflash"
101+
DirPathConfigTiCDC = "/etc/ticdc"
102+
DirPathConfigTSO = "/etc/tso"
103+
DirPathConfigScheduling = "/etc/scheduling"
104+
DirPathConfigResourceManager = "/etc/resource-manager"
105+
DirPathConfigTiProxy = "/etc/tiproxy"
104106
// Deprecated: use DirPathConfigScheduling
105107
DirPathConfigScheduler = "/etc/scheduler"
106108

@@ -120,16 +122,17 @@ const (
120122
// TLS
121123
//
122124
// Dir path of cluster tls file
123-
DirPathClusterTLSPD = "/var/lib/pd-tls"
124-
DirPathClusterTLSTiKV = "/var/lib/tikv-tls"
125-
DirPathClusterTLSTiKVWorker = "/var/lib/tikv-worker-tls"
126-
DirPathClusterTLSTiDB = "/var/lib/tidb-tls"
127-
DirPathClusterTLSTiFlash = "/var/lib/tiflash-tls"
128-
DirPathClusterClientTLS = "/var/lib/cluster-client-tls"
129-
DirPathClusterTLSTiCDC = "/var/lib/ticdc-tls"
130-
DirPathClusterTLSTSO = "/var/lib/tso-tls"
131-
DirPathClusterTLSScheduling = "/var/lib/scheduling-tls"
132-
DirPathClusterTLSTiProxy = "/var/lib/tiproxy-tls"
125+
DirPathClusterTLSPD = "/var/lib/pd-tls"
126+
DirPathClusterTLSTiKV = "/var/lib/tikv-tls"
127+
DirPathClusterTLSTiKVWorker = "/var/lib/tikv-worker-tls"
128+
DirPathClusterTLSTiDB = "/var/lib/tidb-tls"
129+
DirPathClusterTLSTiFlash = "/var/lib/tiflash-tls"
130+
DirPathClusterClientTLS = "/var/lib/cluster-client-tls"
131+
DirPathClusterTLSTiCDC = "/var/lib/ticdc-tls"
132+
DirPathClusterTLSTSO = "/var/lib/tso-tls"
133+
DirPathClusterTLSScheduling = "/var/lib/scheduling-tls"
134+
DirPathClusterTLSResourceManager = "/var/lib/resource-manager-tls"
135+
DirPathClusterTLSTiProxy = "/var/lib/tiproxy-tls"
133136
// Deprecated: use DirPathClusterTLSScheduling
134137
DirPathClusterTLSScheduler = "/var/lib/scheduler-tls"
135138

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
// Copyright 2024 PingCAP, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package v1alpha1
16+
17+
import (
18+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
19+
20+
meta "github.com/pingcap/tidb-operator/api/v2/meta/v1alpha1"
21+
)
22+
23+
const (
24+
ResourceManagerPortNameClient = "client"
25+
DefaultResourceManagerPortClient = 3379
26+
27+
// DefaultResourceManagerMinReadySeconds is default min ready seconds of resource manager
28+
DefaultResourceManagerMinReadySeconds = 5
29+
)
30+
31+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
32+
// +kubebuilder:object:root=true
33+
34+
// ResourceManagerGroupList defines a list of ResourceManager groups
35+
type ResourceManagerGroupList struct {
36+
metav1.TypeMeta `json:",inline"`
37+
metav1.ListMeta `json:"metadata,omitempty"`
38+
39+
Items []ResourceManagerGroup `json:"items"`
40+
}
41+
42+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
43+
// +kubebuilder:object:root=true
44+
// +kubebuilder:subresource:status
45+
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.selector
46+
// +kubebuilder:resource:categories=group,shortName=rmg
47+
// +kubebuilder:selectablefield:JSONPath=`.spec.cluster.name`
48+
// +kubebuilder:printcolumn:name="Cluster",type=string,JSONPath=`.spec.cluster.name`
49+
// +kubebuilder:printcolumn:name="Desired",type=string,JSONPath=`.spec.replicas`
50+
// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.readyReplicas`
51+
// +kubebuilder:printcolumn:name="Updated",type=string,JSONPath=`.status.updatedReplicas`
52+
// +kubebuilder:printcolumn:name="UpdateRevision",type=string,JSONPath=`.status.updateRevision`
53+
// +kubebuilder:printcolumn:name="CurrentRevision",type=string,JSONPath=`.status.currentRevision`
54+
// +kubebuilder:printcolumn:name="Synced",type=string,JSONPath=`.status.conditions[?(@.type=="Synced")].status`
55+
// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`
56+
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
57+
58+
// ResourceManagerGroup defines a group of similar ResourceManager instances
59+
// +kubebuilder:validation:XValidation:rule="size(self.metadata.name) <= 40",message="name must not exceed 40 characters"
60+
type ResourceManagerGroup struct {
61+
metav1.TypeMeta `json:",inline"`
62+
metav1.ObjectMeta `json:"metadata,omitempty"`
63+
64+
Spec ResourceManagerGroupSpec `json:"spec,omitempty"`
65+
Status ResourceManagerGroupStatus `json:"status,omitempty"`
66+
}
67+
68+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
69+
// +kubebuilder:object:root=true
70+
71+
// ResourceManagerList defines a list of ResourceManager instances
72+
type ResourceManagerList struct {
73+
metav1.TypeMeta `json:",inline"`
74+
metav1.ListMeta `json:"metadata,omitempty"`
75+
76+
Items []ResourceManager `json:"items"`
77+
}
78+
79+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
80+
// +kubebuilder:object:root=true
81+
// +kubebuilder:subresource:status
82+
// +kubebuilder:resource:categories=instance
83+
// +kubebuilder:selectablefield:JSONPath=`.spec.cluster.name`
84+
// +kubebuilder:printcolumn:name="Cluster",type=string,JSONPath=`.spec.cluster.name`
85+
// +kubebuilder:printcolumn:name="Synced",type=string,JSONPath=`.status.conditions[?(@.type=="Synced")].status`
86+
// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`
87+
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
88+
89+
// ResourceManager defines a ResourceManager instance
90+
// +kubebuilder:validation:XValidation:rule="size(self.metadata.name) <= 47",message="name must not exceed 47 characters"
91+
type ResourceManager struct {
92+
metav1.TypeMeta `json:",inline"`
93+
metav1.ObjectMeta `json:"metadata,omitempty"`
94+
95+
Spec ResourceManagerSpec `json:"spec,omitempty"`
96+
Status ResourceManagerStatus `json:"status,omitempty"`
97+
}
98+
99+
// ResourceManagerGroupSpec describes the common attributes of a ResourceManagerGroup
100+
101+
type ResourceManagerGroupSpec struct {
102+
Cluster ClusterReference `json:"cluster"`
103+
// Features are enabled feature
104+
Features []meta.Feature `json:"features,omitempty"`
105+
106+
// +kubebuilder:validation:Minimum=0
107+
Replicas *int32 `json:"replicas"`
108+
109+
// +listType=map
110+
// +listMapKey=type
111+
SchedulePolicies []SchedulePolicy `json:"schedulePolicies,omitempty"`
112+
113+
// MinReadySeconds specifies the minimum number of seconds for which a newly created pod be ready without any of its containers crashing, for it to be considered available.
114+
// +kubebuilder:validation:Minimum=0
115+
// +optional
116+
MinReadySeconds *int64 `json:"minReadySeconds,omitempty"`
117+
118+
Template ResourceManagerTemplate `json:"template"`
119+
}
120+
121+
type ResourceManagerTemplate struct {
122+
ObjectMeta `json:"metadata,omitempty"`
123+
Spec ResourceManagerTemplateSpec `json:"spec"`
124+
}
125+
126+
// ResourceManagerTemplateSpec can only be specified in ResourceManagerGroup
127+
// TODO: It's name may need to be changed to distinguish from PodTemplateSpec
128+
// +kubebuilder:validation:XValidation:rule="!has(self.overlay) || !has(self.overlay.volumeClaims) || (has(self.volumes) && self.overlay.volumeClaims.all(vc, vc.name in self.volumes.map(v, v.name)))",message="overlay volumeClaims names must exist in volumes"
129+
130+
type ResourceManagerTemplateSpec struct {
131+
// Version must be a semantic version.
132+
// It can has a v prefix or not.
133+
// +kubebuilder:validation:Pattern=`^(v)?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$`
134+
Version string `json:"version"`
135+
136+
// Image is pd's image
137+
// If tag is omitted, version will be used as the image tag.
138+
// Default is pingcap/pd
139+
Image *string `json:"image,omitempty"`
140+
141+
// Server defines server config for ResourceManager
142+
Server ResourceManagerServer `json:"server,omitempty"`
143+
144+
Resources ResourceRequirements `json:"resources,omitempty"`
145+
146+
UpdateStrategy UpdateStrategy `json:"updateStrategy,omitempty"`
147+
148+
// Config defines config file of ResourceManager
149+
Config ConfigFile `json:"config,omitempty"`
150+
151+
// Security defines security config
152+
Security *Security `json:"security,omitempty"`
153+
154+
// Volumes defines persistent volumes of ResourceManager
155+
// +listType=map
156+
// +listMapKey=name
157+
// +kubebuilder:validation:MaxItems=256
158+
Volumes []Volume `json:"volumes,omitempty"`
159+
160+
// Overlay defines a k8s native resource template patch
161+
// All resources(pod, pvcs, ...) managed by ResourceManager can be overlayed by this field
162+
Overlay *Overlay `json:"overlay,omitempty"`
163+
}
164+
165+
type ResourceManagerServer struct {
166+
// Ports defines all ports listened by ResourceManager
167+
Ports ResourceManagerPorts `json:"ports,omitempty"`
168+
}
169+
170+
type ResourceManagerPorts struct {
171+
// Client defines port for ResourceManager's api service
172+
Client *Port `json:"client,omitempty"`
173+
}
174+
175+
type ResourceManagerGroupStatus struct {
176+
CommonStatus `json:",inline"`
177+
GroupStatus `json:",inline"`
178+
}
179+
180+
// ResourceManagerSpec describes the common attributes of a ResourceManager instance
181+
// +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"
182+
183+
type ResourceManagerSpec struct {
184+
// Cluster is a reference of tidb cluster
185+
Cluster ClusterReference `json:"cluster"`
186+
// Features are enabled feature
187+
Features []meta.Feature `json:"features,omitempty"`
188+
189+
// Topology defines the topology domain of this ResourceManager instance
190+
// It will be translated into a node affinity config
191+
// Topology cannot be changed
192+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="topology is immutable"
193+
Topology Topology `json:"topology,omitempty"`
194+
195+
// Subdomain means the subdomain of the exported ResourceManager dns.
196+
// A same ResourceManager cluster will use a same subdomain
197+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="subdomain is immutable"
198+
Subdomain string `json:"subdomain"`
199+
200+
// ResourceManagerTemplateSpec embedded some fields managed by ResourceManagerGroup
201+
ResourceManagerTemplateSpec `json:",inline"`
202+
}
203+
204+
type ResourceManagerStatus struct {
205+
CommonStatus `json:",inline"`
206+
}

0 commit comments

Comments
 (0)