Skip to content

Commit b38569c

Browse files
authored
tidb,tiproxy: expose max surge on tidb/tiproxygroup spec (#6797)
1 parent 6a1bbac commit b38569c

18 files changed

Lines changed: 307 additions & 7 deletions

File tree

api/core/v1alpha1/tidb_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ type TiDBGroupSpec struct {
138138
// +optional
139139
MinReadySeconds *int64 `json:"minReadySeconds,omitempty"`
140140

141+
// MaxSurge specifies the maximum number of additional instances that may be created during rolling restart.
142+
// It only takes effect when the update requires restarting TiDB instances.
143+
// Defaults to 1.
144+
// +kubebuilder:validation:Minimum=1
145+
// +optional
146+
MaxSurge *int32 `json:"maxSurge,omitempty"`
147+
141148
// Template is the instance template
142149
Template TiDBTemplate `json:"template"`
143150
}

api/core/v1alpha1/tiproxy_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ type TiProxyGroupSpec struct {
123123
// +optional
124124
MinReadySeconds *int64 `json:"minReadySeconds,omitempty"`
125125

126+
// MaxSurge specifies the maximum number of additional instances that may be created during rolling restart.
127+
// It only takes effect when the update requires restarting TiProxy instances.
128+
// Defaults to 1.
129+
// +kubebuilder:validation:Minimum=1
130+
// +optional
131+
MaxSurge *int32 `json:"maxSurge,omitempty"`
132+
126133
Template TiProxyTemplate `json:"template"`
127134
}
128135

api/core/v1alpha1/zz_generated.deepcopy.go

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

manifests/crd/core.pingcap.com_tidbgroups.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ spec:
110110
- IndependentKVEngineWorker
111111
type: string
112112
type: array
113+
maxSurge:
114+
description: |-
115+
MaxSurge specifies the maximum number of additional instances that may be created during rolling restart.
116+
It only takes effect when the update requires restarting TiDB instances.
117+
Defaults to 1.
118+
format: int32
119+
minimum: 1
120+
type: integer
113121
minReadySeconds:
114122
description: MinReadySeconds specifies the minimum number of seconds
115123
for which a newly created pod be ready without any of its containers

manifests/crd/core.pingcap.com_tiproxygroups.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ spec:
110110
- IndependentKVEngineWorker
111111
type: string
112112
type: array
113+
maxSurge:
114+
description: |-
115+
MaxSurge specifies the maximum number of additional instances that may be created during rolling restart.
116+
It only takes effect when the update requires restarting TiProxy instances.
117+
Defaults to 1.
118+
format: int32
119+
minimum: 1
120+
type: integer
113121
minReadySeconds:
114122
description: MinReadySeconds specifies the minimum number of seconds
115123
for which a newly created pod be ready without any of its containers

pkg/controllers/tidbgroup/tasks/updater.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ func TaskUpdater(state *ReconcileContext, c client.Client, af tracker.AllocateFa
8989
noUpdate := false
9090
if needRestart {
9191
maxSurge, maxUnavailable = 1, 0
92+
if dbg.Spec.MaxSurge != nil {
93+
maxSurge = int(*dbg.Spec.MaxSurge)
94+
}
9295
noUpdate = true
9396
}
9497

pkg/controllers/tidbgroup/tasks/updater_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,28 @@ func TestTaskUpdater(t *testing.T) {
254254
expectedStatus: task.SWait,
255255
expectedTiDBNum: 3,
256256
},
257+
{
258+
desc: "rolling restart honors maxSurge",
259+
state: &ReconcileContext{
260+
State: &state{
261+
dbg: fake.FakeObj("aaa", func(obj *v1alpha1.TiDBGroup) *v1alpha1.TiDBGroup {
262+
obj.Spec.Replicas = ptr.To[int32](2)
263+
obj.Spec.MaxSurge = ptr.To[int32](2)
264+
obj.Spec.Template.Spec.Image = ptr.To("pingcap/tidb:v8.1.1")
265+
return obj
266+
}),
267+
cluster: fake.FakeObj[v1alpha1.Cluster]("cluster"),
268+
dbs: []*v1alpha1.TiDB{
269+
fakeAvailableTiDB("aaa-xxx", fake.FakeObj[v1alpha1.TiDBGroup]("aaa"), oldRevision),
270+
fakeAvailableTiDB("aaa-yyy", fake.FakeObj[v1alpha1.TiDBGroup]("aaa"), oldRevision),
271+
},
272+
updateRevision: newRevision,
273+
},
274+
},
275+
276+
expectedStatus: task.SWait,
277+
expectedTiDBNum: 4,
278+
},
257279
}
258280

259281
for i := range cases {

pkg/controllers/tiproxygroup/tasks/updater.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ func TaskUpdater(state *ReconcileContext, c client.Client, af tracker.AllocateFa
8686
noUpdate := false
8787
if needRestart {
8888
maxSurge, maxUnavailable = 1, 0
89+
if proxyg.Spec.MaxSurge != nil {
90+
maxSurge = int(*proxyg.Spec.MaxSurge)
91+
}
8992
noUpdate = true
9093
}
9194

pkg/controllers/tiproxygroup/tasks/updater_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,28 @@ func TestTaskUpdater(t *testing.T) {
227227
expectedStatus: task.SWait,
228228
expectedTiProxyNum: 3,
229229
},
230+
{
231+
desc: "rolling restart honors maxSurge",
232+
state: &ReconcileContext{
233+
State: &state{
234+
proxyg: fake.FakeObj("aaa", func(obj *v1alpha1.TiProxyGroup) *v1alpha1.TiProxyGroup {
235+
obj.Spec.Replicas = ptr.To[int32](2)
236+
obj.Spec.MaxSurge = ptr.To[int32](2)
237+
obj.Spec.Template.Spec.Image = ptr.To("pingcap/tiproxy:v8.1.1")
238+
return obj
239+
}),
240+
cluster: fake.FakeObj[v1alpha1.Cluster]("cluster"),
241+
proxies: []*v1alpha1.TiProxy{
242+
fakeAvailableTiProxy("aaa-xxx", fake.FakeObj[v1alpha1.TiProxyGroup]("aaa"), oldRevision),
243+
fakeAvailableTiProxy("aaa-yyy", fake.FakeObj[v1alpha1.TiProxyGroup]("aaa"), oldRevision),
244+
},
245+
updateRevision: newRevision,
246+
},
247+
},
248+
249+
expectedStatus: task.SWait,
250+
expectedTiProxyNum: 4,
251+
},
230252
}
231253

232254
for i := range cases {

pkg/utils/hasher/hasher_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestHash(t *testing.T) {
4242
},
4343
},
4444
// not important, feel free to change if tidb group is changed
45-
expected: "58c864c88",
45+
expected: "6c9dc4f5cd",
4646
},
4747
}
4848

0 commit comments

Comments
 (0)