Skip to content

Commit 7d238e5

Browse files
authored
fix(group): fix unexpected rolling update when scale out/in (#6053)
Signed-off-by: liubo02 <liubo02@pingcap.com>
1 parent 2a9af0c commit 7d238e5

35 files changed

+118
-100
lines changed

apis/core/v1alpha1/pd_types.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (in *PDGroup) GetDesiredReplicas() int32 {
111111
}
112112

113113
func (in *PDGroup) GetDesiredVersion() string {
114-
return in.Spec.Version
114+
return in.Spec.Template.Spec.Version
115115
}
116116

117117
func (in *PDGroup) GetActualVersion() string {
@@ -276,7 +276,6 @@ func (in *PD) TLSClusterSecretName() string {
276276
type PDGroupSpec struct {
277277
Cluster ClusterReference `json:"cluster"`
278278
Replicas *int32 `json:"replicas"`
279-
Version string `json:"version"`
280279

281280
// Bootstrapped means that pd cluster has been bootstrapped,
282281
// and there is no need to initialize a new cluster.
@@ -285,6 +284,8 @@ type PDGroupSpec struct {
285284
// If it's true, it cannot be set to false for security
286285
Bootstrapped bool `json:"bootstrapped,omitempty"`
287286

287+
// +listType=map
288+
// +listMapKey=type
288289
SchedulePolicies []SchedulePolicy `json:"schedulePolicies,omitempty"`
289290

290291
Template PDTemplate `json:"template"`
@@ -298,6 +299,7 @@ type PDTemplate struct {
298299
// PDTemplateSpec can only be specified in PDGroup
299300
// TODO: It's name may need to be changed to distinguish from PodTemplateSpec
300301
type PDTemplateSpec struct {
302+
Version string `json:"version"`
301303
// Image is pd's image
302304
// If tag is omitted, version will be used as the image tag.
303305
// Default is pingcap/pd
@@ -344,9 +346,6 @@ type PDSpec struct {
344346
// Topology cannot be changed
345347
Topology Topology `json:"topology,omitempty"`
346348

347-
// Version specifies the PD version
348-
Version string `json:"version"`
349-
350349
// Subdomain means the subdomain of the exported pd dns.
351350
// A same pd cluster will use a same subdomain
352351
Subdomain string `json:"subdomain"`

apis/core/v1alpha1/tidb_types.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (in *TiDBGroup) GetDesiredReplicas() int32 {
142142
}
143143

144144
func (in *TiDBGroup) GetDesiredVersion() string {
145-
return in.Spec.Version
145+
return in.Spec.Template.Spec.Version
146146
}
147147

148148
func (in *TiDBGroup) GetActualVersion() string {
@@ -315,11 +315,12 @@ func (in *TiDB) TLSClusterSecretName() string {
315315
type TiDBGroupSpec struct {
316316
Cluster ClusterReference `json:"cluster"`
317317
Replicas *int32 `json:"replicas"`
318-
Version string `json:"version"`
319318

320319
// Service defines some fields used to override the default service.
321320
Service *TiDBService `json:"service,omitempty"`
322321

322+
// +listType=map
323+
// +listMapKey=type
323324
SchedulePolicies []SchedulePolicy `json:"schedulePolicies,omitempty"`
324325

325326
Template TiDBTemplate `json:"template"`
@@ -332,6 +333,7 @@ type TiDBTemplate struct {
332333

333334
// TiDBTemplateSpec can only be specified in TiDBGroup.
334335
type TiDBTemplateSpec struct {
336+
Version string `json:"version"`
335337
// Image is tidb's image
336338
// If tag is omitted, version will be used as the image tag.
337339
// Default is pingcap/tidb
@@ -480,9 +482,6 @@ type TiDBSpec struct {
480482
// Topology cannot be changed.
481483
Topology Topology `json:"topology,omitempty"`
482484

483-
// Version specifies the TiDB version.
484-
Version string `json:"version"`
485-
486485
// Subdomain means the subdomain of the exported pd dns.
487486
// A same pd cluster will use a same subdomain
488487
Subdomain string `json:"subdomain"`

apis/core/v1alpha1/tiflash_types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (in *TiFlashGroup) GetDesiredReplicas() int32 {
113113
}
114114

115115
func (in *TiFlashGroup) GetDesiredVersion() string {
116-
return in.Spec.Version
116+
return in.Spec.Template.Spec.Version
117117
}
118118

119119
func (in *TiFlashGroup) GetActualVersion() string {
@@ -305,8 +305,9 @@ func (in *TiFlash) TLSClusterSecretName() string {
305305
type TiFlashGroupSpec struct {
306306
Cluster ClusterReference `json:"cluster"`
307307
Replicas *int32 `json:"replicas"`
308-
Version string `json:"version"`
309308

309+
// +listType=map
310+
// +listMapKey=type
310311
SchedulePolicies []SchedulePolicy `json:"schedulePolicies,omitempty"`
311312
Template TiFlashTemplate `json:"template"`
312313
}
@@ -317,6 +318,7 @@ type TiFlashTemplate struct {
317318
}
318319

319320
type TiFlashTemplateSpec struct {
321+
Version string `json:"version"`
320322
// Image is tiflash's image
321323
// If tag is omitted, version will be used as the image tag.
322324
// Default is pingcap/tiflash
@@ -382,8 +384,6 @@ type TiFlashSpec struct {
382384
// It will be translated into a node affinity config
383385
// Topology cannot be changed
384386
Topology Topology `json:"topology,omitempty"`
385-
// Version specifies the TiFlash version
386-
Version string `json:"version"`
387387
// Subdomain means the subdomain of the exported TiFlash dns.
388388
// A same TiFlash group will use a same subdomain
389389
Subdomain string `json:"subdomain"`

apis/core/v1alpha1/tikv_types.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func (in *TiKVGroup) GetDesiredReplicas() int32 {
148148
}
149149

150150
func (in *TiKVGroup) GetDesiredVersion() string {
151-
return in.Spec.Version
151+
return in.Spec.Template.Spec.Version
152152
}
153153

154154
func (in *TiKVGroup) GetActualVersion() string {
@@ -281,7 +281,6 @@ func (in *TiKV) TLSClusterSecretName() string {
281281
type TiKVGroupSpec struct {
282282
Cluster ClusterReference `json:"cluster"`
283283
Replicas *int32 `json:"replicas"`
284-
Version string `json:"version"`
285284

286285
// +listType=map
287286
// +listMapKey=type
@@ -298,6 +297,7 @@ type TiKVTemplate struct {
298297
// TiKVTemplateSpec can only be specified in TiKVGroup
299298
// TODO: It's name may need to be changed to distinguish from PodTemplateSpec
300299
type TiKVTemplateSpec struct {
300+
Version string `json:"version"`
301301
// Image is tikv's image
302302
// If tag is omitted, version will be used as the image tag.
303303
// Default is pingcap/tikv
@@ -351,8 +351,6 @@ type TiKVSpec struct {
351351
// It will be translated into a node affinity config
352352
// Topology cannot be changed
353353
Topology Topology `json:"topology,omitempty"`
354-
// Version specifies the TiKV version
355-
Version string `json:"version"`
356354
// Subdomain means the subdomain of the exported tikv dns.
357355
// A same tikv group will use a same subdomain
358356
Subdomain string `json:"subdomain"`

manifests/crd/core.pingcap.com_pdgroups.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ spec:
105105
- type
106106
type: object
107107
type: array
108+
x-kubernetes-list-map-keys:
109+
- type
110+
x-kubernetes-list-type: map
108111
template:
109112
properties:
110113
metadata:
@@ -215,6 +218,8 @@ spec:
215218
- HotReload
216219
type: string
217220
type: object
221+
version:
222+
type: string
218223
volumes:
219224
description: Volumes defines persistent volumes of PD
220225
items:
@@ -276,18 +281,16 @@ spec:
276281
type: array
277282
required:
278283
- config
284+
- version
279285
- volumes
280286
type: object
281287
required:
282288
- spec
283289
type: object
284-
version:
285-
type: string
286290
required:
287291
- cluster
288292
- replicas
289293
- template
290-
- version
291294
type: object
292295
status:
293296
properties:

manifests/crd/core.pingcap.com_pds.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ spec:
151151
type: string
152152
type: object
153153
version:
154-
description: Version specifies the PD version
155154
type: string
156155
volumes:
157156
description: Volumes defines persistent volumes of PD

manifests/crd/core.pingcap.com_tidbgroups.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ spec:
9797
- type
9898
type: object
9999
type: array
100+
x-kubernetes-list-map-keys:
101+
- type
102+
x-kubernetes-list-type: map
100103
service:
101104
description: Service defines some fields used to override the default
102105
service.
@@ -330,6 +333,8 @@ spec:
330333
- HotReload
331334
type: string
332335
type: object
336+
version:
337+
type: string
333338
volumes:
334339
description: Volumes defines data volume of TiDB, it is optional.
335340
items:
@@ -391,17 +396,15 @@ spec:
391396
type: array
392397
required:
393398
- config
399+
- version
394400
type: object
395401
required:
396402
- spec
397403
type: object
398-
version:
399-
type: string
400404
required:
401405
- cluster
402406
- replicas
403407
- template
404-
- version
405408
type: object
406409
status:
407410
properties:

manifests/crd/core.pingcap.com_tidbs.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ spec:
242242
type: string
243243
type: object
244244
version:
245-
description: Version specifies the TiDB version.
246245
type: string
247246
volumes:
248247
description: Volumes defines data volume of TiDB, it is optional.

manifests/crd/core.pingcap.com_tiflashes.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ spec:
195195
type: string
196196
type: object
197197
version:
198-
description: Version specifies the TiFlash version
199198
type: string
200199
volumes:
201200
description: Volumes defines data volume of TiFlash

manifests/crd/core.pingcap.com_tiflashgroups.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ spec:
9696
- type
9797
type: object
9898
type: array
99+
x-kubernetes-list-map-keys:
100+
- type
101+
x-kubernetes-list-type: map
99102
template:
100103
properties:
101104
metadata:
@@ -250,6 +253,8 @@ spec:
250253
- HotReload
251254
type: string
252255
type: object
256+
version:
257+
type: string
253258
volumes:
254259
description: Volumes defines data volume of TiFlash
255260
items:
@@ -311,18 +316,16 @@ spec:
311316
type: array
312317
required:
313318
- config
319+
- version
314320
- volumes
315321
type: object
316322
required:
317323
- spec
318324
type: object
319-
version:
320-
type: string
321325
required:
322326
- cluster
323327
- replicas
324328
- template
325-
- version
326329
type: object
327330
status:
328331
properties:

manifests/crd/core.pingcap.com_tikvgroups.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ spec:
215215
- HotReload
216216
type: string
217217
type: object
218+
version:
219+
type: string
218220
volumes:
219221
description: Volumes defines data volume of TiKV
220222
items:
@@ -276,18 +278,16 @@ spec:
276278
type: array
277279
required:
278280
- config
281+
- version
279282
- volumes
280283
type: object
281284
required:
282285
- spec
283286
type: object
284-
version:
285-
type: string
286287
required:
287288
- cluster
288289
- replicas
289290
- template
290-
- version
291291
type: object
292292
status:
293293
properties:

manifests/crd/core.pingcap.com_tikvs.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ spec:
155155
type: string
156156
type: object
157157
version:
158-
description: Version specifies the TiKV version
159158
type: string
160159
volumes:
161160
description: Volumes defines data volume of TiKV

pkg/action/upgrader_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,11 @@ func TestUpgradePolicy(t *testing.T) {
201201
Cluster: v1alpha1.ClusterReference{
202202
Name: "tc",
203203
},
204-
Version: "v8.5.0",
204+
Template: v1alpha1.PDTemplate{
205+
Spec: v1alpha1.PDTemplateSpec{
206+
Version: "v8.5.0",
207+
},
208+
},
205209
},
206210
Status: v1alpha1.PDGroupStatus{
207211
GroupStatus: v1alpha1.GroupStatus{
@@ -222,7 +226,11 @@ func TestUpgradePolicy(t *testing.T) {
222226
Cluster: v1alpha1.ClusterReference{
223227
Name: "tc",
224228
},
225-
Version: "v8.5.0",
229+
Template: v1alpha1.TiKVTemplate{
230+
Spec: v1alpha1.TiKVTemplateSpec{
231+
Version: "v8.5.0",
232+
},
233+
},
226234
},
227235
Status: v1alpha1.TiKVGroupStatus{
228236
GroupStatus: v1alpha1.GroupStatus{

pkg/controllers/common/revision_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ func (f *fakeRevisionStateInitializer[G]) RevisionInitializer() RevisionInitiali
4646
}
4747

4848
const (
49-
fakeOldRevision = "aaa-c9f48df69"
50-
fakeNewRevision = "aaa-c9f48df68"
49+
fakeOldRevision = "aaa-77554fbd78"
50+
fakeNewRevision = "aaa-77554fbd79"
5151
)
5252

5353
func TestTaskRevision(t *testing.T) {
@@ -169,7 +169,7 @@ func TestTaskRevision(t *testing.T) {
169169
fake.FakeObj(fakeOldRevision, fake.Label[appsv1.ControllerRevision]("ccc", "ddd")),
170170
fake.FakeObj(fakeNewRevision, fake.Label[appsv1.ControllerRevision]("ccc", "ddd")),
171171
},
172-
expectedUpdateRevision: "aaa-c9f48df6c",
172+
expectedUpdateRevision: "aaa-77554fbd76",
173173
expectedCurrentRevision: fakeOldRevision,
174174
expectedCollisionCount: 2,
175175
},

pkg/controllers/pdgroup/tasks/updater.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func TaskUpdater(state *ReconcileContext, c client.Client) task.Task {
9999
}
100100

101101
func needVersionUpgrade(pdg *v1alpha1.PDGroup) bool {
102-
return pdg.Spec.Version != pdg.Status.Version && pdg.Status.Version != ""
102+
return pdg.Spec.Template.Spec.Version != pdg.Status.Version && pdg.Status.Version != ""
103103
}
104104

105105
const (
@@ -141,7 +141,6 @@ func PDNewer(pdg *v1alpha1.PDGroup, rev string) updater.NewFactory[*runtime.PD]
141141
},
142142
Spec: v1alpha1.PDSpec{
143143
Cluster: pdg.Spec.Cluster,
144-
Version: pdg.Spec.Version,
145144
Subdomain: HeadlessServiceName(pdg.Name),
146145
PDTemplateSpec: *spec,
147146
},

0 commit comments

Comments
 (0)