Skip to content

Commit 986fd4b

Browse files
authored
feat: TiCDC support (#6082)
1 parent ffbbc1f commit 986fd4b

Some content is hidden

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

84 files changed

+6391
-80
lines changed

api/core/v1alpha1/cluster_types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,14 @@ const (
158158
ComponentKindTiKV ComponentKind = "TiKV"
159159
ComponentKindTiDB ComponentKind = "TiDB"
160160
ComponentKindTiFlash ComponentKind = "TiFlash"
161+
ComponentKindTiCDC ComponentKind = "TiCDC"
161162
)
162163

163164
// ComponentStatus is the status of a component in the cluster.
164165
type ComponentStatus struct {
165166
// Kind is the kind of the component, e.g., PD, TiKV, TiDB, TiFlash.
166167
// +kubebuilder:validation:Required
167-
// +kubebuilder:validation:Enum=PD;TiKV;TiDB;TiFlash
168+
// +kubebuilder:validation:Enum=PD;TiKV;TiDB;TiFlash;TiCDC
168169
Kind ComponentKind `json:"kind"`
169170

170171
// Replicas is the number of desired replicas of the component.

api/core/v1alpha1/common_types.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const (
7575
LabelValComponentTiDB = "tidb"
7676
LabelValComponentTiKV = "tikv"
7777
LabelValComponentTiFlash = "tiflash"
78+
LabelValComponentTiCDC = "ticdc"
7879

7980
// LabelKeyClusterID is the unique identifier of the cluster.
8081
// This label is used for backward compatibility with TiDB Operator v1, so it has a different prefix.
@@ -196,7 +197,8 @@ type Volume struct {
196197
type VolumeMount struct {
197198
// Type is a type of the volume mount.
198199
Type VolumeMountType `json:"type"`
199-
// Mount path of volume, if it's not set, use the default path of this type
200+
// Mount path of volume, if it's not set, use the default path of this type.
201+
// TODO: webhook for empty path if it's not a built-in type.
200202
MountPath string `json:"mountPath,omitempty"`
201203
// SubPath is the path of the volume's root path.
202204
SubPath string `json:"subPath,omitempty"`

api/core/v1alpha1/doc.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,17 @@
4949
// +kubebuilder:rbac:groups=core.pingcap.com,resources=tiflashgroups/status,verbs=get;list;watch;update
5050
// +kubebuilder:rbac:groups=core.pingcap.com,resources=tiflashes,verbs=get;list;watch;create;update;patch;delete
5151
// +kubebuilder:rbac:groups=core.pingcap.com,resources=tiflashes/status,verbs=get;list;watch;update;patch
52+
//
5253
// +kubebuilder:rbac:groups=core.pingcap.com,resources=tidbgroups,verbs=get;list;watch;delete;update
5354
// +kubebuilder:rbac:groups=core.pingcap.com,resources=tidbgroups/status,verbs=get;list;watch;update
5455
// +kubebuilder:rbac:groups=core.pingcap.com,resources=tidbs,verbs=get;list;watch;create;update;patch;delete
5556
// +kubebuilder:rbac:groups=core.pingcap.com,resources=tidbs/status,verbs=get;list;watch;update;patch
5657
//
58+
// +kubebuilder:rbac:groups=core.pingcap.com,resources=ticdcgroups,verbs=get;list;watch;delete;update
59+
// +kubebuilder:rbac:groups=core.pingcap.com,resources=ticdcgroups/status,verbs=get;list;watch;update
60+
// +kubebuilder:rbac:groups=core.pingcap.com,resources=ticdcs,verbs=get;list;watch;create;update;patch;delete
61+
// +kubebuilder:rbac:groups=core.pingcap.com,resources=ticdcs/status,verbs=get;list;watch;update;patch
62+
//
5763
// +kubebuilder:rbac:resources="",verbs=get,urls=/metrics
5864
//
5965
// Package v1alpha1 is the v1alpha1 version of core tidb operator api

api/core/v1alpha1/names.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const (
4646
ContainerNameTiKV = "tikv"
4747
ContainerNameTiDB = "tidb"
4848
ContainerNameTiFlash = "tiflash"
49+
ContainerNameTiCDC = "ticdc"
4950

5051
// An init container to copy pre stop checker cmd to main container
5152
ContainerNamePrestopChecker = meta.NamePrefix + "prestop-checker"
@@ -70,6 +71,7 @@ const (
7071
DirPathConfigTiKV = "/etc/tikv"
7172
DirPathConfigTiDB = "/etc/tidb"
7273
DirPathConfigTiFlash = "/etc/tiflash"
74+
DirPathConfigTiCDC = "/etc/ticdc"
7375

7476
// DirPathPrestop defines dir path of pre stop checker cmd
7577
DirPathPrestop = "/prestop"
@@ -87,6 +89,7 @@ const (
8789
DirPathClusterTLSTiKV = "/var/lib/tikv-tls"
8890
DirPathClusterTLSTiDB = "/var/lib/tidb-tls"
8991
DirPathClusterTLSTiFlash = "/var/lib/tiflash-tls"
92+
DirPathClusterTLSTiCDC = "/var/lib/ticdc-tls"
9093
// Dir path of tls file for tidb and mysql client
9194
DirPathMySQLTLS = "/var/lib/tidb-sql-tls"
9295
)

api/core/v1alpha1/ticdc_types.go

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
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+
21+
const (
22+
TiCDCPortName = "ticdc" // main port
23+
DefaultTiCDCPort = 8300
24+
)
25+
26+
const (
27+
// TODO: combine all Health condition
28+
TiCDCCondHealth = "Health"
29+
TiCDCHealthReason = "TiCDCHealth"
30+
31+
TiCDCCondSuspended = "Suspended"
32+
TiCDCSuspendReason = "TiCDCSuspend"
33+
34+
TiCDCGroupCondAvailable = "Available"
35+
TiCDCGroupAvailableReason = "TiCDCGroupAvailable"
36+
37+
TiCDCGroupCondSuspended = "Suspended"
38+
TiCDCGroupSuspendReason = "TiCDCGroupSuspend"
39+
)
40+
41+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
42+
// +kubebuilder:object:root=true
43+
44+
// TiCDCGroupList defines a list of TiCDC groups
45+
type TiCDCGroupList struct {
46+
metav1.TypeMeta `json:",inline"`
47+
metav1.ListMeta `json:"metadata,omitempty"`
48+
49+
Items []TiCDCGroup `json:"items"`
50+
}
51+
52+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
53+
// +kubebuilder:object:root=true
54+
// +kubebuilder:subresource:status
55+
// +kubebuilder:resource:categories=tc
56+
// +kubebuilder:resource:categories=tg
57+
// +kubebuilder:printcolumn:name="Cluster",type=string,JSONPath=`.spec.cluster.name`
58+
// +kubebuilder:printcolumn:name="Available",type=string,JSONPath=`.status.conditions[?(@.type=="Available")].status`
59+
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
60+
61+
// TiCDCGroup defines a group of similar TiCDC instances
62+
type TiCDCGroup struct {
63+
metav1.TypeMeta `json:",inline"`
64+
metav1.ObjectMeta `json:"metadata,omitempty"`
65+
66+
Spec TiCDCGroupSpec `json:"spec,omitempty"`
67+
Status TiCDCGroupStatus `json:"status,omitempty"`
68+
}
69+
70+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
71+
// +kubebuilder:object:root=true
72+
73+
// TiCDCList defines a list of TiCDC instances
74+
type TiCDCList struct {
75+
metav1.TypeMeta `json:",inline"`
76+
metav1.ListMeta `json:"metadata,omitempty"`
77+
78+
Items []TiCDC `json:"items"`
79+
}
80+
81+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
82+
// +kubebuilder:object:root=true
83+
// +kubebuilder:subresource:status
84+
// +kubebuilder:resource:categories=tc
85+
// +kubebuilder:resource:categories=peer
86+
// +kubebuilder:printcolumn:name="Cluster",type=string,JSONPath=`.spec.cluster.name`
87+
// +kubebuilder:printcolumn:name="Healthy",type=string,JSONPath=`.status.conditions[?(@.type=="Health")].status`
88+
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
89+
90+
// TiCDC defines a TiCDC instance
91+
type TiCDC struct {
92+
metav1.TypeMeta `json:",inline"`
93+
metav1.ObjectMeta `json:"metadata,omitempty"`
94+
95+
Spec TiCDCSpec `json:"spec,omitempty"`
96+
Status TiCDCStatus `json:"status,omitempty"`
97+
}
98+
99+
// TiCDCGroupSpec describes the common attributes of a TiCDCGroup
100+
type TiCDCGroupSpec struct {
101+
Cluster ClusterReference `json:"cluster"`
102+
Replicas *int32 `json:"replicas"`
103+
104+
// +listType=map
105+
// +listMapKey=type
106+
SchedulePolicies []SchedulePolicy `json:"schedulePolicies,omitempty"`
107+
108+
Template TiCDCTemplate `json:"template"`
109+
}
110+
111+
type TiCDCTemplate struct {
112+
ObjectMeta `json:"metadata,omitempty"`
113+
Spec TiCDCTemplateSpec `json:"spec"`
114+
}
115+
116+
// TiCDCTemplateSpec can only be specified in TiCDCGroup
117+
type TiCDCTemplateSpec struct {
118+
Version string `json:"version"`
119+
// Image is TiCDC's image
120+
// If tag is omitted, version will be used as the image tag.
121+
// Default is pingcap/ticdc
122+
Image *string `json:"image,omitempty"`
123+
// Server defines server config for TiCDC
124+
Server TiCDCServer `json:"server,omitempty"`
125+
Resources ResourceRequirements `json:"resources,omitempty"`
126+
UpdateStrategy UpdateStrategy `json:"updateStrategy,omitempty"`
127+
// Config defines config file of TiCDC
128+
Config ConfigFile `json:"config,omitempty"`
129+
130+
// Volumes defines persistent volumes of TiCDC, it is optional.
131+
// If you want to use ephemeral storage or mount sink TLS certs, you can use "overlay" instead.
132+
Volumes []Volume `json:"volumes,omitempty"`
133+
// Overlay defines a k8s native resource template patch
134+
// All resources(pod, pvcs, ...) managed by TiCDC can be overlayed by this field
135+
// +kubebuilder:validation:Schemaless
136+
// +kubebuilder:pruning:PreserveUnknownFields
137+
Overlay *Overlay `json:"overlay,omitempty"`
138+
139+
// GracefulShutdownTimeout is the timeout of gracefully shutdown a TiCDC pod
140+
// when scaling in or rolling update.
141+
// Encoded in the format of Go Duration.
142+
// Defaults to 10m
143+
GracefulShutdownTimeout *metav1.Duration `json:"gracefulShutdownTimeout,omitempty"`
144+
}
145+
146+
type TiCDCServer struct {
147+
// Ports defines all ports listened by TiCDC
148+
Ports TiCDCPorts `json:"ports,omitempty"`
149+
}
150+
151+
type TiCDCPorts struct {
152+
// Port defines main port for TiCDC.
153+
Port *Port `json:"port,omitempty"`
154+
}
155+
156+
type TiCDCGroupStatus struct {
157+
CommonStatus `json:",inline"`
158+
GroupStatus `json:",inline"`
159+
}
160+
161+
// TiCDCSpec describes the common attributes of a TiCDC instance
162+
type TiCDCSpec struct {
163+
// Cluster is a reference of tidb cluster
164+
Cluster ClusterReference `json:"cluster"`
165+
166+
// Topology defines the topology domain of this TiCDC instance
167+
// It will be translated into a node affinity config
168+
// Topology cannot be changed
169+
Topology Topology `json:"topology,omitempty"`
170+
171+
// Subdomain means the subdomain of the exported TiCDC DNS.
172+
// A same TiCDC cluster will use a same subdomain
173+
Subdomain string `json:"subdomain"`
174+
175+
// TiCDCTemplateSpec embedded some fields managed by TiCDCGroup
176+
TiCDCTemplateSpec `json:",inline"`
177+
}
178+
179+
type TiCDCStatus struct {
180+
CommonStatus `json:",inline"`
181+
182+
// ID is the member id of this TiCDC instance
183+
ID string `json:"id"`
184+
185+
// should we need to save IsOwner in status?
186+
// but this value may be changed when scaling in or rolling update
187+
}

0 commit comments

Comments
 (0)