Skip to content

Commit 32b6e95

Browse files
committed
basic implementation of external opd clusters
Signed-off-by: Yang Keao <yangkeao@chunibyo.icu>
1 parent f1c9aea commit 32b6e95

15 files changed

Lines changed: 830 additions & 22 deletions

File tree

api/core/v1alpha1/tiproxy_types.go

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,15 @@ type TiProxyTemplateSpec struct {
159159
Config ConfigFile `json:"config,omitempty"`
160160
UpdateStrategy UpdateStrategy `json:"updateStrategy,omitempty"`
161161

162+
// ExternalPDClusters defines additional backend PD clusters that TiProxy
163+
// should connect to besides the local cluster referenced by spec.cluster.
164+
// Operator will manage these clusters through TiProxy's reloadable
165+
// backend-clusters config and HTTP config API.
166+
// +listType=map
167+
// +listMapKey=name
168+
// +kubebuilder:validation:MaxItems=64
169+
ExternalPDClusters []TiProxyExternalPDCluster `json:"externalPDClusters,omitempty"`
170+
162171
Security *TiProxySecurity `json:"security,omitempty"`
163172

164173
// Volumes defines data volume of TiProxy, it is optional.
@@ -182,6 +191,24 @@ type TiProxyPreStop struct {
182191
SleepSeconds int32 `json:"sleepSeconds,omitempty"`
183192
}
184193

194+
type TiProxyExternalPDCluster struct {
195+
// Name identifies the backend PD cluster inside TiProxy.
196+
// +kubebuilder:validation:MinLength=1
197+
// +kubebuilder:validation:Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
198+
Name string `json:"name"`
199+
200+
// PDAddrs is a comma separated address list of PD servers, for example:
201+
// "pd-0.example.com:2379,pd-1.example.com:2379".
202+
// +kubebuilder:validation:MinLength=1
203+
PDAddrs string `json:"pdAddrs"`
204+
205+
// NSServers defines the DNS servers TiProxy should use when resolving the
206+
// backend cluster endpoints.
207+
// +listType=set
208+
// +kubebuilder:validation:MaxItems=16
209+
NSServers []string `json:"nsServers,omitempty"`
210+
}
211+
185212
type TiProxySecurity struct {
186213
// Whether enable the TLS connection.
187214
TLS *TiProxyTLSConfig `json:"tls,omitempty"`
@@ -205,13 +232,37 @@ type TiProxyServer struct {
205232

206233
type TiProxyPorts struct {
207234
// Client defines port for TiProxy's SQL service.
208-
Client *Port `json:"client,omitempty"`
235+
Client *TiProxyPortOrRange `json:"client,omitempty"`
209236
// API defines port for TiProxy API service.
210237
API *Port `json:"api,omitempty"`
211238
// Peer defines port for TiProxy's peer service.
212239
Peer *Port `json:"peer,omitempty"`
213240
}
214241

242+
// TiProxyPortOrRange defines the main SQL port and optional extra listening range.
243+
// The operator continues to use Port for Pod probes and the internal Service.
244+
// Range is only propagated to TiProxy's proxy.port-range config.
245+
// +kubebuilder:validation:XValidation:rule="!has(self.range) || self.range.start <= self.range.end",message="range.start must be less than or equal to range.end"
246+
type TiProxyPortOrRange struct {
247+
// Port defines the main SQL port exposed by the TiProxy Pod and Service.
248+
// +kubebuilder:validation:Minimum=1
249+
// +kubebuilder:validation:Maximum=65535
250+
Port *int32 `json:"port,omitempty"`
251+
252+
// Range defines additional SQL ports listened by TiProxy itself.
253+
Range *TiProxyPortRange `json:"range,omitempty"`
254+
}
255+
256+
type TiProxyPortRange struct {
257+
// +kubebuilder:validation:Minimum=1
258+
// +kubebuilder:validation:Maximum=65535
259+
Start int32 `json:"start"`
260+
261+
// +kubebuilder:validation:Minimum=1
262+
// +kubebuilder:validation:Maximum=65535
263+
End int32 `json:"end"`
264+
}
265+
215266
type TiProxyProbes struct {
216267
// Readiness defines the readiness probe for TiProxy.
217268
// The default handler is a TCP socket on the client port.

api/core/v1alpha1/zz_generated.deepcopy.go

Lines changed: 72 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

manifests/crd/core.pingcap.com_tiproxies.yaml

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,43 @@ spec:
7272
config:
7373
description: Config defines config file of TiProxy.
7474
type: string
75+
externalPDClusters:
76+
description: |-
77+
ExternalPDClusters defines additional backend PD clusters that TiProxy
78+
should connect to besides the local cluster referenced by spec.cluster.
79+
Operator will manage these clusters through TiProxy's reloadable
80+
backend-clusters config and HTTP config API.
81+
items:
82+
properties:
83+
name:
84+
description: Name identifies the backend PD cluster inside TiProxy.
85+
minLength: 1
86+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
87+
type: string
88+
nsServers:
89+
description: |-
90+
NSServers defines the DNS servers TiProxy should use when resolving the
91+
backend cluster endpoints.
92+
items:
93+
type: string
94+
maxItems: 16
95+
type: array
96+
x-kubernetes-list-type: set
97+
pdAddrs:
98+
description: |-
99+
PDAddrs is a comma separated address list of PD servers, for example:
100+
"pd-0.example.com:2379,pd-1.example.com:2379".
101+
minLength: 1
102+
type: string
103+
required:
104+
- name
105+
- pdAddrs
106+
type: object
107+
maxItems: 64
108+
type: array
109+
x-kubernetes-list-map-keys:
110+
- name
111+
x-kubernetes-list-type: map
75112
features:
76113
description: Features are enabled feature
77114
items:
@@ -8538,11 +8575,34 @@ spec:
85388575
description: Client defines port for TiProxy's SQL service.
85398576
properties:
85408577
port:
8578+
description: Port defines the main SQL port exposed by
8579+
the TiProxy Pod and Service.
85418580
format: int32
8581+
maximum: 65535
8582+
minimum: 1
85428583
type: integer
8543-
required:
8544-
- port
8584+
range:
8585+
description: Range defines additional SQL ports listened
8586+
by TiProxy itself.
8587+
properties:
8588+
end:
8589+
format: int32
8590+
maximum: 65535
8591+
minimum: 1
8592+
type: integer
8593+
start:
8594+
format: int32
8595+
maximum: 65535
8596+
minimum: 1
8597+
type: integer
8598+
required:
8599+
- end
8600+
- start
8601+
type: object
85458602
type: object
8603+
x-kubernetes-validations:
8604+
- message: range.start must be less than or equal to range.end
8605+
rule: '!has(self.range) || self.range.start <= self.range.end'
85468606
peer:
85478607
description: Peer defines port for TiProxy's peer service.
85488608
properties:

manifests/crd/core.pingcap.com_tiproxygroups.yaml

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,44 @@ spec:
213213
config:
214214
description: Config defines config file of TiProxy.
215215
type: string
216+
externalPDClusters:
217+
description: |-
218+
ExternalPDClusters defines additional backend PD clusters that TiProxy
219+
should connect to besides the local cluster referenced by spec.cluster.
220+
Operator will manage these clusters through TiProxy's reloadable
221+
backend-clusters config and HTTP config API.
222+
items:
223+
properties:
224+
name:
225+
description: Name identifies the backend PD cluster
226+
inside TiProxy.
227+
minLength: 1
228+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
229+
type: string
230+
nsServers:
231+
description: |-
232+
NSServers defines the DNS servers TiProxy should use when resolving the
233+
backend cluster endpoints.
234+
items:
235+
type: string
236+
maxItems: 16
237+
type: array
238+
x-kubernetes-list-type: set
239+
pdAddrs:
240+
description: |-
241+
PDAddrs is a comma separated address list of PD servers, for example:
242+
"pd-0.example.com:2379,pd-1.example.com:2379".
243+
minLength: 1
244+
type: string
245+
required:
246+
- name
247+
- pdAddrs
248+
type: object
249+
maxItems: 64
250+
type: array
251+
x-kubernetes-list-map-keys:
252+
- name
253+
x-kubernetes-list-type: map
216254
image:
217255
description: |-
218256
Image is TiProxy's image
@@ -8836,11 +8874,35 @@ spec:
88368874
service.
88378875
properties:
88388876
port:
8877+
description: Port defines the main SQL port exposed
8878+
by the TiProxy Pod and Service.
88398879
format: int32
8880+
maximum: 65535
8881+
minimum: 1
88408882
type: integer
8841-
required:
8842-
- port
8883+
range:
8884+
description: Range defines additional SQL ports
8885+
listened by TiProxy itself.
8886+
properties:
8887+
end:
8888+
format: int32
8889+
maximum: 65535
8890+
minimum: 1
8891+
type: integer
8892+
start:
8893+
format: int32
8894+
maximum: 65535
8895+
minimum: 1
8896+
type: integer
8897+
required:
8898+
- end
8899+
- start
8900+
type: object
88438901
type: object
8902+
x-kubernetes-validations:
8903+
- message: range.start must be less than or equal
8904+
to range.end
8905+
rule: '!has(self.range) || self.range.start <= self.range.end'
88448906
peer:
88458907
description: Peer defines port for TiProxy's peer
88468908
service.

pkg/apiutil/core/v1alpha1/tiproxy.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import (
2323

2424
func TiProxyGroupClientPort(proxyg *v1alpha1.TiProxyGroup) int32 {
2525
if proxyg.Spec.Template.Spec.Server.Ports.Client != nil {
26-
return proxyg.Spec.Template.Spec.Server.Ports.Client.Port
26+
if proxyg.Spec.Template.Spec.Server.Ports.Client.Port != nil {
27+
return *proxyg.Spec.Template.Spec.Server.Ports.Client.Port
28+
}
2729
}
2830
return v1alpha1.DefaultTiProxyPortClient
2931
}
@@ -44,11 +46,23 @@ func TiProxyGroupPeerPort(proxyg *v1alpha1.TiProxyGroup) int32 {
4446

4547
func TiProxyClientPort(tiproxy *v1alpha1.TiProxy) int32 {
4648
if tiproxy.Spec.Server.Ports.Client != nil {
47-
return tiproxy.Spec.Server.Ports.Client.Port
49+
if tiproxy.Spec.Server.Ports.Client.Port != nil {
50+
return *tiproxy.Spec.Server.Ports.Client.Port
51+
}
4852
}
4953
return v1alpha1.DefaultTiProxyPortClient
5054
}
5155

56+
func TiProxyClientPortRange(tiproxy *v1alpha1.TiProxy) []int {
57+
if tiproxy.Spec.Server.Ports.Client == nil || tiproxy.Spec.Server.Ports.Client.Range == nil {
58+
return nil
59+
}
60+
return []int{
61+
int(tiproxy.Spec.Server.Ports.Client.Range.Start),
62+
int(tiproxy.Spec.Server.Ports.Client.Range.End),
63+
}
64+
}
65+
5266
func TiProxyAPIPort(tiproxy *v1alpha1.TiProxy) int32 {
5367
if tiproxy.Spec.Server.Ports.API != nil {
5468
return tiproxy.Spec.Server.Ports.API.Port

0 commit comments

Comments
 (0)